Created
October 4, 2012 13:42
-
-
Save matzew/3833597 to your computer and use it in GitHub Desktop.
Usage of AGAuthenticationManager and AGAuthenticationModule for signup/signin/signout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 success:^(id data) { | |
// after a successful _registration_, we can work | |
// with the returned data... | |
NSLog(@"We got: %@", data); | |
} failure:^(NSError *error) { | |
// when an error occurs... at least log it to the console.. | |
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" success:^(id object) { | |
// after a successful _login_, we can work | |
// with the returned data... | |
} failure:^(NSError *error) { | |
// when an error occurs... at least log it to the console.. | |
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:^{ | |
// after a successful _logout_, when can notify the application | |
} failure:^(NSError *error) { | |
// when an error occurs... at least log it to the console.. | |
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