Git Product home page Git Product logo

auth0.ios's Introduction

#Auth0 iOS Client License MIT Badge w/ Version Badge w/ Platform

Usage

  1. Install library in your project

    If you are using CocoaPods, add the following line to your Podfile

    pod 'Auth0Client'

    Or just git clone and reference the library in your project following these steps:

    git clone [email protected]:auth0/Auth0.iOS.git
    1. Go to your project
    2. Right-click in the Frameworks folder and select Add Files to "Your Project Name"
    3. Go to the Auth0.iOS, select the Auth0Client folder, ensure that your project target is selected and press Add
  2. Instantiate Auth0Client

    #import "Auth0Client.h"
    
    // ...
    
    Auth0Client *client = [Auth0Client auth0Client:@"YOUR_AUTH0_DOMAIN" clientId:@"YOUR_CLIENT_ID"];
  3. Trigger login (with Widget)

    [client loginAsync:self withCompletionHandler:^(NSMutableDictionary* error) {
    if (error) {
    	NSLog(@"Error authenticating: %@", [error objectForKey:@"error"]);
    }
    else {
      // * Use client.auth0User to do wonderful things, e.g.:
      // - get user email => [client.auth0User.Profile objectForKey:@"email"]
      // - get facebook/google/twitter/etc access token => [[[client.auth0User.Profile objectForKey:@"identities"] objectAtIndex:0] objectForKey:@"access_token"]
      // - get Windows Azure AD groups => [client.auth0User.Profile objectForKey:@"groups"]
      // - etc.
    }
    }];

Or you can use the connection as a parameter (e.g. here we login with a Windows Azure AD account)

[client loginAsync:self connection:@"auth0waadtests.onmicrosoft.com" withCompletionHandler:^(NSMutableDictionary* error) { ... }];

Login with User/Password (without WebView)

Only certain providers support this option (Database Connections, AD Connector and ADFS)..

[client loginAsync:self connection:@"my-db-connection"
						username:@"username"
						password:@"password"
						withCompletionHandler:^(NSMutableDictionary* error) {
	if (error) {
		NSLog(@"Error authenticating: %@ - %@", [error objectForKey:@"error"], [error objectForKey:@"error_description"]);
	}
	else {
		// * Use client.auth0User to do wonderful things, e.g.:
		// - get user email => [client.auth0User.Profile objectForKey:@"email"]
		// - get facebook/google/twitter/etc access token => [[[client.auth0User.Profile objectForKey:@"identities"] objectAtIndex:0] objectForKey:@"access_token"]
		// - get Windows Azure AD groups => [client.auth0User.Profile objectForKey:@"groups"]
		// - etc.
	}
}];

Optionally you can specify the scope parameter. There are two possible values for scope today:

  • scope:@"openid" (default) - It will return, not only the access_token, but also an id_token which is a Json Web Token (JWT). The JWT will only contain the user id.
  • scope:@"openid profile": If you want the entire user profile to be part of the id_token.

Delegation Token Request

You can obtain a delegation token specifying the ID of the target client (targetClientId) and, optionally, an NSMutableDictionary object (options) in order to include custom parameters like scope or id_token:

NSMutableDictionary *options = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
	@"USER_ID_TOKEN", @"id_token", 	// default: id_token of the authenticated user (client.auth0User.IdToken)
	@"openid profile", @"scope", 	// default: openid
	nil];

[client getDelegationToken:targetClientId options:options withCompletionHandler:^(NSMutableDictionary* delegationResult)
{
	// [delegationResult objectForKey:@"id_token"]
}];

Authentication with Facebook App Native Login Dialog

  1. Install and configure your app in order to work with Facebook SDK for iOS.

  2. Implement Facebook login in your iOS app. There are two ways:

  3. Once the user is authenticated with Facebook App Native, call to the loginAsync method specifying the Facebook access_token:

NSString *fb_access_token = [[FBSession.activeSession accessTokenData] accessToken];

[client loginAsync:self connection:@"facebook"
						accessToken:fb_access_token
						withCompletionHandler:^(NSMutableDictionary* error) {
	if (error) {
		NSLog(@"Error authenticating: %@ - %@", [error objectForKey:@"error"], [error objectForKey:@"error_description"]);
	}
	else {
		// Use client.auth0User to do wonderful things
	}
}];

For more details, you can check our sample.


What is Auth0?

Auth0 helps you to:

  • Add authentication with multiple authentication sources, either social like Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, or enterprise identity systems like Windows Azure AD, Google Apps, AD, ADFS or any SAML Identity Provider.
  • Add authentication through more traditional username/password databases.
  • Add support for linking different user accounts with the same user.
  • Support for generating signed Json Web Tokens to call your APIs and flow the user identity securely.
  • Analytics of how, when and where users are logging in.
  • Pull data from other sources and add it to the user profile, through JavaScript rules.

Create a free account in Auth0

  1. Go to Auth0 and click Sign Up.
  2. Use Google, GitHub or Microsoft Account to login.

auth0.ios's People

Contributors

ezequielm avatar hzalaz avatar martinrybak avatar mgonto avatar reallyseth avatar siacomuzzi avatar woloski avatar

Watchers

 avatar  avatar

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.