From 38ddd141468556b930e8c3eedbd252e0295e801c Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Mon, 4 Apr 2016 18:18:01 -0300 Subject: [PATCH 1/2] Allow to user refresh_token in delegation method --- A0RNLock/Core/A0LockReact.m | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/A0RNLock/Core/A0LockReact.m b/A0RNLock/Core/A0LockReact.m index fb5ca79..3146365 100644 --- a/A0RNLock/Core/A0LockReact.m +++ b/A0RNLock/Core/A0LockReact.m @@ -149,19 +149,32 @@ - (void)delegationWithOptions:(NSDictionary *)options callback:(A0LockCallback)c callback(@[@"Please configure Lock before using it"]); return; } - if (!options[@"api"]) { - callback(@[@"Must specify api in options."]); - return; + + NSString *api = options[@"api"]; + if (!api) { + api = @"app"; } - if (!options[@"id_token"]) { - callback(@[@"Must specify id_token in options"]); + + NSString *token = options[@"token"]; + NSString *refreshToken = options[@"refresh_token"]; + + if (token && refreshToken) { + callback(@[@"Must specify either a token or a refreshToken in options"]); return; } - if (!options[@"scope"]) { - callback(@[@"Must specify scope in options"]); + + if (!token && !refreshToken) { + callback(@[@"Must specify at least a token or a refreshToken in options"]); return; } + NSString *scope = options[@"scope"]; + if (!scope) { + scope = @"openid"; + } + + NSString *target = options[@"target"]; + A0APIClient *client = [self.lock apiClient]; void(^success)(NSDictionary *) = ^(NSDictionary *credentials) { @@ -171,11 +184,16 @@ - (void)delegationWithOptions:(NSDictionary *)options callback:(A0LockCallback)c callback(@[[error localizedDescription]]); }; + NSString *tokenKey = refreshToken ? @"refresh_token" : @"id_token"; + NSString *tokenValue = refreshToken ? refreshToken : token; A0AuthParameters *parameters = [A0AuthParameters newWithDictionary:@{ A0ParameterAPIType: options[@"api"], - @"id_token": options[@"id_token"], + tokenKey: tokenValue, A0ParameterScope: [self scopeParamterFromOptions:options], }]; + if (target) { + parameters[@"target"] = target; + } [client fetchDelegationTokenWithParameters:parameters success:success failure:failure]; } From ad8488f7289d608d23acee2b54f0f0a25cfbb5f5 Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Mon, 4 Apr 2016 18:19:26 -0300 Subject: [PATCH 2/2] Fix name in JS --- A0RNLock/A0LockReactModule.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/A0RNLock/A0LockReactModule.m b/A0RNLock/A0LockReactModule.m index 08cd13f..8d0dea3 100644 --- a/A0RNLock/A0LockReactModule.m +++ b/A0RNLock/A0LockReactModule.m @@ -97,7 +97,7 @@ @implementation A0LockReactModule }); } -RCT_EXPORT_METHOD(getDelegationToken:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback) { +RCT_EXPORT_METHOD(delegation:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback) { dispatch_async(dispatch_get_main_queue(), ^{ [[A0LockReact sharedInstance] delegationWithOptions:options callback:callback]; }); @@ -109,4 +109,4 @@ @implementation A0LockReactModule }); } -@end \ No newline at end of file +@end