Skip to content

Instantly share code, notes, and snippets.

@matzew
Created October 4, 2012 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matzew/3833597 to your computer and use it in GitHub Desktop.
Save matzew/3833597 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 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