[auth] Add OAuthProvider

This commit is contained in:
Chris Bianca 2018-01-24 15:21:52 +00:00
parent c3e5eb634e
commit 5f3a9755d7
3 changed files with 30 additions and 0 deletions

View File

@ -38,6 +38,7 @@ import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseAuthProvider;
import com.google.firebase.auth.FirebaseUserMetadata;
import com.google.firebase.auth.GithubAuthProvider;
import com.google.firebase.auth.OAuthProvider;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
import com.google.firebase.auth.ProviderQueryResult;
@ -1104,6 +1105,8 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
return TwitterAuthProvider.getCredential(authToken, authSecret);
case "github.com":
return GithubAuthProvider.getCredential(authToken);
case "oauth":
return OAuthProvider.getCredential(provider, authToken, authSecret);
case "phone":
// If the phone number is auto-verified quickly, then the verificationId can be null
// We cached the credential as part of the verifyPhoneNumber request to be re-used here

View File

@ -1029,6 +1029,8 @@ RCT_EXPORT_METHOD(fetchProvidersForEmail:
credential = [FIRGitHubAuthProvider credentialWithToken:authToken];
} else if ([provider compare:@"phone" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
credential = [[FIRPhoneAuthProvider provider] credentialWithVerificationID:authToken verificationCode:authTokenSecret];
} else if ([provider compare:@"oauth" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
credential = [FIROAuthProvider credentialWithProviderID:@"oauth" IDToken:authToken accessToken:authTokenSecret];
} else {
NSLog(@"Provider not yet handled: %@", provider);
}

View File

@ -0,0 +1,25 @@
/**
* @flow
* OAuthProvider representation wrapper
*/
import type { AuthCredential } from '../types';
const providerId = 'oauth';
export default class OAuthProvider {
constructor() {
throw new Error('`new OAuthProvider()` is not supported on the native Firebase SDKs.');
}
static get PROVIDER_ID(): string {
return providerId;
}
static credential(idToken: string, accessToken: string): AuthCredential {
return {
token: idToken,
secret: accessToken,
providerId,
};
}
}