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/Aer...
https://github.com/corinnekrych/aerogear-ios-cookbook-1/blob/AGIOS-145.re...
++
Corinne