Project: /docs/reference/js/_project.yaml Book: /docs/reference/_book.yaml page_type: reference
{% comment %} DO NOT EDIT THIS FILE! This is generated by the JS SDK team, and any local changes will be overwritten. Changes should be made in the source code at https://github.com/firebase/firebase-js-sdk {% endcomment %}
Provider for generating an OAuthCredential for ProviderId.TWITTER.
Signature:
export declare class TwitterAuthProvider extends BaseOAuthProvider
Extends: BaseOAuthProvider
Constructor | Modifiers | Description |
---|---|---|
(constructor)() | Constructs a new instance of the TwitterAuthProvider class |
Property | Modifiers | Type | Description |
---|---|---|---|
PROVIDER_ID | static |
'twitter.com' | Always set to ProviderId.TWITTER. |
TWITTER_SIGN_IN_METHOD | static |
'twitter.com' | Always set to SignInMethod.TWITTER. |
Method | Modifiers | Description |
---|---|---|
credential(token, secret) | static |
Creates a credential for Twitter. |
credentialFromError(error) | static |
Used to extract the underlying OAuthCredential from a AuthError which was thrown during a sign-in, link, or reauthenticate operation. |
credentialFromResult(userCredential) | static |
Used to extract the underlying OAuthCredential from a UserCredential. |
Constructs a new instance of the TwitterAuthProvider
class
Signature:
constructor();
Always set to ProviderId.TWITTER.
Signature:
static readonly PROVIDER_ID: 'twitter.com';
Always set to SignInMethod.TWITTER.
Signature:
static readonly TWITTER_SIGN_IN_METHOD: 'twitter.com';
Creates a credential for Twitter.
Signature:
static credential(token: string, secret: string): OAuthCredential;
Parameter | Type | Description |
---|---|---|
token | string | Twitter access token. |
secret | string | Twitter secret. |
Returns:
Used to extract the underlying OAuthCredential from a AuthError which was thrown during a sign-in, link, or reauthenticate operation.
Signature:
static credentialFromError(error: FirebaseError): OAuthCredential | null;
Parameter | Type | Description |
---|---|---|
error | FirebaseError |
Returns:
OAuthCredential | null
Used to extract the underlying OAuthCredential from a UserCredential.
Signature:
static credentialFromResult(userCredential: UserCredential): OAuthCredential | null;
Parameter | Type | Description |
---|---|---|
userCredential | UserCredential | The user credential. |
Returns:
OAuthCredential | null
// Sign in using a redirect.
const provider = new TwitterAuthProvider();
// Start a sign in process for an unauthenticated user.
await signInWithRedirect(auth, provider);
// This will trigger a full page redirect away from your app
// After returning from the redirect when your app initializes you can obtain the result
const result = await getRedirectResult(auth);
if (result) {
// This is the signed-in user
const user = result.user;
// This gives you a Twitter Access Token and Secret.
const credential = TwitterAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
const secret = credential.secret;
}
// Sign in using a popup.
const provider = new TwitterAuthProvider();
const result = await signInWithPopup(auth, provider);
// The signed-in user info.
const user = result.user;
// This gives you a Twitter Access Token and Secret.
const credential = TwitterAuthProvider.credentialFromResult(result);
const token = credential.accessToken;
const secret = credential.secret;