voluptasmollitia
Version:
Monorepo for the Firebase JavaScript SDK
67 lines (48 loc) • 2.62 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@firebase/auth](./auth.md) > [OAuthProvider](./auth.oauthprovider.md)
## OAuthProvider class
Provider for generating generic [OAuthCredential](./auth.oauthcredential.md)<!-- -->.
<b>Signature:</b>
```typescript
export declare class OAuthProvider extends BaseOAuthProvider
```
<b>Extends:</b> BaseOAuthProvider
## Example 1
```javascript
// Sign in using a redirect.
const provider = new OAuthProvider('google.com');
// Start a sign in process for an unauthenticated user.
provider.addScope('profile');
provider.addScope('email');
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 OAuth Access Token for the provider.
const credential = provider.credentialFromResult(auth, result);
const token = credential.accessToken;
}
```
## Example 2
```javascript
// Sign in using a popup.
const provider = new OAuthProvider('google.com');
provider.addScope('profile');
provider.addScope('email');
const result = await signInWithPopup(auth, provider);
// The signed-in user info.
const user = result.user;
// This gives you a OAuth Access Token for the provider.
const credential = provider.credentialFromResult(auth, result);
const token = credential.accessToken;
```
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [credential(params)](./auth.oauthprovider.credential.md) | | Creates a [OAuthCredential](./auth.oauthcredential.md) from a generic OAuth provider's access token or ID token. |
| [credentialFromError(error)](./auth.oauthprovider.credentialfromerror.md) | <code>static</code> | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [AuthError](./auth.autherror.md) which was thrown during a sign-in, link, or reauthenticate operation. |
| [credentialFromJSON(json)](./auth.oauthprovider.credentialfromjson.md) | <code>static</code> | Creates an [OAuthCredential](./auth.oauthcredential.md) from a JSON string or a plain object. |
| [credentialFromResult(userCredential)](./auth.oauthprovider.credentialfromresult.md) | <code>static</code> | Used to extract the underlying [OAuthCredential](./auth.oauthcredential.md) from a [UserCredential](./auth.usercredential.md)<!-- -->. |