From 43bfeb487a1759c65e34bb2fa10c778d32a221d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Jos=C3=A9=20L=C3=B3pez?= <antoniojlopez@gmail.com> Date: Fri, 2 Nov 2018 13:18:41 -0300 Subject: [PATCH] feat(firebase-authentication): add plugin (#2797) * feat(firebase-authentication): add plugin * Update index.ts * Update index.ts --- .../plugins/firebase-authentication/index.ts | 189 ++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 src/@ionic-native/plugins/firebase-authentication/index.ts diff --git a/src/@ionic-native/plugins/firebase-authentication/index.ts b/src/@ionic-native/plugins/firebase-authentication/index.ts new file mode 100644 index 000000000..b33e83bd1 --- /dev/null +++ b/src/@ionic-native/plugins/firebase-authentication/index.ts @@ -0,0 +1,189 @@ +import { Injectable } from '@angular/core'; +import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; +import { Observable } from 'rxjs/Observable'; + +/** + * @name Firebase Authentication + * @description + * Cordova plugin for Firebase Authentication + * + * @usage + * ```typescript + * import { FirebaseAuthentication } from '@ionic-native/firebase-authentication'; + * + * + * constructor(private firebaseAuthentication: FirebaseAuthentication) { } + * + * ... + * + * + * this.firebaseAuthentication.createUserWithEmailAndPassword('test@gmail.com', '123') + * .then((res: any) => console.log(res)) + * .catch((error: any) => console.error(error)); + * + * ``` + */ +@Plugin({ + pluginName: 'FirebaseAuthentication', + plugin: 'cordova-plugin-firebase-authentication', + pluginRef: 'cordova.plugins.firebase.auth', + repo: 'https://github.com/chemerisuk/cordova-plugin-firebase-authentication', + install: 'ionic cordova plugin add cordova-plugin-firebase-authentication --variable FIREBASE_AUTH_VERSION=version', + installVariables: ['FIREBASE_AUTH_VERSION'], + platforms: ['Android', 'iOS'] +}) +@Injectable() +export class FirebaseAuthentication extends IonicNativePlugin { + /** + * Returns a JWT token used to identify the user to a Firebase service. + * @param forceRefresh {boolean} Force Refresh + * @return {Promise<any>} Returns the id token + */ + @Cordova({ sync: true }) + getIdToken(forceRefresh: boolean): Promise<any> { + return; + } + + /** + * Tries to create a new user account with the given email address and password. + * @param email Email + * @param password Password + */ + @Cordova({ sync: true }) + createUserWithEmailAndPassword( + email: string, + password: string + ): Promise<any> { + return; + } + + /** + * Initiates email verification for the current user. + */ + @Cordova({ sync: true }) + sendEmailVerification(): Promise<any> { + return; + } + + /** + * Triggers the Firebase Authentication backend to send a password-reset email to the given email address, + * which must correspond to an existing user of your app. + * @param email Email + */ + @Cordova({ sync: true }) + sendPasswordResetEmail(email: string): Promise<any> { + return; + } + + /** + * Asynchronously signs in using an email and password. + * @param email Email + * @param password Password + */ + @Cordova({ sync: true }) + signInWithEmailAndPassword(email: string, password: string): Promise<any> { + return; + } + + /** + * Starts the phone number verification process for the given phone number. + * NOTE: Android supports auto-verify and instant device verification. + * Therefore in that cases it doesn't make sense to ask for sms code. + * It's recommended to register onAuthStateChanged callback to be notified on auto sign-in. + * timeout [milliseconds] is the maximum amount of time you are willing to wait for SMS auto-retrieval + * to be completed by the library. Maximum allowed value is 2 minutes. Use 0 to disable SMS-auto-retrieval. + * If you specify a positive value less than 30 seconds, library will default to 30 seconds. + * @param phoneNumber Phone number + * @param timeout {number} Timeout + */ + @Cordova({ sync: true }) + verifyPhoneNumber(phoneNumber: string, timeout: number): Promise<any> { + return; + } + + /** + * Asynchronously signs in using verificationId and 6-digit SMS code. + * @param verificationId Verification ID + * @param smsCode SMS code + */ + @Cordova({ sync: true }) + signInWithVerificationId( + verificationId: string, + smsCode: number + ): Promise<any> { + return; + } + + /** + * Create and use temporary anonymous account to authenticate with Firebase. + */ + @Cordova({ sync: true }) + signInAnonymously(): Promise<any> { + return; + } + + /** + * Uses Google's idToken and accessToken to sign-in into firebase account. In order to retrieve those tokens follow instructions for Android and iOS + * @param idToken ID Token + * @param accessToken Access Token + */ + @Cordova({ sync: true }) + signInWithGoogle(idToken: string, accessToken: string): Promise<any> { + return; + } + + /** + * Uses Facebook's accessToken to sign-in into firebase account. In order to retrieve those tokens follow instructions for Android and iOS. + * @param accessToken Access Token + */ + @Cordova({ sync: true }) + signInWithFacebook(accessToken: string): Promise<any> { + return; + } + + /** + * Uses Twitter's token and secret to sign-in into firebase account. In order to retrieve those tokens follow instructions for Android and iOS. + * @param token Token + * @param secret Secret + */ + @Cordova({ sync: true }) + signInWithTwitter(token: string, secret: string): Promise<any> { + return; + } + + /** + * Registers a block as an auth state did change listener. To be invoked when: + * - The block is registered as a listener, + * - A user with a different UID from the current user has signed in, or + * - The current user has signed out. + */ + @Cordova({ observable: true, callbackOrder: 'reverse' }) + onAuthStateChanged(): Observable<any> { + return; + } + + /** + * Set's the current user language code. The string used to set this property must be a language code that follows BCP 47. + * @param languageCode Language Code + */ + @Cordova({ sync: true }) + setLanguageCode(languageCode: string): Promise<any> { + return; + } + + /** + * Sets languageCode to the app’s current language. + */ + @Cordova({ sync: true }) + useAppLanguage(): Promise<any> { + return; + } + + /** + * Signs out the current user and clears it from the disk cache. + */ + @Cordova({ sync: true }) + signOut(): Promise<any> { + return; + } +}