Created
October 11, 2017 20:14
-
-
Save stupiduglyfool/3a5bd9e121330013c78fbfe0697cf76d to your computer and use it in GitHub Desktop.
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
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