Code Monkey home page Code Monkey logo

simplicity's Introduction

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.

simplicity's People

Contributors

edjiang avatar omgitstom avatar pherret avatar talisk avatar teameh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplicity's Issues

LINE

Hi, can you create a provider for LINE? Thank you so much!

Callback not called

Hi, when the user press the Done button at the top of the safari view the simplicity callback is not called. I think it should be because now the code can't have any clue if the safari view is cancelled like this.

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.

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

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.

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.

Swift 3.0

Do you plan to support Swift 3.0? It's few days till Xcode 8 official release.

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.

Flickr

Can you create a provider for Flickr?

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.

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!

Carthage Compatible!

Please share the scheme and update this. Carthage is unable to build a scheme for this.

Instagram

Hi, have you thought of a new provider for Instagram? Thanks

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
}

vk.com

If their API is not well-documented in English, I can help.

Create a companion server that handles authorization_code flows

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.

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

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
    })
}

FB Login in testflight and Store

Hi, FB login works fine in local but when I upload the app to TestFlight or Store is not working (My FB App is in production mode).

Google login keeps asking for authorizations

Hi everyone,

I was wondering why this strange behavior happen in my project : every time I try to re-connect to an account I already logged into, the Google Explorer (whom already know my password) keep asking me authorizations, even if it's my 3rd login to the same account.
If I take a look at the Google documentation, it shouldn't be asking me permission over time :

Before making the first authenticated call, the Explorer asks you to choose which scope you would like to use when granting it access to your data.

Here's the code responsible for the login, but I guess this behavior doesn't come from him :)

let google = Google()
google.scopes = ["email"]
google.login { [unowned self] (accessToken, error) in
    if let token = accessToken {
        print("Call Google API with token : \(token)")
    }
}

So I was wondering if you guys know about that, and if a workaround exists :)

Thank you!
Jérôme

Multiple app launch

Hi, Simplicity is working great in my project but what is the preferred way to store the token after getting it ? Can you provide a tiny sample ?

id_token Google

When connecting with Google, there is a way to get the access_token AND the id_token (used for private api) ?

Modals and safaryViewController bug

Hi,

I'm using modals in my projects and if I use simplicity to open the safariController It dismiss my modals so its not convenient from the user point of view. I've fixed it by adding :

safari?.modalPresentationStyle = .overFullScreen

just before
topController?.present(safari!, animated: true, completion: nil)

in presentSafariView(_ url:) in Simplicity class

As safariView is present over full screen anyway I don't think there are drawbacks to do so. Can I have you point of view on this ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.