⚡️ Capacitor plugin for Firebase Authentication.

Overview

⚠️ Deprecated repository

This project has been moved to the following monorepo: robingenz/capacitor-firebase.



Firebase Authentication

@robingenz/capacitor-firebase-authentication

Capacitor plugin for Firebase Authentication.


Maintainers

Maintainer GitHub Social
Robin Genz robingenz @robin_genz

Installation

npm install @robingenz/capacitor-firebase-authentication firebase
npx cap sync

Add Firebase to your project if you haven't already (Android / iOS / Web).

On iOS, verify that this function is included in your app's AppDelegate.swift:

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
  return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
}

The further installation steps depend on the selected authentication method:

Attention: Please note that this plugin uses third-party SDKs to offer native sign-in. These SDKs can initialize on their own and collect various data. Here you can find more information.

Configuration

These configuration values are available:

Prop Type Description Default
skipNativeAuth boolean Configure whether the plugin should skip the native authentication. Only needed if you want to use the Firebase JavaScript SDK. Only available for Android and iOS. false
providers string[] Configure which providers you want to use so that only the providers you need are fully initialized. If you do not configure any providers, they will be all initialized. Please note that this does not prevent the automatic initialization of third-party SDKs. Only available for Android and iOS. ["apple.com", "facebook.com", "github.com", "google.com", "microsoft.com", "playgames.google.com", "twitter.com", "yahoo.com", "phone"]

Examples

In capacitor.config.json:

{
  "plugins": {
    "FirebaseAuthentication": {
      "skipNativeAuth": false,
      "providers": ["apple.com", "google.com"]
    }
  }
}

In capacitor.config.ts:

/// <reference types="@capacitor/firebase-authentication" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  plugins: {
    FirebaseAuthentication: {
      skipNativeAuth: false,
      providers: ["apple.com", "google.com"],
    },
  },
};

export default config;

Demo

A working example can be found here: robingenz/capacitor-firebase-authentication-demo

Usage

import { FirebaseAuthentication } from '@robingenz/capacitor-firebase-authentication';

const getCurrentUser = async () => {
  const result = await FirebaseAuthentication.getCurrentUser();
  return result.user;
};

const getIdToken = async () => {
  const result = await FirebaseAuthentication.getIdToken();
  return result.token;
};

const setLanguageCode = async () => {
  await FirebaseAuthentication.setLanguageCode({ languageCode: 'en-US' });
};

const signInWithApple = async () => {
  await FirebaseAuthentication.signInWithApple();
};

const signInWithFacebook = async () => {
  await FirebaseAuthentication.signInWithFacebook();
};

const signInWithGithub = async () => {
  await FirebaseAuthentication.signInWithGithub();
};

const signInWithGoogle = async () => {
  await FirebaseAuthentication.signInWithGoogle();
};

const signInWithMicrosoft = async () => {
  await FirebaseAuthentication.signInWithMicrosoft();
};

const signInWithPlayGames = async () => {
  await FirebaseAuthentication.signInWithPlayGames();
};

const signInWithPhoneNumber = async () => {
  const { verificationId } = await FirebaseAuthentication.signInWithPhoneNumber(
    {
      phoneNumber: '123456789',
    },
  );
  const verificationCode = window.prompt(
    'Please enter the verification code that was sent to your mobile device.',
  );
  await FirebaseAuthentication.signInWithPhoneNumber({
    verificationId,
    verificationCode,
  });
};

const signInWithTwitter = async () => {
  await FirebaseAuthentication.signInWithTwitter();
};

const signInWithYahoo = async () => {
  await FirebaseAuthentication.signInWithYahoo();
};

const signOut = async () => {
  await FirebaseAuthentication.signOut();
};

const useAppLanguage = async () => {
  await FirebaseAuthentication.useAppLanguage();
};

API

getCurrentUser()

getCurrentUser() => Promise<GetCurrentUserResult>

Fetches the currently signed-in user.

Returns: Promise<GetCurrentUserResult>


getIdToken(...)

getIdToken(options?: GetIdTokenOptions | undefined) => Promise<GetIdTokenResult>

Fetches the Firebase Auth ID Token for the currently signed-in user.

Param Type
options GetIdTokenOptions

Returns: Promise<GetIdTokenResult>


setLanguageCode(...)

setLanguageCode(options: SetLanguageCodeOptions) => Promise<void>

Sets the user-facing language code for auth operations.

Param Type
options SetLanguageCodeOptions

signInWithApple(...)

signInWithApple(options?: SignInOptions | undefined) => Promise<SignInResult>

Starts the Apple sign-in flow.

Param Type
options SignInOptions

Returns: Promise<SignInResult>


signInWithFacebook(...)

signInWithFacebook(options?: SignInOptions | undefined) => Promise<SignInResult>

Starts the Facebook sign-in flow.

Param Type
options SignInOptions

Returns: Promise<SignInResult>


signInWithGithub(...)

signInWithGithub(options?: SignInOptions | undefined) => Promise<SignInResult>

Starts the GitHub sign-in flow.

Param Type
options SignInOptions

Returns: Promise<SignInResult>


signInWithGoogle(...)

signInWithGoogle(options?: SignInOptions | undefined) => Promise<SignInResult>

Starts the Google sign-in flow.

Param Type
options SignInOptions

Returns: Promise<SignInResult>


signInWithMicrosoft(...)

signInWithMicrosoft(options?: SignInOptions | undefined) => Promise<SignInResult>

Starts the Microsoft sign-in flow.

Param Type
options SignInOptions

Returns: Promise<SignInResult>


signInWithPlayGames(...)

signInWithPlayGames(options?: SignInOptions | undefined) => Promise<SignInResult>

Starts the Play Games sign-in flow.

Param Type
options SignInOptions

Returns: Promise<SignInResult>


signInWithTwitter(...)

signInWithTwitter(options?: SignInOptions | undefined) => Promise<SignInResult>

Starts the Twitter sign-in flow.

Param Type
options SignInOptions

Returns: Promise<SignInResult>


signInWithYahoo(...)

signInWithYahoo(options?: SignInOptions | undefined) => Promise<SignInResult>

Starts the Yahoo sign-in flow.

Param Type
options SignInOptions

Returns: Promise<SignInResult>


signInWithPhoneNumber(...)

signInWithPhoneNumber(options: SignInWithPhoneNumberOptions) => Promise<SignInWithPhoneNumberResult>

Starts the sign-in flow using a phone number.

Either the phone number or the verification code and verification ID must be provided.

Only available for Android and iOS.

Param Type
options SignInWithPhoneNumberOptions

Returns: Promise<SignInWithPhoneNumberResult>


signInWithCustomToken(...)

signInWithCustomToken(options: SignInWithCustomTokenOptions) => Promise<SignInResult>

Starts the Custom Token sign-in flow.

This method cannot be used in combination with skipNativeAuth on Android and iOS. In this case you have to use the signInWithCustomToken interface of the Firebase JS SDK directly.

Param Type
options SignInWithCustomTokenOptions

Returns: Promise<SignInResult>


signOut()

signOut() => Promise<void>

Starts the sign-out flow.


useAppLanguage()

useAppLanguage() => Promise<void>

Sets the user-facing language code to be the default app language.


addListener('authStateChange', ...)

addListener(eventName: 'authStateChange', listenerFunc: AuthStateChangeListener) => Promise<PluginListenerHandle> & PluginListenerHandle

Listen for the user's sign-in state changes.

Param Type
eventName 'authStateChange'
listenerFunc AuthStateChangeListener

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.


Interfaces

GetCurrentUserResult

Prop Type Description
user User | null The currently signed-in user, or null if there isn't any.

User

Prop Type
displayName string | null
email string | null
emailVerified boolean
isAnonymous boolean
phoneNumber string | null
photoUrl string | null
providerId string
tenantId string | null
uid string

GetIdTokenResult

Prop Type Description
token string The Firebase Auth ID token JWT string.

GetIdTokenOptions

Prop Type Description
forceRefresh boolean Force refresh regardless of token expiration.

SetLanguageCodeOptions

Prop Type Description
languageCode string BCP 47 language code. Example: en-US.

SignInResult

Prop Type Description
user User | null The currently signed-in user, or null if there isn't any.
credential AuthCredential | null Credentials returned by an auth provider.

AuthCredential

Prop Type Description
providerId string The authentication provider ID for the credential. Example: google.com.
accessToken string The OAuth access token associated with the credential if it belongs to an OAuth provider.
idToken string The OAuth ID token associated with the credential if it belongs to an OIDC provider.
secret string The OAuth access token secret associated with the credential if it belongs to an OAuth 1.0 provider.
nonce string The random string used to make sure that the ID token you get was granted specifically in response to your app's authentication request.

SignInOptions

Prop Type Description
customParameters SignInCustomParameter[] Configures custom parameters to be passed to the identity provider during the OAuth sign-in flow.

SignInCustomParameter

Prop Type Description
key string The custom parameter key (e.g. login_hint).
value string The custom parameter value (e.g. [email protected]).

SignInWithPhoneNumberResult

Prop Type Description
verificationId string The verification ID, which is needed to identify the verification code.

SignInWithPhoneNumberOptions

Prop Type Description
phoneNumber string The phone number to be verified.
verificationId string The verification ID which will be returned when signInWithPhoneNumber is called for the first time. The verificationCode must also be provided.
verificationCode string The verification code from the SMS message. The verificationId must also be provided.

SignInWithCustomTokenOptions

Prop Type Description
token string The custom token to sign in with.

PluginListenerHandle

Prop Type
remove () => Promise<void>

AuthStateChange

Prop Type Description
user User | null The currently signed-in user, or null if there isn't any.

Type Aliases

AuthStateChangeListener

Callback to receive the user's sign-in state change notifications.

(change: AuthStateChange): void

FAQ

  1. What does this plugin do?
    This plugin enables the use of Firebase Authentication in a Capacitor app. It uses the Firebase SDK for Java (Android), Swift (iOS) and JavaScript.
  2. What is the difference between the web implementation of this plugin and the Firebase JS SDK?
    The web implementation of this plugin encapsulates the Firebase JS SDK and enables a consistent interface across all platforms. You can decide if you prefer to use the web implementation or the Firebase JS SDK.
  3. What is the difference between the native and web authentication?
    For web authentication, the Firebase JS SDK is used. This only works to a limited extent on Android and iOS in the WebViews (see here). For native authentication, the native SDKs from Firebase, Google, etc. are used. These offer all the functionalities that the Firebase JS SDK also offers on the web. However, after a login with the native SDK, the user is only logged in on the native layer of the app. If the user should also be logged in on the web layer, additional steps are required (see here).
  4. How can I use this plugin with the Firebase JavaScript SDK?
    See here.

Changelog

See CHANGELOG.md.

License

See LICENSE.

You might also like...

Authentication and authorization for application, api and user

多树AUTH / MT-AUTH 用户,应用,API管理中心 MT-AUTH是一款基于Spring Boot, OAuth2与事件驱动的角色的权限管理(RBAC)系统,通过集成Spring Cloud Gateway实现了API鉴权,缓存,跨域,CSRF防护,特殊字符过滤等常用功能 项目特点 基于事

Dec 14, 2022

Spring Boot REST API authentication best practices using JWT

 Spring Boot REST API authentication best practices using JWT

Spring Boot REST API authentication best practices using JWT Token based API authentication with Spring Security and JWT (JSON web Token) Overview Thi

Dec 22, 2022

Implementing JWT authentication with spring boot.

Jwt-SpringBoot Implementing JWT authentication with spring boot. Normally you would create an endpoint to create the credentials(token), then this tok

May 7, 2022

Squadio-App is a Users-Accounts financial system. exposes Rest APIs with JWT authentication/Authorization process .

squadio-app Description Squadio-App is a Users-Accounts financial system. exposes Rest APIs with JWT authentication/Authorization process . How to Run

Jan 29, 2022

Vaadin Flow example with JWT authentication

Example how to enable JWT based authentication with Vaadin Flow and Spring Security

Sep 12, 2022

Spring Boot JWT Authentication example with Spring Security & Spring Data JPA

Spring Boot JWT Authentication example with Spring Security & Spring Data JPA

Jan 26, 2022

Spring REST API for financial management, developed with Java 11, JWT for authentication, JUnit for unit testing and Oracle Database

Spring REST API for financial management, developed with Java 11, JWT for authentication, JUnit for unit testing and Oracle Database

control_financial Spring REST API for financial management, developed with Java 11, JWT for authentication, JUnit for unit testing and Oracle Database

May 27, 2022

ReactJS, Spring Boot JWT Authentication Example

ReactJS, Spring Boot JWT Authentication Example

springboot-reactjs-jwt-authentication ReactJS - SpringBoot - JWT - Flow Local setup Step 1: Download or clone the source code from GitHub to a local m

Dec 2, 2022

trying to create a plugin using the spigot api! this plugin will be responsible for delivering the products according to the settings!

KettraShop "simples plugin de ativação de produtos da loja, dentro do Minecraft" ⚙️ Configurações caso você não tenha uma loja virtual para seu servid

Nov 2, 2022
Releases(v0.4.3)
Owner
Robin Genz
🎓 CS Student and Full Stack Developer | 💙 @ionic-team Developer Expert | ⚡️ @capacitor-community Member
Robin Genz
Build your own Minecraft authentication system with Mojang authentication server support.

Build your own Minecraft authentication system with Mojang authentication server support. A fork of yushijinhun/authlib-injector.

Ethan Zuo 15 Dec 17, 2022
A quiz app with great layout design, dynamic questions using firebase and what not....

AndroidQuizApp An android quiz app created using Android Studio with our language JAVA that has great layout design, dynamic questions using firebase

Ejaz Mahmood 4 Dec 30, 2022
A simple online Quiz App made by using Firebase firestore database.

Quiz App Online Description Quiz App is an Online quiz maker app that can be used to create effective quizzes by teachers. This app uses Firebase Fire

Soham Naigaonkar 2 Dec 30, 2021
Share food-Android- - Food donation coded in native android with firebase, google maps api and php server xampp

share_food-Android- Instructions: 1. Create a firebase account and link it with the project via google-services.json. 2. This project also uses a XAMP

Abubakar 3 Dec 28, 2021
Simple Android app during a coding night. Just Learning Firebase and Android

KUI-App Simple Android app during a coding night. Just Learning Firebase and Android What we learned: Some basics of Android Basic setup of Firebase:

Kibabii University Informatics Club (KUI) 7 Aug 28, 2022
Firebase Gallery

Firebase Gallery Um simples aplicativo de galeria utilizando o FirebaseStorage O aplicativo foi desenvolvido para a apresentação de um projeto em grup

Neto Sepulveda 2 Mar 15, 2022
This project is a simple messaging application made using React-Native framework, Gifted-Chat library and Firebase database

This project is a simple messaging application made using React-Native framework, Gifted-Chat library and Firebase database. The example that will be shown here focuses on the ability of two people to message each other in a chat room.

null 3 Jan 30, 2022
An application created using Android Studio, Java and Firebase DB to serve patients and doctors at a medical clinic.

MEDICAL CLINIC APP An application created using Android Studio, Java and Firebase DB to serve patients and doctors at a medical clinic. Patients are a

Anik Sarker 16 Jan 5, 2023
A Spring Security based Authentication microservice with MySQL

Spring Security Microservice using JWT and MySQL Background This is an open source, production-ready application that provides role-based user authent

Safeer Ansari 4 Sep 28, 2021
Mc-msa-token-getter - Scripts to retrieve MC authentication tokens for use in modding dev envs.

Minecraft MSA Token Getter Python and Java scripts to retrieve MC authentication tokens for use in modding dev envs. Requires a properly configured Az

Ryan 1 Jan 3, 2022