Skip to content

Instantly share code, notes, and snippets.

@elm4ward
Forked from matzew/gist:3833597
Created October 5, 2012 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elm4ward/3838469 to your computer and use it in GitHub Desktop.
Save elm4ward/3838469 to your computer and use it in GitHub Desktop.
Usage of AGAuthenticationManager and AGAuthenticationModule for signup/signin/signout
// create an auth manager object
AGAuthenticationManager* authMgr = [AGAuthenticationManager manager];
// add a new auth module and the required 'base url':
NSURL* baseURL = [NSURL URLWithString:@"https://todoauth-aerogear.rhcloud.com/todo-server"];
id<AGAuthenticationModule> myMod = [authMgr add:@"authMod" baseURL:baseURL];
// ====================================
// =========== REGISTRATION ===========
// ====================================
// assemble the dictionary that has all the data for THIS particular user:
NSMutableDictionary* userData = [NSMutableDictionary dictionary];
[userData setValue:@"john" forKey:@"username"];
[userData setValue:@"123" forKey:@"password"];
[userData setValue:@"me@you.com" forKey:@"email"];
[userData setValue:@"21sda812sad24" forKey:@"betaAccountToken"];
// with the default/REST auth module, the following issues
// http a request against:
// https://todoauth-aerogear.rhcloud.com/todo-server/auth/register ...
[myMod enroll:userData completion:^(id data, NSError *error) {
// after a successful _registration_, we can work
//or when an error occurs... at least log it to the console..
if(error){
NSLog(@"SAVE: An error occured! \n%@", error);
}
}];
// =============================
// =========== LOGIN ===========
// =============================
// with the default/REST auth module, the following issues
// http a request against:
// https://todoauth-aerogear.rhcloud.com/todo-server/auth/login ...
[myMod login:@"john" password:@"123" completion:^(id object, NSError *error) {
// after a successful _login_, we can work with the returned data...
// or when an error occurs... at least log it to the console..
if(error){
NSLog(@"SAVE: An error occured! \n%@", error);
}
}];
// ==============================
// =========== LOGOUT ===========
// ==============================
// with the default/REST auth module, the following issues
// http a request against:
// https://todoauth-aerogear.rhcloud.com/todo-server/auth/logout ...
[myMod logout:^(NSError *error) {
// after a successful _logout_, when can notify the application
// when an error occurs... at least log it to the console..
if(error){
NSLog(@"SAVE: An error occured! \n%@", error);
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment