diff --git a/CHANGELOG.md b/CHANGELOG.md index 843e6cefc..e8dd48fbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. ##master +##Changed +- Fix how `connection_scopes` parameter was handled. + +## 1.10.0 - 2015-03-16 + ###Added - Property to hide statusBar in `A0Theme`. diff --git a/Lock/Tests/A0AuthParametersSpec.m b/Lock/Tests/A0AuthParametersSpec.m index c7a969f09..42e0266bd 100644 --- a/Lock/Tests/A0AuthParametersSpec.m +++ b/Lock/Tests/A0AuthParametersSpec.m @@ -186,6 +186,7 @@ @"google": @[], @"linkedin": @[@"public_profile"], }; + [params setValue:@"facebook" forKey:A0ParameterConnection]; params.state = @"TEST"; params.device = @"Specta Test"; [params setValue:@"bar" forKey:@"foo"]; @@ -196,16 +197,10 @@ expect(dict[A0ParameterScope]).to.equal(@"openid profile offline_access"); }); - it(@"should coalesce connection_scopes for FB in a NSString", ^{ - expect(dict[A0ParameterConnectionScopes][@"facebook"]).to.equal(@"email,friends"); - }); - - it(@"should coalesce connection_scopes for linkedin in a NSString", ^{ - expect(dict[A0ParameterConnectionScopes][@"linkedin"]).to.equal(@"public_profile"); - }); - - it(@"should skip connection_scopes for twitter", ^{ - expect(dict[A0ParameterConnectionScopes][@"twitter"]).to.beNil(); + it(@"should include specified scopes for connection", ^{ + NSDictionary *payload = [params asAPIPayload]; + expect(payload.allKeys).to.contain(@"connection_scope"); + expect(payload[@"connection_scope"]).to.equal(@"email,friends"); }); it(@"should have state", ^{ diff --git a/Pod/Classes/Core/A0AuthParameters.m b/Pod/Classes/Core/A0AuthParameters.m index b782fe5cf..c209654bc 100644 --- a/Pod/Classes/Core/A0AuthParameters.m +++ b/Pod/Classes/Core/A0AuthParameters.m @@ -115,13 +115,16 @@ + (instancetype)newWithScopes:(NSArray *)scopes { } - (NSDictionary *)asAPIPayload { - NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:self.params]; - params[A0ParameterScope] = ScopeValueFromNSArray(self.params[A0ParameterScope]); + NSMutableDictionary *params = self.params.mutableCopy; + [params removeObjectsForKeys:@[A0ParameterScope, A0ParameterConnectionScopes]]; + NSMutableDictionary *payload = [NSMutableDictionary dictionaryWithDictionary:params]; + payload[A0ParameterScope] = ScopeValueFromNSArray(self.params[A0ParameterScope]); NSDictionary *connectionScopes = self.params[A0ParameterConnectionScopes]; - if (connectionScopes.count > 0) { - params[A0ParameterConnectionScopes] = ConnectionScopeValuesFromNSDictionary(connectionScopes); + NSArray *connectionScope = connectionScopes[self.params[A0ParameterConnection]]; + if (connectionScope) { + payload[@"connection_scope"] = [connectionScope componentsJoinedByString:@","]; } - return [NSDictionary dictionaryWithDictionary:params]; + return payload; } - (NSArray *)scopes { diff --git a/Pod/Classes/Provider/Facebook/A0FacebookAuthenticator.m b/Pod/Classes/Provider/Facebook/A0FacebookAuthenticator.m index 833b6d342..4dbd01140 100644 --- a/Pod/Classes/Provider/Facebook/A0FacebookAuthenticator.m +++ b/Pod/Classes/Provider/Facebook/A0FacebookAuthenticator.m @@ -26,6 +26,7 @@ #import "A0Application.h" #import "A0APIClient.h" #import "A0IdentityProviderCredentials.h" +#import "A0AuthParameters.h" #import #import @@ -92,7 +93,8 @@ -(void)authenticateWithParameters:(A0AuthParameters *)parameters success:(void ( [self executeAuthenticationWithCredentials:[[A0IdentityProviderCredentials alloc] initWithAccessToken:active.accessTokenData.accessToken] parameters:parameters success:success failure:failure]; } else { @weakify(self); - [FBSession openActiveSessionWithReadPermissions:self.permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { + NSArray *permissions = [self permissionsFromParameters:parameters]; + [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { if (error) { if (failure) { A0LogError(@"Failed to open FB Session with error %@", error); @@ -122,6 +124,12 @@ -(void)authenticateWithParameters:(A0AuthParameters *)parameters success:(void ( #pragma mark - Utility methods +- (NSArray *)permissionsFromParameters:(A0AuthParameters *)parameters { + NSArray *connectionScopes = parameters.connectionScopes[A0StrategyNameFacebook]; + NSArray *permissions = connectionScopes.count > 0 ? connectionScopes : self.permissions; + A0LogDebug(@"Facebook Permissions %@", permissions); + return permissions; +} - (void)executeAuthenticationWithCredentials:(A0IdentityProviderCredentials *)credentials parameters:(A0AuthParameters *)parameters success:(void(^)(A0UserProfile *, A0Token *))success diff --git a/Pod/Classes/Provider/GooglePlus/A0GooglePlusAuthenticator.m b/Pod/Classes/Provider/GooglePlus/A0GooglePlusAuthenticator.m index adec7a308..b7a7bc764 100644 --- a/Pod/Classes/Provider/GooglePlus/A0GooglePlusAuthenticator.m +++ b/Pod/Classes/Provider/GooglePlus/A0GooglePlusAuthenticator.m @@ -27,12 +27,14 @@ #import "A0APIClient.h" #import "A0IdentityProviderCredentials.h" #import "A0Errors.h" +#import "A0AuthParameters.h" @interface A0GooglePlusAuthenticator () @property (copy, nonatomic) void (^successBlock)(A0UserProfile *, A0Token *); @property (copy, nonatomic) void (^failureBlock)(NSError *); @property (strong, nonatomic) A0AuthParameters *parameters; @property (assign, nonatomic) BOOL authenticating; +@property (strong, nonatomic) NSArray *scopes; @end @implementation A0GooglePlusAuthenticator @@ -48,15 +50,8 @@ - (instancetype)initWithClientId:(NSString *)clientId scopes:(NSArray *)scopes { if (self) { GPPSignIn *signIn = [GPPSignIn sharedInstance]; signIn.clientID = clientId; - NSMutableSet *scopeSet = [[NSMutableSet alloc] init]; - [scopeSet addObject:kGTLAuthScopePlusLogin]; - [scopeSet addObject:kGTLAuthScopePlusUserinfoEmail]; - if (scopes) { - [scopeSet addObjectsFromArray:scopes]; - } - signIn.scopes = [scopeSet allObjects]; + self.scopes = [scopes copy]; signIn.delegate = self; - A0LogDebug(@"Initialised Google+ authenticator with scopes %@", signIn.scopes); [self clearCallbacks]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; } @@ -88,6 +83,7 @@ - (void)authenticateWithParameters:(A0AuthParameters *)parameters self.failureBlock = failure; self.parameters = parameters; GPPSignIn *signIn = [GPPSignIn sharedInstance]; + signIn.scopes = [self scopesFromParameters:parameters]; self.authenticating = YES; [signIn authenticate]; A0LogVerbose(@"Starting Google+ Authentication..."); @@ -129,6 +125,19 @@ - (void)finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error #pragma mark - Utility methods +- (NSArray *)scopesFromParameters:(A0AuthParameters *)parameters { + NSMutableSet *scopeSet = [[NSMutableSet alloc] init]; + [scopeSet addObject:kGTLAuthScopePlusLogin]; + [scopeSet addObject:kGTLAuthScopePlusUserinfoEmail]; + NSArray *connectionScopes = parameters.connectionScopes[A0StrategyNameFacebook]; + NSArray *scopes = connectionScopes.count > 0 ? connectionScopes : self.scopes; + if (scopes) { + [scopeSet addObjectsFromArray:scopes]; + } + A0LogDebug(@"Google+ scopes %@", scopeSet); + return [scopeSet allObjects]; +} + - (void)clearCallbacks { self.failureBlock = ^(NSError *error) {}; self.successBlock = ^(A0UserProfile* profile, A0Token *token) {};