-
Notifications
You must be signed in to change notification settings - Fork 910
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,706 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@firebase/auth': patch | ||
--- | ||
|
||
Support TOTP as a multi-factor option in Firebase Auth/GCIP. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 %} | ||
|
||
# TotpMultiFactorAssertion interface | ||
The class for asserting ownership of a TOTP second factor. Provided by [TotpMultiFactorGenerator.assertionForEnrollment()](./auth.totpmultifactorgenerator.md#totpmultifactorgeneratorassertionforenrollment) and [TotpMultiFactorGenerator.assertionForSignIn()](./auth.totpmultifactorgenerator.md#totpmultifactorgeneratorassertionforsignin)<!-- -->. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface TotpMultiFactorAssertion extends MultiFactorAssertion | ||
``` | ||
<b>Extends:</b> [MultiFactorAssertion](./auth.multifactorassertion.md#multifactorassertion_interface) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
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 %} | ||
|
||
# TotpMultiFactorGenerator class | ||
Provider for generating a [TotpMultiFactorAssertion](./auth.totpmultifactorassertion.md#totpmultifactorassertion_interface)<!-- -->. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare class TotpMultiFactorGenerator | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Modifiers | Type | Description | | ||
| --- | --- | --- | --- | | ||
| [FACTOR\_ID](./auth.totpmultifactorgenerator.md#totpmultifactorgeneratorfactor_id) | <code>static</code> | FactorId | The identifier of the TOTP second factor: <code>totp</code>. | | ||
|
||
## Methods | ||
|
||
| Method | Modifiers | Description | | ||
| --- | --- | --- | | ||
| [assertionForEnrollment(secret, oneTimePassword)](./auth.totpmultifactorgenerator.md#totpmultifactorgeneratorassertionforenrollment) | <code>static</code> | Provides a [TotpMultiFactorAssertion](./auth.totpmultifactorassertion.md#totpmultifactorassertion_interface) to confirm ownership of the TOTP (time-based one-time password) second factor. This assertion is used to complete enrollment in TOTP second factor. | | ||
| [assertionForSignIn(enrollmentId, oneTimePassword)](./auth.totpmultifactorgenerator.md#totpmultifactorgeneratorassertionforsignin) | <code>static</code> | Provides a [TotpMultiFactorAssertion](./auth.totpmultifactorassertion.md#totpmultifactorassertion_interface) to confirm ownership of the TOTP second factor. This assertion is used to complete signIn with TOTP as the second factor. | | ||
| [generateSecret(session)](./auth.totpmultifactorgenerator.md#totpmultifactorgeneratorgeneratesecret) | <code>static</code> | Returns a promise to [TotpSecret](./auth.totpsecret.md#totpsecret_class) which contains the TOTP shared secret key and other parameters. Creates a TOTP secret as part of enrolling a TOTP second factor. Used for generating a QR code URL or inputting into a TOTP app. This method uses the auth instance corresponding to the user in the multiFactorSession. | | ||
|
||
## TotpMultiFactorGenerator.FACTOR\_ID | ||
|
||
The identifier of the TOTP second factor: `totp`<!-- -->. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
static FACTOR_ID: FactorId; | ||
``` | ||
|
||
## TotpMultiFactorGenerator.assertionForEnrollment() | ||
|
||
Provides a [TotpMultiFactorAssertion](./auth.totpmultifactorassertion.md#totpmultifactorassertion_interface) to confirm ownership of the TOTP (time-based one-time password) second factor. This assertion is used to complete enrollment in TOTP second factor. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
static assertionForEnrollment(secret: TotpSecret, oneTimePassword: string): TotpMultiFactorAssertion; | ||
``` | ||
|
||
### Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| secret | [TotpSecret](./auth.totpsecret.md#totpsecret_class) | A [TotpSecret](./auth.totpsecret.md#totpsecret_class) containing the shared secret key and other TOTP parameters. | | ||
| oneTimePassword | string | One-time password from TOTP App. | | ||
|
||
<b>Returns:</b> | ||
|
||
[TotpMultiFactorAssertion](./auth.totpmultifactorassertion.md#totpmultifactorassertion_interface) | ||
|
||
A [TotpMultiFactorAssertion](./auth.totpmultifactorassertion.md#totpmultifactorassertion_interface) which can be used with [MultiFactorUser.enroll()](./auth.multifactoruser.md#multifactoruserenroll)<!-- -->. | ||
|
||
## TotpMultiFactorGenerator.assertionForSignIn() | ||
|
||
Provides a [TotpMultiFactorAssertion](./auth.totpmultifactorassertion.md#totpmultifactorassertion_interface) to confirm ownership of the TOTP second factor. This assertion is used to complete signIn with TOTP as the second factor. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
static assertionForSignIn(enrollmentId: string, oneTimePassword: string): TotpMultiFactorAssertion; | ||
``` | ||
|
||
### Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| enrollmentId | string | identifies the enrolled TOTP second factor. | | ||
| oneTimePassword | string | One-time password from TOTP App. | | ||
|
||
<b>Returns:</b> | ||
|
||
[TotpMultiFactorAssertion](./auth.totpmultifactorassertion.md#totpmultifactorassertion_interface) | ||
|
||
A [TotpMultiFactorAssertion](./auth.totpmultifactorassertion.md#totpmultifactorassertion_interface) which can be used with [MultiFactorResolver.resolveSignIn()](./auth.multifactorresolver.md#multifactorresolverresolvesignin)<!-- -->. | ||
|
||
## TotpMultiFactorGenerator.generateSecret() | ||
|
||
Returns a promise to [TotpSecret](./auth.totpsecret.md#totpsecret_class) which contains the TOTP shared secret key and other parameters. Creates a TOTP secret as part of enrolling a TOTP second factor. Used for generating a QR code URL or inputting into a TOTP app. This method uses the auth instance corresponding to the user in the multiFactorSession. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
static generateSecret(session: MultiFactorSession): Promise<TotpSecret>; | ||
``` | ||
|
||
### Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| session | [MultiFactorSession](./auth.multifactorsession.md#multifactorsession_interface) | The [MultiFactorSession](./auth.multifactorsession.md#multifactorsession_interface) that the user is part of. | | ||
|
||
<b>Returns:</b> | ||
|
||
Promise<[TotpSecret](./auth.totpsecret.md#totpsecret_class)<!-- -->> | ||
|
||
A promise to [TotpSecret](./auth.totpsecret.md#totpsecret_class)<!-- -->. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 %} | ||
|
||
# TotpMultiFactorInfo interface | ||
The subclass of the [MultiFactorInfo](./auth.multifactorinfo.md#multifactorinfo_interface) interface for TOTP second factors. The `factorId` of this second factor is [FactorId](./auth.md#factorid)<!-- -->.TOTP. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface TotpMultiFactorInfo extends MultiFactorInfo | ||
``` | ||
<b>Extends:</b> [MultiFactorInfo](./auth.multifactorinfo.md#multifactorinfo_interface) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
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 %} | ||
|
||
# TotpSecret class | ||
Provider for generating a [TotpMultiFactorAssertion](./auth.totpmultifactorassertion.md#totpmultifactorassertion_interface)<!-- -->. | ||
|
||
Stores the shared secret key and other parameters to generate time-based OTPs. Implements methods to retrieve the shared secret key and generate a QR code URL. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export declare class TotpSecret | ||
``` | ||
|
||
## Properties | ||
|
||
| Property | Modifiers | Type | Description | | ||
| --- | --- | --- | --- | | ||
| [codeIntervalSeconds](./auth.totpsecret.md#totpsecretcodeintervalseconds) | | number | The interval (in seconds) when the OTP codes should change. | | ||
| [codeLength](./auth.totpsecret.md#totpsecretcodelength) | | number | Length of the one-time passwords to be generated. | | ||
| [enrollmentCompletionDeadline](./auth.totpsecret.md#totpsecretenrollmentcompletiondeadline) | | string | The timestamp (UTC string) by which TOTP enrollment should be completed. | | ||
| [hashingAlgorithm](./auth.totpsecret.md#totpsecrethashingalgorithm) | | string | Hashing algorithm used. | | ||
| [secretKey](./auth.totpsecret.md#totpsecretsecretkey) | | string | Shared secret key/seed used for enrolling in TOTP MFA and generating OTPs. | | ||
|
||
## Methods | ||
|
||
| Method | Modifiers | Description | | ||
| --- | --- | --- | | ||
| [generateQrCodeUrl(accountName, issuer)](./auth.totpsecret.md#totpsecretgenerateqrcodeurl) | | Returns a QR code URL as described in https://github.com/google/google-authenticator/wiki/Key-Uri-Format This can be displayed to the user as a QR code to be scanned into a TOTP app like Google Authenticator. If the optional parameters are unspecified, an accountName of <userEmail> and issuer of <firebaseAppName> are used. | | ||
|
||
## TotpSecret.codeIntervalSeconds | ||
|
||
The interval (in seconds) when the OTP codes should change. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly codeIntervalSeconds: number; | ||
``` | ||
|
||
## TotpSecret.codeLength | ||
|
||
Length of the one-time passwords to be generated. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly codeLength: number; | ||
``` | ||
|
||
## TotpSecret.enrollmentCompletionDeadline | ||
|
||
The timestamp (UTC string) by which TOTP enrollment should be completed. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly enrollmentCompletionDeadline: string; | ||
``` | ||
|
||
## TotpSecret.hashingAlgorithm | ||
|
||
Hashing algorithm used. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly hashingAlgorithm: string; | ||
``` | ||
|
||
## TotpSecret.secretKey | ||
|
||
Shared secret key/seed used for enrolling in TOTP MFA and generating OTPs. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
readonly secretKey: string; | ||
``` | ||
|
||
## TotpSecret.generateQrCodeUrl() | ||
|
||
Returns a QR code URL as described in https://github.com/google/google-authenticator/wiki/Key-Uri-Format This can be displayed to the user as a QR code to be scanned into a TOTP app like Google Authenticator. If the optional parameters are unspecified, an accountName of <userEmail> and issuer of <firebaseAppName> are used. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
generateQrCodeUrl(accountName?: string, issuer?: string): string; | ||
``` | ||
|
||
### Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| accountName | string | the name of the account/app along with a user identifier. | | ||
| issuer | string | issuer of the TOTP (likely the app name). | | ||
|
||
<b>Returns:</b> | ||
|
||
string | ||
|
||
A QR code URL string. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ host of npm scripts to run these tests. The most important commands are: | |
| `yarn test:<platform>:unit:debug` | Runs \<platform> unit tests, auto-watching for file system changes | | ||
| `yarn test:<platform>:integration` | Runs only integration tests against the live environment | | ||
| `yarn test:<platform>:integration:local` | Runs all headless \<platform> integration tests against the emulator (more below) | | ||
| `yarn test:browser:integration:prodbackend` | Runs TOTP MFA integration tests against the backend (more below) | | ||
|
||
Where \<platform> is "browser" or "node". There are also cordova tests, but they | ||
are not broken into such granular details. Check out `package.json` for more. | ||
|
@@ -46,6 +47,25 @@ you would simply execute the following command: | |
firebase emulators:exec --project foo-bar --only auth "yarn test:integration:local" | ||
``` | ||
|
||
### Integration testing with the production backend | ||
|
||
Currently, MFA TOTP tests only run against the production backend (since they are not supported on the emulator yet). | ||
Running against the backend also makes it a more reliable end-to-end test. | ||
|
||
The TOTP tests require the following email/password combination to exist in the project, so if you are running this test against your test project, please create this user: | ||
|
||
'[email protected]', 'password' | ||
|
||
You also need to verify this email address, in order to use MFA. This can be done with a curl command like this: | ||
|
||
``` | ||
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json" -H "X-Goog-User-Project: ${PROJECT_ID}" -X POST https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode -d '{ | ||
"email": "[email protected]", | ||
"requestType": "VERIFY_EMAIL", | ||
"returnOobLink": true, | ||
}' | ||
``` | ||
|
||
### Selenium Webdriver tests | ||
|
||
These tests assume that you have both Firefox and Chrome installed on your | ||
|
Oops, something went wrong.