TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Hernan Zalazar, Sebastian Iacomuzzi, Eugenio Pace.
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
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 and Active Directory/LDAP).
[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"]
}];
The
options
parameter must not include theclient_id
andtarget
keys.target
is populated fromtargetClientId
andclient_id
uses the id used when creeating theAuth0Client
instance.
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:
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.
Auth0 helps you to: