-
Notifications
You must be signed in to change notification settings - Fork 946
Add public methods to support TOTP as a multi-factor provider. #6547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,78 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import { TotpSecret } from '../../platform_browser/mfa/assertions/totp'; | ||
import { | ||
TotpMultiFactorAssertion, | ||
MultiFactorSession, | ||
FactorId | ||
} from '../../model/public_types'; | ||
/** | ||
* Provider for generating a {@link TotpMultiFactorAssertion}. | ||
* | ||
* @public | ||
*/ | ||
export class TotpMultiFactorGenerator { | ||
/** | ||
* Provides a {@link TotpMultiFactorAssertion} to confirm ownership of | ||
* the totp(Time-based One Time Password) second factor. | ||
* This assertion is used to complete enrollment in TOTP second factor. | ||
* | ||
* @param secret {@link TotpSecret}. | ||
* @param oneTimePassword One-time password from TOTP App. | ||
* @returns A {@link TotpMultiFactorAssertion} which can be used with | ||
* {@link MultiFactorUser.enroll}. | ||
*/ | ||
static assertionForEnrollment( | ||
_secret: TotpSecret, | ||
_oneTimePassword: string | ||
): TotpMultiFactorAssertion { | ||
throw new Error('Unimplemented'); | ||
} | ||
/** | ||
* Provides a {@link TotpMultiFactorAssertion} to confirm ownership of the totp second factor. | ||
* This assertion is used to complete signIn with TOTP as the second factor. | ||
* | ||
* @param enrollmentId identifies the enrolled TOTP second factor. | ||
* @param otp One-time password from TOTP App. | ||
* @returns A {@link TotpMultiFactorAssertion} which can be used with | ||
* {@link MultiFactorResolver.resolveSignIn}. | ||
*/ | ||
static assertionForSignIn( | ||
_enrollmentId: string, | ||
_otp: string | ||
): TotpMultiFactorAssertion { | ||
throw new Error('Unimplemented'); | ||
} | ||
/** | ||
* Returns a promise to {@link TOTPSecret} 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 QRCode URL or inputting into a TOTP App. | ||
* This method uses the auth instance corresponding to the user in the multiFactorSession. | ||
* | ||
* @param session A link to {@MultiFactorSession}. | ||
* @returns A promise to {@link TotpSecret}. | ||
*/ | ||
static async generateSecret( | ||
_session: MultiFactorSession | ||
): Promise<TotpSecret> { | ||
throw new Error('Unimplemented'); | ||
} | ||
/** | ||
* The identifier of the TOTP second factor: `totp`. | ||
*/ | ||
static FACTOR_ID = FactorId.TOTP; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,50 @@ | ||
/** | ||
* @license | ||
* Copyright 2022 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Stores the shared secret key and other parameters to generate time-based OTPs. | ||
* Implements methods to retrieve the shared secret key, generate a QRCode URL. | ||
* @public | ||
*/ | ||
export class TotpSecret { | ||
/** | ||
* Constructor for TotpSecret. | ||
* @param secretKey - Shared secret key/seed used for enrolling in TOTP MFA and generating otps. | ||
* @param hashingAlgorithm - Hashing algorithm used. | ||
* @param codeLength - Length of the one-time passwords to be generated. | ||
* @param codeIntervalSeconds - The interval (in seconds) when the OTP codes should change. | ||
*/ | ||
constructor( | ||
readonly secretKey: string, | ||
readonly hashingAlgorithm: string, | ||
readonly codeLength: number, | ||
readonly codeIntervalSeconds: number | ||
) {} | ||
/** | ||
* Returns a QRCode URL as described in | ||
* https://github.com/google/google-authenticator/wiki/Key-Uri-Format | ||
* This can be displayed to the user as a QRCode to be scanned into a TOTP App like Google Authenticator. | ||
* If the optional parameters are unspecified, an accountName of "<firebaseAppName>:<userEmail> and issuer of <firebaseAppName> are used. | ||
* | ||
* @param accountName the name of the account/app along with a user identifier. | ||
* @param issuer issuer of the TOTP(likely the app name). | ||
* @returns A QRCode URL string. | ||
*/ | ||
generateQrCodeUrl(_accountName?: string, _issuer?: string): string { | ||
throw new Error('Unimplemented'); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.