Skip to content
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

fix(docs): improve types and docs for generateCodeVerifierAsync #840

Merged
merged 1 commit into from Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/auth/oauth2client.ts
Expand Up @@ -29,6 +29,24 @@ import {AuthClient} from './authclient';
import {CredentialRequest, Credentials, JWTInput} from './credentials';
import {LoginTicket, TokenPayload} from './loginticket';

/**
* The results from the `generateCodeVerifierAsync` method. To learn more,
* See the sample:
* https://github.com/googleapis/google-auth-library-nodejs/blob/master/samples/oauth2-codeVerifier.js
*/
export interface CodeVerifierResults {
/**
* The code verifier that will be used when calling `getToken` to obtain a new
* access token.
*/
codeVerifier: string;
/**
* The code_challenge that should be sent with the `generateAuthUrl` call
* to obtain a verifiable authentication url.
*/
codeChallenge?: string;
}

export interface Certificates {
[index: string]: string | JwkCertificate;
}
Expand Down Expand Up @@ -485,7 +503,7 @@ export class OAuth2Client extends AuthClient {
return rootUrl + '?' + querystring.stringify(opts);
}

generateCodeVerifier() {
generateCodeVerifier(): void {
// To make the code compatible with browser SubtleCrypto we need to make
// this method async.
throw new Error(
Expand All @@ -497,8 +515,11 @@ export class OAuth2Client extends AuthClient {
* Convenience method to automatically generate a code_verifier, and it's
* resulting SHA256. If used, this must be paired with a S256
* code_challenge_method.
*
* For a full example see:
* https://github.com/googleapis/google-auth-library-nodejs/blob/master/samples/oauth2-codeVerifier.js
*/
async generateCodeVerifierAsync() {
async generateCodeVerifierAsync(): Promise<CodeVerifierResults> {
// base64 encoding uses 6 bits per character, and we want to generate128
// characters. 6*128/8 = 96.
const crypto = createCrypto();
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -28,6 +28,7 @@ export {JWT, JWTOptions} from './auth/jwtclient';
export {
Certificates,
CodeChallengeMethod,
CodeVerifierResults,
GenerateAuthUrlOpts,
GetTokenOptions,
OAuth2Client,
Expand Down