-
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
- Go to your project
- Right-click in the Frameworks folder and select Add Files to "Your Project Name"
- Go to the Auth0.iOS, select the Auth0Client folder, ensure that your project target is selected and press Add
-
Instantiate Auth0Client
#import "Auth0Client.h" // ... Auth0Client *client = [Auth0Client auth0Client:@"YOUR_AUTH0_DOMAIN" clientId:@"YOUR_CLIENT_ID"];
-
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) { ... }];
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.
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"]
}];
-
Install and configure your app in order to work with Facebook SDK for iOS.
-
Implement Facebook login in your iOS app. There are two ways:
- Using the Facebook login button
- Implementing your custom login UI using API calls
-
Once the user is authenticated with Facebook App Native, call to the
loginAsync
method specifying the Facebookaccess_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.
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.
- Go to Auth0 and click Sign Up.
- Use Google, GitHub or Microsoft Account to login.