firebase
is a global namespace from which all Firebase
* services are accessed.
*/
declare namespace firebase {
/**
* @hidden
*/
type NextFnerror.email
, error.phoneNumber
, and
* error.credential
({@link firebase.auth.AuthCredential})
* may be provided, depending on the type of credential. You can recover
* from this error by signing in with error.credential
directly
* via {@link firebase.auth.Auth.signInWithCredential}.error.email
and error.credential
* ({@link firebase.auth.AuthCredential}) fields are also provided.
* You have to link the credential to the existing user with that email if
* you wish to continue signing in with that credential. To do so, call
* {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
* error.email
via one of the providers returned and then
* {@link firebase.User.linkWithCredential} the original credential to that
* newly signed in user.error.email
, error.phoneNumber
, and
* error.credential
({@link firebase.auth.AuthCredential})
* may be provided, depending on the type of credential. You can recover
* from this error by signing in with error.credential
directly
* via {@link firebase.auth.Auth.signInWithCredential}.error.email
and error.credential
* ({@link firebase.auth.AuthCredential}) fields are also provided.
* You have to link the credential to the existing user with that email if
* you wish to continue signing in with that credential. To do so, call
* {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
* error.email
via one of the providers returned and then
* {@link firebase.User.linkWithCredential} the original credential to that
* newly signed in user.error.phoneNumber
and
* error.credential
({@link firebase.auth.AuthCredential})
* are provided in this case. You can recover from this error by signing in
* with that credential directly via
* {@link firebase.auth.Auth.signInWithCredential}.error.email
and error.credential
* ({@link firebase.auth.AuthCredential}) fields are also provided. You can
* recover from this error by signing in with that credential directly via
* {@link firebase.auth.Auth.signInWithCredential}.error.email
and error.credential
* ({@link firebase.auth.AuthCredential}) fields are also provided.
* You have to link the credential to the existing user with that email if
* you wish to continue signing in with that credential. To do so, call
* {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
* error.email
via one of the providers returned and then
* {@link firebase.User.linkWithCredential} the original credential to that
* newly signed in user.remoteConfig.getValue(key).asBoolean()
.
*/
getBoolean(key: string): boolean;
/**
* Gets the value for the given key as a number.
*
* Convenience method for calling remoteConfig.getValue(key).asNumber()
.
*/
getNumber(key: string): number;
/**
* Gets the value for the given key as a String.
*
* Convenience method for calling remoteConfig.getValue(key).asString()
.
*/
getString(key: string): string;
/**
* Gets the {@link Value} for the given key.
*/
getValue(key: string): Value;
/**
* Defines the log level to use.
*/
setLogLevel(logLevel: LogLevel): void;
}
/**
* Indicates the source of a value.
*
* Number(value) || 0
.
*/
asNumber(): number;
/**
* Gets the value as a string.
*/
asString(): string;
/**
* Gets the {@link ValueSource} for the given key.
*/
getSource(): ValueSource;
}
/**
* Defines configuration options for the Remote Config SDK.
*/
export interface Settings {
/**
* Defines the maximum age in milliseconds of an entry in the config cache before
* it is considered stale. Defaults to 43200000 (Twelve hours).
*/
minimumFetchIntervalMillis: number;
/**
* Defines the maximum amount of milliseconds to wait for a response when fetching
* configuration from the Remote Config server. Defaults to 60000 (One minute).
*/
fetchTimeoutMillis: number;
}
/**
* Summarizes the outcome of the last attempt to fetch config from the Firebase Remote Config server.
*
* url: Sets the link continue/state URL, which has different meanings * in different contexts:
*error.email
and error.credential
* ({@link firebase.auth.AuthCredential}) fields are also provided. You can
* recover from this error by signing in with that credential directly via
* {@link firebase.auth.Auth.signInWithCredential}.error.email
and error.credential
* ({@link firebase.auth.AuthCredential}) fields are also provided.
* You have to link the credential to the existing user with that email if
* you wish to continue signing in with that credential. To do so, call
* {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
* error.email
via one of the providers returned and then
* {@link firebase.User.linkWithCredential} the original credential to that
* newly signed in user.error.email
, error.phoneNumber
, and
* error.credential
({@link firebase.auth.AuthCredential})
* may be provided, depending on the type of credential. You can recover
* from this error by signing in with error.credential
directly
* via {@link firebase.auth.Auth.signInWithCredential}.error.email
and error.credential
* ({@link firebase.auth.AuthCredential}) fields are also provided.
* You have to link the credential to the existing user with that email if
* you wish to continue signing in with that credential. To do so, call
* {@link firebase.auth.Auth.fetchSignInMethodsForEmail}, sign in to
* error.email
via one of the providers returned and then
* {@link firebase.User.linkWithCredential} the original credential to that
* newly signed in user.auth/multi-factor-auth-required
.
* This error provides a {@link firebase.auth.MultiFactorResolver} object,
* which you can use to get the second sign-in factor from the user.
*
* @example
* ```javascript
* firebase.auth().signInWithEmailAndPassword()
* .then(function(result) {
* // User signed in. No 2nd factor challenge is needed.
* })
* .catch(function(error) {
* if (error.code == 'auth/multi-factor-auth-required') {
* var resolver = error.resolver;
* var multiFactorHints = resolver.hints;
* } else {
* // Handle other errors.
* }
* });
*
* resolver.resolveSignIn(multiFactorAssertion)
* .then(function(userCredential) {
* // User signed in.
* });
* ```
*/
interface MultiFactorError extends firebase.auth.AuthError {
/**
* The multi-factor resolver to complete second factor sign-in.
*/
resolver: firebase.auth.MultiFactorResolver;
}
/**
* Facebook auth provider.
*
* @example
* ```javascript
* // Sign in using a redirect.
* firebase.auth().getRedirectResult().then(function(result) {
* if (result.credential) {
* // This gives you a Google Access Token.
* var token = result.credential.accessToken;
* }
* var user = result.user;
* })
* // Start a sign in process for an unauthenticated user.
* var provider = new firebase.auth.FacebookAuthProvider();
* provider.addScope('user_birthday');
* firebase.auth().signInWithRedirect(provider);
* ```
*
* @example
* ```javascript
* // Sign in using a popup.
* var provider = new firebase.auth.FacebookAuthProvider();
* provider.addScope('user_birthday');
* firebase.auth().signInWithPopup(provider).then(function(result) {
* // This gives you a Facebook Access Token.
* var token = result.credential.accessToken;
* // The signed-in user info.
* var user = result.user;
* });
* ```
*
* @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
* changes.
*/
class FacebookAuthProvider extends FacebookAuthProvider_Instance {
static PROVIDER_ID: string;
/**
* This corresponds to the sign-in method identifier as returned in
* {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
*/
static FACEBOOK_SIGN_IN_METHOD: string;
/**
* @example
* ```javascript
* var cred = firebase.auth.FacebookAuthProvider.credential(
* // `event` from the Facebook auth.authResponseChange callback.
* event.authResponse.accessToken
* );
* ```
*
* @param token Facebook access token.
*/
static credential(token: string): firebase.auth.OAuthCredential;
}
/**
* @hidden
*/
class FacebookAuthProvider_Instance implements firebase.auth.AuthProvider {
/**
* @param scope Facebook OAuth scope.
* @return The provider instance itself.
*/
addScope(scope: string): firebase.auth.AuthProvider;
providerId: string;
/**
* Sets the OAuth custom parameters to pass in a Facebook OAuth request for
* popup and redirect sign-in operations.
* Valid parameters include 'auth_type', 'display' and 'locale'.
* For a detailed list, check the
* {@link https://goo.gl/pve4fo Facebook}
* documentation.
* Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
* 'scope', 'response_type' and 'state' are not allowed and will be ignored.
* @param customOAuthParameters The custom OAuth parameters to pass
* in the OAuth request.
* @return The provider instance itself.
*/
setCustomParameters(
customOAuthParameters: Object
): firebase.auth.AuthProvider;
}
/**
* GitHub auth provider.
*
* GitHub requires an OAuth 2.0 redirect, so you can either handle the redirect
* directly, or use the signInWithPopup handler:
*
* @example
* ```javascript
* // Using a redirect.
* firebase.auth().getRedirectResult().then(function(result) {
* if (result.credential) {
* // This gives you a GitHub Access Token.
* var token = result.credential.accessToken;
* }
* var user = result.user;
* }).catch(function(error) {
* // Handle Errors here.
* var errorCode = error.code;
* var errorMessage = error.message;
* // The email of the user's account used.
* var email = error.email;
* // The firebase.auth.AuthCredential type that was used.
* var credential = error.credential;
* if (errorCode === 'auth/account-exists-with-different-credential') {
* alert('You have signed up with a different provider for that email.');
* // Handle linking here if your app allows it.
* } else {
* console.error(error);
* }
* });
*
* // Start a sign in process for an unauthenticated user.
* var provider = new firebase.auth.GithubAuthProvider();
* provider.addScope('repo');
* firebase.auth().signInWithRedirect(provider);
* ```
*
* @example
* ```javascript
* // With popup.
* var provider = new firebase.auth.GithubAuthProvider();
* provider.addScope('repo');
* firebase.auth().signInWithPopup(provider).then(function(result) {
* // This gives you a GitHub Access Token.
* var token = result.credential.accessToken;
* // The signed-in user info.
* var user = result.user;
* }).catch(function(error) {
* // Handle Errors here.
* var errorCode = error.code;
* var errorMessage = error.message;
* // The email of the user's account used.
* var email = error.email;
* // The firebase.auth.AuthCredential type that was used.
* var credential = error.credential;
* if (errorCode === 'auth/account-exists-with-different-credential') {
* alert('You have signed up with a different provider for that email.');
* // Handle linking here if your app allows it.
* } else {
* console.error(error);
* }
* });
* ```
*
* @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
* changes.
*/
class GithubAuthProvider extends GithubAuthProvider_Instance {
static PROVIDER_ID: string;
/**
* This corresponds to the sign-in method identifier as returned in
* {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
*/
static GITHUB_SIGN_IN_METHOD: string;
/**
* @example
* ```javascript
* var cred = firebase.auth.FacebookAuthProvider.credential(
* // `event` from the Facebook auth.authResponseChange callback.
* event.authResponse.accessToken
* );
* ```
*
* @param token Github access token.
* @return {!firebase.auth.OAuthCredential} The auth provider credential.
*/
static credential(token: string): firebase.auth.OAuthCredential;
}
/**
* @hidden
*/
class GithubAuthProvider_Instance implements firebase.auth.AuthProvider {
/**
* @param scope Github OAuth scope.
* @return The provider instance itself.
*/
addScope(scope: string): firebase.auth.AuthProvider;
providerId: string;
/**
* Sets the OAuth custom parameters to pass in a GitHub OAuth request for popup
* and redirect sign-in operations.
* Valid parameters include 'allow_signup'.
* For a detailed list, check the
* {@link https://developer.github.com/v3/oauth/ GitHub} documentation.
* Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
* 'scope', 'response_type' and 'state' are not allowed and will be ignored.
* @param customOAuthParameters The custom OAuth parameters to pass
* in the OAuth request.
* @return The provider instance itself.
*/
setCustomParameters(
customOAuthParameters: Object
): firebase.auth.AuthProvider;
}
/**
* Google auth provider.
*
* @example
* ```javascript
* // Using a redirect.
* firebase.auth().getRedirectResult().then(function(result) {
* if (result.credential) {
* // This gives you a Google Access Token.
* var token = result.credential.accessToken;
* }
* var user = result.user;
* });
*
* // Start a sign in process for an unauthenticated user.
* var provider = new firebase.auth.GoogleAuthProvider();
* provider.addScope('profile');
* provider.addScope('email');
* firebase.auth().signInWithRedirect(provider);
* ```
*
* @example
* ```javascript
* // Using a popup.
* var provider = new firebase.auth.GoogleAuthProvider();
* provider.addScope('profile');
* provider.addScope('email');
* firebase.auth().signInWithPopup(provider).then(function(result) {
* // This gives you a Google Access Token.
* var token = result.credential.accessToken;
* // The signed-in user info.
* var user = result.user;
* });
* ```
*
* @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
* changes.
*/
class GoogleAuthProvider extends GoogleAuthProvider_Instance {
static PROVIDER_ID: string;
/**
* This corresponds to the sign-in method identifier as returned in
* {@link firebase.auth.Auth.fetchSignInMethodsForEmail}.
*/
static GOOGLE_SIGN_IN_METHOD: string;
/**
* Creates a credential for Google. At least one of ID token and access token
* is required.
*
* @example
* ```javascript
* // \`googleUser\` from the onsuccess Google Sign In callback.
* var credential = firebase.auth.GoogleAuthProvider.credential(
googleUser.getAuthResponse().id_token);
* firebase.auth().signInWithCredential(credential)
* ```
* @param idToken Google ID token.
* @param accessToken Google access token.
* @return The auth provider credential.
*/
static credential(
idToken?: string | null,
accessToken?: string | null
): firebase.auth.OAuthCredential;
}
/**
* @hidden
*/
class GoogleAuthProvider_Instance implements firebase.auth.AuthProvider {
/**
* @param scope Google OAuth scope.
* @return The provider instance itself.
*/
addScope(scope: string): firebase.auth.AuthProvider;
providerId: string;
/**
* Sets the OAuth custom parameters to pass in a Google OAuth request for popup
* and redirect sign-in operations.
* Valid parameters include 'hd', 'hl', 'include_granted_scopes', 'login_hint'
* and 'prompt'.
* For a detailed list, check the
* {@link https://goo.gl/Xo01Jm Google}
* documentation.
* Reserved required OAuth 2.0 parameters such as 'client_id', 'redirect_uri',
* 'scope', 'response_type' and 'state' are not allowed and will be ignored.
* @param customOAuthParameters The custom OAuth parameters to pass
* in the OAuth request.
* @return The provider instance itself.
*/
setCustomParameters(
customOAuthParameters: Object
): firebase.auth.AuthProvider;
}
/**
* Generic OAuth provider.
*
* @example
* ```javascript
* // Using a redirect.
* firebase.auth().getRedirectResult().then(function(result) {
* if (result.credential) {
* // This gives you the OAuth Access Token for that provider.
* var token = result.credential.accessToken;
* }
* var user = result.user;
* });
*
* // Start a sign in process for an unauthenticated user.
* var provider = new firebase.auth.OAuthProvider('google.com');
* provider.addScope('profile');
* provider.addScope('email');
* firebase.auth().signInWithRedirect(provider);
* ```
* @example
* ```javascript
* // Using a popup.
* var provider = new firebase.auth.OAuthProvider('google.com');
* provider.addScope('profile');
* provider.addScope('email');
* firebase.auth().signInWithPopup(provider).then(function(result) {
* // This gives you the OAuth Access Token for that provider.
* var token = result.credential.accessToken;
* // The signed-in user info.
* var user = result.user;
* });
* ```
*
* @see {@link firebase.auth.Auth.onAuthStateChanged} to receive sign in state
* changes.
* @param providerId The associated provider ID, such as `github.com`.
*/
class OAuthProvider implements firebase.auth.AuthProvider {
constructor(providerId: string);
providerId: string;
/**
* @param scope Provider OAuth scope to add.
*/
addScope(scope: string): firebase.auth.AuthProvider;
/**
* Creates a Firebase credential from a generic OAuth provider's access token or
* ID token. The raw nonce is required when an ID token with a nonce field is
* provided. The SHA-256 hash of the raw nonce must match the nonce field in
* the ID token.
*
* @example
* ```javascript
* // `googleUser` from the onsuccess Google Sign In callback.
* // Initialize a generate OAuth provider with a `google.com` providerId.
* var provider = new firebase.auth.OAuthProvider('google.com');
* var credential = provider.credential({
* idToken: googleUser.getAuthResponse().id_token,
* });
* firebase.auth().signInWithCredential(credential)
* ```
*
* @param optionsOrIdToken Either the options object containing
* the ID token, access token and raw nonce or the ID token string.
* @param accessToken The OAuth access token.
*/
credential(
optionsOrIdToken: firebase.auth.OAuthCredentialOptions | string | null,
accessToken?: string
): firebase.auth.OAuthCredential;
/**
* Sets the OAuth custom parameters to pass in an OAuth request for popup
* and redirect sign-in operations.
* For a detailed list, check the
* reserved required OAuth 2.0 parameters such as `client_id`, `redirect_uri`,
* `scope`, `response_type` and `state` are not allowed and will be ignored.
* @param customOAuthParameters The custom OAuth parameters to pass
* in the OAuth request.
*/
setCustomParameters(
customOAuthParameters: Object
): firebase.auth.AuthProvider;
}
class SAMLAuthProvider implements firebase.auth.AuthProvider {
constructor(providerId: string);
providerId: string;
}
/**
* Interface representing ID token result obtained from
* {@link firebase.User.getIdTokenResult}. It contains the ID token JWT string
* and other helper properties for getting different data associated with the
* token as well as all the decoded payload claims.
*
* Note that these claims are not to be trusted as they are parsed client side.
* Only server side verification can guarantee the integrity of the token
* claims.
*/
interface IdTokenResult {
/**
* The Firebase Auth ID token JWT string.
*/
token: string;
/**
* The ID token expiration time formatted as a UTC string.
*/
expirationTime: string;
/**
* The authentication time formatted as a UTC string. This is the time the
* user authenticated (signed in) and not the time the token was refreshed.
*/
authTime: string;
/**
* The ID token issued at time formatted as a UTC string.
*/
issuedAtTime: string;
/**
* The sign-in provider through which the ID token was obtained (anonymous,
* custom, phone, password, etc). Note, this does not map to provider IDs.
*/
signInProvider: string | null;
/**
* The type of second factor associated with this session, provided the user
* was multi-factor authenticated (eg. phone, etc).
*/
signInSecondFactor: string | null;
/**
* The entire payload claims of the ID token including the standard reserved
* claims as well as the custom claims.
*/
claims: {
[key: string]: any;
};
}
/**
* Defines the options for initializing an
* {@link firebase.auth.OAuthCredential}. For ID tokens with nonce claim,
* the raw nonce has to also be provided.
*/
interface OAuthCredentialOptions {
/**
* The OAuth ID token used to initialize the OAuthCredential.
*/
idToken?: string;
/**
* The OAuth access token used to initialize the OAuthCredential.
*/
accessToken?: string;
/**
* The raw nonce associated with the ID token. It is required when an ID token
* with a nonce field is provided. The SHA-256 hash of the raw nonce must match
* the nonce field in the ID token.
*/
rawNonce?: string;
}
/**
* The base class for asserting ownership of a second factor. This is used to
* facilitate enrollment of a second factor on an existing user
* or sign-in of a user who already verified the first factor.
*
*/
abstract class MultiFactorAssertion {
/**
* The identifier of the second factor.
*/
factorId: string;
}
/**
* The class for asserting ownership of a phone second factor.
*/
class PhoneMultiFactorAssertion extends firebase.auth.MultiFactorAssertion {
private constructor();
}
/**
* The class used to initialize {@link firebase.auth.PhoneMultiFactorAssertion}.
*/
class PhoneMultiFactorGenerator {
private constructor();
/**
* The identifier of the phone second factor: `phone`.
*/
static FACTOR_ID: string;
/**
* Initializes the {@link firebase.auth.PhoneMultiFactorAssertion} to confirm ownership
* of the phone second factor.
*/
static assertion(
phoneAuthCredential: firebase.auth.PhoneAuthCredential
): firebase.auth.PhoneMultiFactorAssertion;
}
/**
* A structure containing the information of a second factor entity.
*/
interface MultiFactorInfo {
/**
* The multi-factor enrollment ID.
*/
uid: string;
/**
* The user friendly name of the current second factor.
*/
displayName?: string | null;
/**
* The enrollment date of the second factor formatted as a UTC string.
*/
enrollmentTime: string;
/**
* The identifier of the second factor.
*/
factorId: string;
}
/**
* The subclass of the MultiFactorInfo interface for phone number second factors.
* The factorId of this second factor is
* {@link firebase.auth.PhoneMultiFactorGenerator.FACTOR_ID}.
*/
interface PhoneMultiFactorInfo extends firebase.auth.MultiFactorInfo {
/**
* The phone number associated with the current second factor.
*/
phoneNumber: string;
}
/**
* The information required to verify the ownership of a phone number. The
* information that's required depends on whether you are doing single-factor
* sign-in, multi-factor enrollment or multi-factor sign-in.
*/
type PhoneInfoOptions =
| firebase.auth.PhoneSingleFactorInfoOptions
| firebase.auth.PhoneMultiFactorEnrollInfoOptions
| firebase.auth.PhoneMultiFactorSignInInfoOptions;
/**
* The phone info options for single-factor sign-in. Only phone number is
* required.
*/
interface PhoneSingleFactorInfoOptions {
phoneNumber: string;
}
/**
* The phone info options for multi-factor enrollment. Phone number and
* multi-factor session are required.
*/
interface PhoneMultiFactorEnrollInfoOptions {
phoneNumber: string;
session: firebase.auth.MultiFactorSession;
}
/**
* The phone info options for multi-factor sign-in. Either multi-factor hint or
* multi-factor UID and multi-factor session are required.
*/
interface PhoneMultiFactorSignInInfoOptions {
multiFactorHint?: firebase.auth.MultiFactorInfo;
multiFactorUid?: string;
session: firebase.auth.MultiFactorSession;
}
/**
* The class used to facilitate recovery from
* {@link firebase.auth.MultiFactorError} when a user needs to provide a second
* factor to sign in.
*
* @example
* ```javascript
* firebase.auth().signInWithEmailAndPassword()
* .then(function(result) {
* // User signed in. No 2nd factor challenge is needed.
* })
* .catch(function(error) {
* if (error.code == 'auth/multi-factor-auth-required') {
* var resolver = error.resolver;
* // Show UI to let user select second factor.
* var multiFactorHints = resolver.hints;
* } else {
* // Handle other errors.
* }
* });
*
* // The enrolled second factors that can be used to complete
* // sign-in are returned in the `MultiFactorResolver.hints` list.
* // UI needs to be presented to allow the user to select a second factor
* // from that list.
*
* var selectedHint = // ; selected from multiFactorHints
* var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
* var phoneInfoOptions = {
* multiFactorHint: selectedHint,
* session: resolver.session
* };
* phoneAuthProvider.verifyPhoneNumber(
* phoneInfoOptions,
* appVerifier
* ).then(function(verificationId) {
* // store verificationID and show UI to let user enter verification code.
* });
*
* // UI to enter verification code and continue.
* // Continue button click handler
* var phoneAuthCredential =
* firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
* var multiFactorAssertion =
* firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
* resolver.resolveSignIn(multiFactorAssertion)
* .then(function(userCredential) {
* // User signed in.
* });
* ```
*/
class MultiFactorResolver {
private constructor();
/**
* The Auth instance used to sign in with the first factor.
*/
auth: firebase.auth.Auth;
/**
* The session identifier for the current sign-in flow, which can be used
* to complete the second factor sign-in.
*/
session: firebase.auth.MultiFactorSession;
/**
* The list of hints for the second factors needed to complete the sign-in
* for the current session.
*/
hints: firebase.auth.MultiFactorInfo[];
/**
* A helper function to help users complete sign in with a second factor
* using an {@link firebase.auth.MultiFactorAssertion} confirming the user
* successfully completed the second factor challenge.
*
* enrolledFactors()
)
* or the factor's UID string.
* Sessions are not revoked when the account is downgraded. An email
* notification is likely to be sent to the user notifying them of the change.
* Recent re-authentication is required for this operation to succeed.
* When an existing factor is unenrolled, an email notification is sent to the
* user’s email.
*
*