Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

add authenticate method #11

Merged
merged 1 commit into from Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion auth0-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class Auth0Lock {
}
LockModule.show(options, callback);
}

authenticate(connectionName, options, callback) {
LockModule.init(this.lockOptions);
if (this.nativeIntegrations) {
LockModule.nativeIntegrations(this.nativeIntegrations);
}
LockModule.authenticate(connectionName, options, callback);
}
}

module.exports = Auth0Lock;
module.exports = Auth0Lock;
8 changes: 7 additions & 1 deletion objc/A0LockReactModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,10 @@ @implementation A0LockReactModule
});
}

@end
RCT_EXPORT_METHOD(authenticate:(NSString *)connectionName options:(NSDictionary *)options callback:(RCTResponseSenderBlock)callback) {
dispatch_async(dispatch_get_main_queue(), ^{
[[A0LockReact sharedInstance] authenticateWithConnectionName:connectionName options:options callback:callback];
});
}

@end
2 changes: 2 additions & 0 deletions objc/core/A0LockReact.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ typedef void(^A0LockCallback)(NSArray *parameters);

- (void)showWithOptions:(NSDictionary *)options callback:(A0LockCallback)callback;

- (void)authenticateWithConnectionName:(NSString *)connectionName options:(NSDictionary *)options callback:(A0LockCallback)callback;

- (void)configureLockFromBundle;

- (void)configureLockWithClientId:(NSString *)clientId domain:(NSString *)domain;
Expand Down
19 changes: 19 additions & 0 deletions objc/core/A0LockReact.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ - (void)showWithOptions:(NSDictionary *)options callback:(A0LockCallback)callbac
}
}

- (void)authenticateWithConnectionName:(NSString *)connectionName options:(NSDictionary *)options callback:(A0LockCallback)callback {
A0IdentityProviderAuthenticator *authenticator = [self.lock identityProviderAuthenticator];
void(^success)(A0UserProfile *, A0Token *) = ^(A0UserProfile *profile, A0Token *token) {
if (profile && token) {
NSDictionary *profileDict = [profile asDictionary];
NSDictionary *tokenDict = [token asDictionary];
callback(@[[NSNull null], profileDict, tokenDict]);
} else {
callback(@[@"Unexpected null value in profile or token"]);
}
};
void(^failure)(NSError *) = ^(NSError *error) {
callback(@[[error localizedDescription]]);
};

A0AuthParameters* parameters = [A0AuthParameters newWithDictionary:options];
[authenticator authenticateWithConnectionName:connectionName parameters:parameters success:success failure:failure];
}

- (A0AuthParameters *)authenticationParametersFromOptions:(NSDictionary *)options {
NSDictionary *jsonParameters = options[@"authParams"];
if (jsonParameters.count == 0) {
Expand Down