diff --git a/Lock/Tests/A0IdentityProviderAuthenticatorSpec.m b/Lock/Tests/A0IdentityProviderAuthenticatorSpec.m index 18ab2b108..3438ca948 100644 --- a/Lock/Tests/A0IdentityProviderAuthenticatorSpec.m +++ b/Lock/Tests/A0IdentityProviderAuthenticatorSpec.m @@ -177,6 +177,23 @@ @interface A0IdentityProviderAuthenticator (TestAPI) }); + context(@"authenticate with known strategy name", ^{ + + void(^failureBlock)(NSError *) = ^(NSError *error) {}; + beforeEach(^{ + [authenticator authenticateForStrategyName:strategy.name parameters:nil success:successBlock failure:failureBlock]; + }); + + it(@"should call the correct provider", ^{ + [MKTVerify(provider) authenticateWithParameters:nil success:successBlock failure:failureBlock]; + }); + + it(@"should tell it can authenticate", ^{ + expect([authenticator canAuthenticateStrategy:strategy]).to.beTruthy(); + }); + + }); + context(@"authenticate with unknown strategy", ^{ __block A0Strategy *unknown; diff --git a/Pod/Classes/Provider/A0IdentityProviderAuthenticator.h b/Pod/Classes/Provider/A0IdentityProviderAuthenticator.h index 1082b413d..3c83d30cd 100644 --- a/Pod/Classes/Provider/A0IdentityProviderAuthenticator.h +++ b/Pod/Classes/Provider/A0IdentityProviderAuthenticator.h @@ -79,6 +79,21 @@ success:(void(^)(A0UserProfile *profile, A0Token *token))success failure:(void(^)(NSError *error))failure; +/** + * Authenticates a user using an identity provider specified by `A0Strategy`'s name and the registered method (Safari or Native). + * For the connection name it will use the first one by default. + * You can override the default connection name setting in parameters the key `connection` with the name of the connection that should be used instead. + * + * @param strategy object that represent an authentication strategy with an identity provider. + * @param parameters authentication parameters for Auth0 API. + * @param success block called on successful authentication with user's token info and profile + * @param failure block called on error with the reason as a parameter + */ +- (void)authenticateForStrategyName:(NSString *)strategyName + parameters:(A0AuthParameters *)parameters + success:(void(^)(A0UserProfile *profile, A0Token *token))success + failure:(void(^)(NSError *error))failure; + /** * Checks if the given startegy has a registered authenticator (either Native or Safari). * diff --git a/Pod/Classes/Provider/A0IdentityProviderAuthenticator.m b/Pod/Classes/Provider/A0IdentityProviderAuthenticator.m index 2dff9a158..f6f997ea9 100644 --- a/Pod/Classes/Provider/A0IdentityProviderAuthenticator.m +++ b/Pod/Classes/Provider/A0IdentityProviderAuthenticator.m @@ -85,21 +85,28 @@ - (BOOL)canAuthenticateStrategy:(A0Strategy *)strategy { return authenticator != nil; } -- (void)authenticateForStrategy:(A0Strategy *)strategy - parameters:(A0AuthParameters *)parameters - success:(void(^)(A0UserProfile *profile, A0Token *token))success - failure:(void(^)(NSError *error))failure { - id authenticator = self.authenticators[strategy.name]; +- (void)authenticateForStrategyName:(NSString *)strategyName + parameters:(A0AuthParameters *)parameters + success:(void (^)(A0UserProfile *, A0Token *))success + failure:(void (^)(NSError *))failure { + id authenticator = self.authenticators[strategyName]; if (authenticator) { [authenticator authenticateWithParameters:parameters success:success failure:failure]; } else { - A0LogWarn(@"No known provider for strategy %@", strategy.name); + A0LogWarn(@"No known provider for strategy %@", strategyName); if (failure) { - failure([A0Errors unkownProviderForStrategy:strategy.name]); + failure([A0Errors unkownProviderForStrategy:strategyName]); } } } +- (void)authenticateForStrategy:(A0Strategy *)strategy + parameters:(A0AuthParameters *)parameters + success:(void(^)(A0UserProfile *profile, A0Token *token))success + failure:(void(^)(NSError *error))failure { + [self authenticateForStrategyName:strategy.name parameters:parameters success:success failure:failure]; +} + - (BOOL)handleURL:(NSURL *)url sourceApplication:(NSString *)application { __block BOOL handled = NO; [self.authenticators enumerateKeysAndObjectsUsingBlock:^(NSString *key, id authenticator, BOOL *stop) {