Skip to content

dkarchive/TwitterSafariViewControllerAuth

Repository files navigation

TwitterSafariViewControllerAuth

Twitter OAuth Login with Safari View Controller on iOS

Build Status Version License Platform

TwitterSafariViewControllerAuth adds Twitter login using Apple's SFSafariViewController, which is safe for your users WKWebView UIWebView 💯 😄

Bonus: access saved credentials in Safari or use 1Password like a boss.

Installation

platform :ios, '9.0'
pod 'TwitterSafariViewControllerAuth'

Manual

Add the TwitterSafariViewControllerAuth/ folder to your project.

Requirements

Twitter App

A Twitter app with a valid Callback URL is required: the value entered there is not used but if the field is empty, redirects are disallowed.

Xcode

A URL scheme for your iOS app is required. In Project Settings → Info: scroll down to URL Types and add an entry with +

  • Identifier: your-app-bundle-id, i.e. com.dkhamsing.TwitterAuthDemo
  • URL Schemes: url-scheme, i.e. TwitterAuthDemo (if there is only one scheme, this value is read and set as the URL scheme for TwitterSafariViewControllerAuth)

Usage

// MyViewController.m

static NSString *const kConsumerKey    = @"<YOUR APP CONSUMER KEY>";
static NSString *const kConsumerSecret = @"<YOUR APP CONSUMER SECRET>";

#import "TwitterSafariViewControllerAuth.h"

// ...

// URL Scheme is assumed to be first scheme in bundle plist, to set this manually, use - configureConsumerKey:clientSecret:urlScheme:.
[[TwitterSafariViewControllerAuth sharedInstance] configureConsumerKey:kConsumerKey clientSecret:kConsumerSecret];

[[TwitterSafariViewControllerAuth sharedInstance] presentOAuthLoginFromController:self];
// AppDelegate.m

#import "TwitterSafariViewControllerAuth.h"

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
    [[TwitterSafariViewControllerAuth sharedInstance] handleOpenUrl:url options:options success:^(NSDictionary *results) {
        NSLog(@"Results: %@", results);               
        /*
        Results: {
            data = <...>;
            "data_string" = "..."
            "oauth_token" = "...";
            "oauth_token_secret" = "...";
            "screen_name" = dkhamsing;
            "user_id" = ...;
            "x_auth_expires" = 0;
        }
        */
    } failure:nil];

    // ...
}

A demo project is included.

Credits

Based on FHSTwitterEngine.

Contact

License

This project is available under the MIT license. See the LICENSE file for more info.

About

🐤 Twitter OAuth Login with Safari View Controller on iOS

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published