A simple way to implement Facebook and Google login in your iOS apps.

Overview

Simplicity

Version License Platform codebeat badge Slack Status

Simplicity is a simple way to implement Facebook and Google login in your iOS apps.

Simplicity can be easily extended to support other external login providers, including OAuth2, OpenID, SAML, and other custom protocols, and will support more in the future. We always appreciate pull requests!

Why use Simplicity?

Facebook and Google's SDKs are heavyweight, and take time to set up and use. You can use Simplicity and only have to manage one SDK for logging in with an external provider in your app. Simplicity adds just 200KB to your app's binary, compared to 5.4MB when using the Facebook & Google SDKs.

Simplicity is also extensible, and already supports other login providers, like VKontakte (the largest European social network) and generic OAuth providers.

Logging in with Simplicity is as easy as:

Simplicity.login(Facebook()) { (accessToken, error) in
  // Handle access token here
}

Stormpath

Simplicity is maintained by Stormpath, an API service for authentication, authorization, and user management. If you're building a backend API for your app, consider using Stormpath to help you implement a secure REST API. Read our tutorial on how to build a REST API for your mobile apps using Node.js.

Installation

Requires XCode 8+ / Swift 3+

To install Simplicity, we use CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Simplicity'

Carthage

To use Simplicity with Carthage, specify it in your Cartfile:

github "SimplicityMobile/Simplicity"

Swift 2

Older versions of Simplicity support Swift 2.3 (Xcode 8) or Swift 2.2 (Xcode 7).

  • Swift 2.3 support is on branch swift2.3
  • Swift 2.2 support is on version 1.x

Add the link handlers to the AppDelegate

When a user finishes their log in flow, Facebook or Google will redirect back into the app. Simplicity will listen for the access token or error. You need to add the following lines of code to AppDelegate.swift:

import Simplicity

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any]) -> Bool {
    return Simplicity.application(app, open: url, options: options)
}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    return Simplicity.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}

Usage

Simplicity is very flexible and supports a number of configuration options for your login providers. To view, please see the full API docs on CocoaDocs.

Using Facebook Login

To get started, you first need to register an application with Facebook. After registering your app, go into your app dashboard's settings page. Click "Add Platform", and fill in your Bundle ID, and turn "Single Sign On" on.

Finally, open up your App's Xcode project and go to the project's info tab. Under "URL Types", add a new entry, and in the URL schemes form field, type in fb[APP_ID_HERE], replacing [APP_ID_HERE] with your Facebook App ID.

Then, you can initiate the login screen by calling:

Simplicity.login(Facebook()) { (accessToken, error) in
  // Handle access token here
}

By request, you can also call .login on any LoginProvider:

Facebook().login { (accessToken, error) in
  // Handle access token here
}

Using Google Login

To get started, you first need to register an application with Google. Click "Enable and Manage APIs", and then the credentials tab. Create an OAuth Client ID for "iOS".

Next, open up your App's Xcode project and go to the project's info tab. Under "URL Types", add a new entry, and in the URL schemes form field, type in your Google iOS Client's iOS URL scheme from the Google Developer Console.

Then, you can initiate the login screen by calling:

Simplicity.login(Google()) { (accessToken, error) in
  // Handle access token here
}

Using VKontakte Login

To get started, you first need to create an application with VKontakte. After registering your app, go into your client settings page. Set App Bundle ID for iOS to your App Bundle in Xcode -> Target -> Bundle Identifier (e.g. com.developer.applicationName)

Finally, open up your App's Xcode project and go to the project's info tab. Under "URL Types", add a new entry, and in the URL schemes form field, type in vk[CLIENT_ID_HERE]. Then, you can initiate the login screen by calling:

Simplicity.login(VKontakte()) { (accessToken, error) in
  // Handle access token here
}

Generic OAuth Provider

Simplicity supports any OAuth provider that implements the Implicit grant type.

let provider = OAuth2(clientId: clientId, authorizationEndpoint: authorizationEndpoint, redirectEndpoint: redirectEndpoint, grantType: .Implicit)

Simplicity.login(provider) { (accessToken, error) in
  // Handle access token here
}

Requesting Scopes for OAuth Providers

If you need custom scopes, you can modify the Facebook or Google object to get them.

let facebook = Facebook()
facebook.scopes = ["public_profile", "email", "user_friends"]

Simplicity.login(facebook) { (accessToken, error) in
  // Handle access token here
}

Twitter, LinkedIn, and GitHub

We can't implement Twitter, GitHub, LinkedIn, Slack, or other login types because we can't do authorization_code grants without a client secret. Client secrets are fundamentally insecure on mobile clients, so we need to create a companion server to help with the authentication request.

If this is something you'd like to see, please +1 or follow this GitHub Issue to create a companion server so I know that there's demand for this.

Other External Login Providers

Want another external login provider implemented? Please open a GitHub issue so I know it's in demand, or consider contributing to this project!

Contributing

Please send a pull request with your new LoginProvider implemented. LoginProviders should try to autoconfigure where possible.

License

Simplicity is available under the Apache 2.0 license. See the LICENSE file for more info.

Comments
  • I have everything setup, yet calling the login function appears to do nothing.

    I have everything setup, yet calling the login function appears to do nothing.

    I called the function 'Simplicity.login(Google())' within my viewDidLoad() function in the ViewController.swift file.

    I expected something to happen when I tried to print the accessToken within the function's scope, yet nothing happens when the code runs. There's no errors so I'd like to know what step I'm missing.

    Thanks!

    opened by knakamura13 6
  • Modifying autolayout from background thread

    Modifying autolayout from background thread

    Hi, I'm getting this error when using the google login feature

    This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release.

    I believe it is a result of using datatask in the google loginhandler.

    Please checkout this stackoverflow post , I believe it could be fixed by wrapping the callback call with:

    if error == nil {
        dispatch_async(dispatch_get_main_queue(), {
            self.handleRequest(...)I
        })
    }
    
    opened by mikkelam 5
  • Extracting data out of AccessToken

    Extracting data out of AccessToken

    Hello there, thanks for this nice library.

    The Google-Login works fine. Now I want to get the E-Mail-Information out of the AccessToken. Is this possible with your library? If not, what next step do you recommend? (For example picking up another library).

    The thing is, getting the E-Mail out of access token is the only functionality I need, and using other Libs seems to be way too overkill for that.

    Thanks in advance.

    opened by quiKsilverItaly 4
  • Present SafariView on top most viewController

    Present SafariView on top most viewController

    Hi,

    There seems to be no available way of presenting the SafariView if another viewController is already being presented.

    Is that wanted or will it be changed?

    Cordially, Louis.

    opened by LouisBorlee 4
  • Facebook returns AccessToken with no E-Mail-Information

    Facebook returns AccessToken with no E-Mail-Information

    I did this:

    let facebook = Facebook()
    facebook.scopes = ["email"]
            
    Simplicity.login(facebook) { (accessToken, error) in
    //do something
    }
    

    After getting the AccessToken back, I make a HTTP-Request with this URL: https://graph.facebook.com/me?access_token= and get following result:

    { "name": "My Name", "id": "10972xxxxxxx718" }

    No E-Mail information.. any ideas? I also tried the default way: Simplicity.login(Facebook())

    opened by quiKsilverItaly 2
  • Issue regarding presenting safari viewcontroller from root view controller

    Issue regarding presenting safari viewcontroller from root view controller

    I have a login view controller that is presented modally which uses the simplicity. But since the root view controllers view is not currently on top of the window stack the system throws a warning that the view controller (safari) cannot be presented since the view is not visible. I did fix it. Do you mind if i issue a pull request.

    opened by Dharin-shah 2
  • Open app if installed in providers

    Open app if installed in providers

    Hello, Edward.

    I've little bit modified sources, and now there is an ability to open Vkontakte and Facebook apps if they are installed, if not - safari will be opened. I've created VkProvider and FbProvider with corresponding logic inside, and then Simplicity.swift and linkhandler.

    opened by rgnlax 2
  • Objective-c

    Objective-c

    Hi

    I'm trying to make it work using objective-c.

    Cannot found hot to call this using Obj-C syntax. Can i please ask if someone have done it with success?

    Thanks!

    Simplicity.login(Facebook()) { (accessToken, error) in // Handle access token here }

    opened by FreudGit 1
  • Getting public_profile,email

    Getting public_profile,email

    Hello,

    How would I go about getting public_profile and email? After I get the token I can get the "name" and "id" fields, but how would I go about getting the rest of that information?

    Thank you

    opened by Marini83 1
  • error presenting safari uiviewcontroller

    error presenting safari uiviewcontroller

    Simplicity[4031:40778] Warning: Attempt to present <SFSafariViewController: 0x7fd56ae95ea0> on <faceBookAPI_2_Simplicity.ViewController: 0x7fd56ae8a120> whose view is not in the window hierarchy!

    Why would I be getting this error? Thanks in advance for your help.

    opened by Ged2323 1
  • Add Track App Installs and App Opens!!

    Add Track App Installs and App Opens!!

    This would be a brilliant feature if you could add it in this repo. Thanks!!

    App Events let you measure installs on your mobile app ads, create high value audiences for targeting, and view analytics including user demographics. To log an app activation event, first, import the Facebook SDK in your AppDelegate.m file:

    import <FBSDKCoreKit/FBSDKCoreKit.h>

    Next, add the following to your app delegate:

    • - (void)applicationDidBecomeActive:(UIApplication *)application { [FBSDKAppEvents activateApp]; }
    • - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; return YES; }
    • - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; } When people install or engage with your app, you'll see this data reflected in your app's Insights dashboard.
    opened by Dershowitz011 1
  • Swift 4.1 + iOS 11 (SFAuthenticationSession)

    Swift 4.1 + iOS 11 (SFAuthenticationSession)

    Hi,

    Changes:

    • Project is now compatible with Swift 4.1.
    • Solved crashed with CFBundleURLSchemes if fb scheme isn't first.
    • Implemented SFAuthenticationSession if available.
    • Send more url parameter for Facebook to display the button "connect via facebook app" (else, only email/password is available).

    I suggest:

    • More testing (other than Facebook)
    • Updating library version to 3.0

    Edit: you can check the fb implementation of this API here

    Cheers, Vincent

    opened by Vinzius 1
  • App will crash if the fb scheme isn't first in CFBundleURLSchemes

    App will crash if the fb scheme isn't first in CFBundleURLSchemes

    Hey !

    First, thanks for your lib 👍

    I noticed that if you don't put the fb scheme in the CFBundleURLSchemes list, then the app will produce an error / crash (at least it'll go to preconditionFailure).

    Reason if that at this line let urlSchemes = urlTypes.flatMap({($0["CFBundleURLSchemes"] as? [String])?.first }) you take .first, instead you could do a reduce instead of the flatMap.

    Would you merge a PR if I were to submit one?

    Thanks, Vincent

    opened by Vinzius 4
Releases(2.0.1)
  • 2.0.1(Sep 30, 2016)

  • 2.0(Sep 13, 2016)

  • 1.0.2(Jul 15, 2016)

    Added support for VK, the largest European social network.

    Also added a convenience method for logging in. Now you can call .login() on any LoginProvider:

    Facebook().login { (accessToken, error) in
      // Handle access token here
    }
    
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(May 23, 2016)

  • 1.0(May 20, 2016)

    An easy way to login with Facebook or Google.

    Supports:

    • Login with Facebook
    • Login with Google
    • OAuth 2 Scopes
    • Facebook's "Auth Type" feature
    • Extensible to more providers
    Source code(tar.gz)
    Source code(zip)
Owner
Simplicity Mobile
A framework for easy mobile authentication
Simplicity Mobile
SwiftCoreDataLoginPage - Login and registration with core data

Login and Registration Page with CoreData In this basic project, which was used

Buse Köseoğlu 2 Aug 22, 2022
SimpleAuth is designed to do the hard work of social account login on iOS

SimpleAuth is designed to do the hard work of social account login on iOS. It has a small set of public APIs backed by a set of "providers"

Caleb Davenport 1.2k Nov 17, 2022
An poc to make a login using Auth0 in Swift

Swift-Auth0-poc This app is an poc to make a login using Auth0. If you want to try it yourself here is a small tutorial on how to do it. 1. Configure

Sem de Wilde 1 Jan 21, 2022
ReCaptcha - Add Google's Invisible ReCaptcha v2 to your project

Add Google's Invisible ReCaptcha v2 to your project. This library automatically handles ReCaptcha's events and retrieves the validation token or notifies you to present the challenge if invisibility is not possible.

Flávio Caetano 250 Dec 5, 2022
A quick and simple way to authenticate an Instagram user in your iPhone or iPad app.

InstagramSimpleOAuth A quick and simple way to authenticate an Instagram user in your iPhone or iPad app. Adding InstagramSimpleOAuth to your project

Ryan Baumbach 90 Aug 20, 2022
A quick and simple way to authenticate a Dropbox user in your iPhone or iPad app.

DropboxSimpleOAuth A quick and simple way to authenticate a Dropbox user in your iPhone or iPad app. Adding DropboxSimpleOAuth to your project CocoaPo

Ryan Baumbach 42 Dec 29, 2021
A quick and simple way to authenticate a Box user in your iPhone or iPad app.

BoxSimpleOAuth A quick and simple way to authenticate a Box user in your iPhone or iPad app. Adding BoxSimpleOAuth to your project CocoaPods CocoaPods

Ryan Baumbach 15 Mar 10, 2021
A simple library to make authenticating tvOS apps easy via their iOS counterparts.

Voucher The new Apple TV is amazing but the keyboard input leaves a lot to be desired. Instead of making your users type credentials into their TV, yo

Riz 516 Nov 24, 2022
Krypton turns your iOS device into a WebAuthn/U2F Authenticator: strong, unphishable 2FA.

Krypton turns your iOS device into a WebAuthn/U2F Authenticator: strong, unphishable 2FA. Krypton implements the standardized FIDO Universal 2nd Facto

krypt.co 332 Nov 5, 2022
LinkedInSignIn - Simple view controller to log in and retrieve an access token from LinkedIn.

LinkedInSignIn Example To run the example project, clone the repo, and run pod install from the Example directory first. Also you need to setup app on

Serhii Londar 34 Sep 1, 2022
Example of simple OAuth2 authentication using Alamofire 5 and RxSwift library

REST Client based on Alamofire 5 and RxSwift library. Supports OAuth2 and Basic authentication interceptor.

Tomáš Smolík 3 Dec 8, 2022
A simple OAuth library for iOS with a built-in set of providers

SwiftyOAuth is a small OAuth library with a built-in set of providers and a nice API to add your owns. let instagram: Provider = .instagram(clientID:

Damien 477 Oct 15, 2022
A simple project for Face ID Authentication for iOS device using LocalAuthentication Framework

BiometricAuthentication This respository is a simple project for Face ID Authentication for iOS device using LocalAuthentication Framework and infoPli

Lee McCormick 0 Oct 23, 2021
Simple OAuth2 library with a support of multiple services.

Simple OAuth2 library with a support of multiple services.

HyperRedink 68 May 13, 2022
A simple to use, standard interface for authenticating to oauth 2.0 protected endpoints via SFSafariViewController.

AuthenticationViewController A simple to use, standard interface for authenticating to OAuth 2.0 protected endpoints via SFSafariViewController. Instr

Raul Riera 256 Dec 14, 2022
OAuth2 framework for macOS and iOS, written in Swift.

OAuth2 OAuth2 frameworks for macOS, iOS and tvOS written in Swift 5.0. ⤵️ Installation ?? Usage ?? Sample macOS app (with data loader examples) ?? Tec

Pascal Pfiffner 1.1k Jan 2, 2023
Swift based OAuth library for iOS and macOS

OAuthSwift Swift based OAuth library for iOS and macOS. Support OAuth1.0, OAuth2.0 Twitter, Flickr, Github, Instagram, Foursquare, Fitbit, Withings, L

OAuthSwift 3.1k Jan 3, 2023
InstagramLogin allows iOS developers to authenticate users by their Instagram accounts.

InstagramLogin handles all the Instagram authentication process by showing a custom UIViewController with the login page and returning an access token that can be used to request data from Instagram.

Ander Goig 67 Aug 20, 2022
Easy to use OAuth 2 library for iOS, written in Swift.

Heimdallr Heimdallr is an OAuth 2.0 client specifically designed for easy usage. It currently supports the resource owner password credentials grant f

trivago N.V. 628 Oct 17, 2022