[aerogear-dev] OAuth2 authotization and Pipe integration
Corinne Krych
corinnekrych at gmail.com
Thu May 15 03:56:28 EDT 2014
Hello folks
I’ve been thinking about providing a more fluid integration between authz and pipes.
Right now to read a list of GoogleDrive document, we need to read the pipe in the success callback of authz’ requestAccess:
AGAuthorizer* authorizer = [AGAuthorizer authorizer];
_restAuthzModule = [authorizer authz:^(id<AGAuthzConfig> config) {
...
}];
[_restAuthzModule requestAccessSuccess:^(id object) {
id<AGPipe> documents = [googleDocuments pipe:^(id<AGPipeConfig> config) {
[config setName:@"files"];
[config setAuthzModule:authzModule]; // inject authz
}];
[documents read:^(id responseObject) {
// do sth with response
} failure:^(NSError *error) {
// when an error occurs...
}];
} failure:^(NSError *error) {
NSLog(@"Failure in getting access token");
}];
What about if we just initialize authzModule and inject it into pipe. Once the pipe read (or any crud) it will be the pipe that first fetch tokens (or renew - whaetever is needed) and on success read the pipe. Basically we do the callback chaining internally in the Pipe instead of letting the developer deal with it.
AGAuthorizer* authorizer = [AGAuthorizer authorizer];
_restAuthzModule = [authorizer authz:^(id<AGAuthzConfig> config) {
...
}];
id<AGPipe> documents = [googleDocuments pipe:^(id<AGPipeConfig> config) {
[config setName:@"files"];
[config setAuthzModule:authzModule]; // inject authz
}];
[documents read:^(id responseObject) {
// do sth with response
} failure:^(NSError *error) {
// when an error occurs...
}];
It feels much fluid on the user.
Doing so we “force” the app flow to ask token when it needs it, not in advance at startup of app. but i think this is good practice to lazy authz your app.
Thoughts?
Test repo can be found here:
https://github.com/corinnekrych/aerogear-ios/blob/transparent.refresh/AeroGear-iOS/pipeline/AGRESTPipe.m#L169
https://github.com/corinnekrych/aerogear-ios-cookbook-1/blob/AGIOS-145.refresh/GoogleDrive/GoogleDrive/AGViewController.m
++
Corinne
More information about the aerogear-dev
mailing list