Latest 0.1.0
Homepage https://github.com/dkhamsing/TwitterSafariViewControllerAuth
License MIT License
Platforms ios 9.0
Authors

Twitter OAuth Login with Safari View Controller on iOS

Build Status
Version
License
Platform

TwitterSafariViewControllerAuth

TwitterSafariViewControllerAuth adds Twitter login using Apple’s SFSafariViewController, which is safe for your users WKWebView UIWebView :100: :smile:

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

Installation

CocoaPods

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.

TwitterSafariViewControllerAuth

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)

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.

Latest podspec

{
    "name": "TwitterSafariViewControllerAuth",
    "version": "0.1.0",
    "summary": "Twitter OAuth Login with Safari View Controller",
    "description": "TwitterSafariViewControllerAuth lets you integrate with Apple's SFSafariViewController which is safe for your users (say no to WKWebView / UIWebView). Bonus: have access to Safari credentials or use 1password like a boss.",
    "homepage": "https://github.com/dkhamsing/TwitterSafariViewControllerAuth",
    "license": "MIT License",
    "authors": {
        "dkhamsing": "[email protected]"
    },
    "social_media_url": "http://twitter.com/dkhamsing",
    "source": {
        "git": "https://github.com/dkhamsing/TwitterSafariViewControllerAuth.git",
        "tag": "0.1.0"
    },
    "source_files": "TwitterSafariViewControllerAuth/*.{h,m}",
    "platforms": {
        "ios": "9.0"
    }
}

Pin It on Pinterest

Share This