Skip to content
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
42 changes: 19 additions & 23 deletions ios/Firestack/FirestackAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,10 @@ @implementation FirestackAuth
}

RCT_EXPORT_METHOD(signInWithProvider:
(NSString *)provider
token:(NSString *)authToken
secret:(NSString *)authTokenSecret
(NSDictionary *)credentialData
callback:(RCTResponseSenderBlock)callback)
{
FIRAuthCredential *credential = [self getCredentialForProvider:provider
token:authToken
secret:authTokenSecret];
FIRAuthCredential *credential = [self getCredentialForProvider:credentialData];
if (credential == nil) {
NSDictionary *err = @{
@"error": @"Unhandled provider"
Expand Down Expand Up @@ -340,14 +336,10 @@ @implementation FirestackAuth
}

RCT_EXPORT_METHOD(reauthenticateWithCredentialForProvider:
(NSString *)provider
token:(NSString *)authToken
secret:(NSString *)authTokenSecret
(NSDictionary *)credentialData
callback:(RCTResponseSenderBlock)callback)
{
FIRAuthCredential *credential = [self getCredentialForProvider:provider
token:authToken
secret:authTokenSecret];
FIRAuthCredential *credential = [self getCredentialForProvider:credentialData];
if (credential == nil) {
NSDictionary *err = @{
@"error": @"Unhandled provider"
Expand Down Expand Up @@ -440,19 +432,23 @@ - (void) userPropsFromFIRUserWithToken:(FIRUser *) user
}];
}

- (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider
token:(NSString *)authToken
secret:(NSString *)authTokenSecret
- (FIRAuthCredential *)getCredentialForProvider:(NSDictionary *)credentialData
{
FIRAuthCredential *credential;
if ([provider compare:@"twitter" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
credential = [FIRTwitterAuthProvider credentialWithToken:authToken
secret:authTokenSecret];
} else if ([provider compare:@"facebook" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
credential = [FIRFacebookAuthProvider credentialWithAccessToken:authToken];
} else if ([provider compare:@"google" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
credential = [FIRGoogleAuthProvider credentialWithIDToken:authToken
accessToken:authTokenSecret];
NSString *provider = [credentialData valueForKey:@"provider"];
if ([provider compare:@"twitter.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
NSString *accessToken = [credentialData valueForKey:@"accessToken"];
NSString *secret = [credentialData valueForKey:@"secret"];
credential = [FIRTwitterAuthProvider credentialWithToken:accessToken
secret:secret];
} else if ([provider compare:@"facebook.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
NSString *accessToken = [credentialData valueForKey:@"accessToken"];
credential = [FIRFacebookAuthProvider credentialWithAccessToken:accessToken];
} else if ([provider compare:@"google.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
NSString *idToken = [credentialData valueForKey:@"idToken"];
NSString *accessToken = [credentialData valueForKey:@"accessToken"];
credential = [FIRGoogleAuthProvider credentialWithIDToken:idToken
accessToken:accessToken];
} else {
NSLog(@"Provider not yet handled: %@", provider);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/modules/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ export default class Auth extends Base {
* Sign the user in with a third-party authentication provider
* @return {Promise} A promise resolved upon completion
*/
signInWithCredential(credential: CredentialType): Promise<Object> {
return promisify('signInWithProvider', FirestackAuth)(credential.provider, credential.token, credential.secret);
signInWithCredential(credential: any): Promise<Object> {
return promisify('signInWithProvider', FirestackAuth)(credential);
}

/**
* Re-authenticate a user with a third-party authentication provider
* @return {Promise} A promise resolved upon completion
*/
reauthenticateUser(credential: CredentialType): Promise<Object> {
return promisify('reauthenticateWithCredentialForProvider', FirestackAuth)(credential.provider, credential.token, credential.secret);
reauthenticateUser(credential: any): Promise<Object> {
return promisify('reauthenticateWithCredentialForProvider', FirestackAuth)(credential);
}

/**
Expand Down