From b1bc038128cace9b9d5c37dd8ec660c77eafc34c Mon Sep 17 00:00:00 2001 From: Salakar Date: Sat, 7 Dec 2019 22:33:43 +0000 Subject: [PATCH] feat(auth): add initial support for Apple auth provider --- packages/auth/ios/RNFBAuth/RNFBAuthModule.m | 2 ++ packages/auth/lib/index.d.ts | 10 ++++++ packages/auth/lib/index.js | 2 ++ .../auth/lib/providers/AppleAuthProvider.js | 36 +++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 packages/auth/lib/providers/AppleAuthProvider.js diff --git a/packages/auth/ios/RNFBAuth/RNFBAuthModule.m b/packages/auth/ios/RNFBAuth/RNFBAuthModule.m index 39dd280cab..2be522a563 100644 --- a/packages/auth/ios/RNFBAuth/RNFBAuthModule.m +++ b/packages/auth/ios/RNFBAuth/RNFBAuthModule.m @@ -878,6 +878,8 @@ - (FIRAuthCredential *)getCredentialForProvider:(NSString *)provider token:(NSSt credential = [FIRFacebookAuthProvider credentialWithAccessToken:authToken]; } else if ([provider compare:@"google.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) { credential = [FIRGoogleAuthProvider credentialWithIDToken:authToken accessToken:authTokenSecret]; + } else if ([provider compare:@"apple.com" options:NSCaseInsensitiveSearch] == NSOrderedSame) { + credential = [FIROAuthProvider credentialWithProviderID:provider IDToken:authToken rawNonce:authTokenSecret]; } else if ([provider compare:@"password" options:NSCaseInsensitiveSearch] == NSOrderedSame) { credential = [FIREmailAuthProvider credentialWithEmail:authToken password:authTokenSecret]; } else if ([provider compare:@"emailLink" options:NSCaseInsensitiveSearch] == NSOrderedSame) { diff --git a/packages/auth/lib/index.d.ts b/packages/auth/lib/index.d.ts index 24d4662c5f..3ce85e32ce 100644 --- a/packages/auth/lib/index.d.ts +++ b/packages/auth/lib/index.d.ts @@ -213,6 +213,16 @@ export namespace FirebaseAuthTypes { * ``` */ GoogleAuthProvider: AuthProvider; + /** + * Apple auth provider implementation. + * + * #### Example + * + * ```js + * firebase.auth.AppleAuthProvider; + * ``` + */ + AppleAuthProvider: AuthProvider; /** * Github auth provider implementation. * diff --git a/packages/auth/lib/index.js b/packages/auth/lib/index.js index 84692232b0..6ea486b5d0 100644 --- a/packages/auth/lib/index.js +++ b/packages/auth/lib/index.js @@ -30,11 +30,13 @@ import GoogleAuthProvider from './providers/GoogleAuthProvider'; import OAuthProvider from './providers/OAuthProvider'; import PhoneAuthProvider from './providers/PhoneAuthProvider'; import TwitterAuthProvider from './providers/TwitterAuthProvider'; +import AppleAuthProvider from './providers/AppleAuthProvider'; import Settings from './Settings'; import User from './User'; import version from './version'; const statics = { + AppleAuthProvider, EmailAuthProvider, PhoneAuthProvider, GoogleAuthProvider, diff --git a/packages/auth/lib/providers/AppleAuthProvider.js b/packages/auth/lib/providers/AppleAuthProvider.js new file mode 100644 index 0000000000..172cc1d12e --- /dev/null +++ b/packages/auth/lib/providers/AppleAuthProvider.js @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +const providerId = 'apple.com'; + +export default class AppleAuthProvider { + constructor() { + throw new Error('`new AppleAuthProvider()` is not supported on the native Firebase SDKs.'); + } + + static get PROVIDER_ID() { + return providerId; + } + + static credential(token, secret) { + return { + token, + secret, + providerId, + }; + } +}