Skip to content

Instantly share code, notes, and snippets.

@stupiduglyfool
Created October 11, 2017 20:14
Show Gist options
  • Save stupiduglyfool/3a5bd9e121330013c78fbfe0697cf76d to your computer and use it in GitHub Desktop.
Save stupiduglyfool/3a5bd9e121330013c78fbfe0697cf76d to your computer and use it in GitHub Desktop.
import * as crypto from 'crypto';
export class CodeVerifier {
challenge: string;
method: string;
verifier: string;
private base64URLEncode(value: Buffer) {
return value.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '');
}
public static sha256(value: string) {
return crypto.createHash('sha256').update(value).digest();
}
private getVerifier() {
return this.base64URLEncode(crypto.randomBytes(32));
}
constructor() {
this.verifier = this.getVerifier();
this.challenge = this.base64URLEncode(CodeVerifier.sha256(this.verifier));
this.method = "S256";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment