init
This commit is contained in:
commit
ec53fcbe95
1905 changed files with 513762 additions and 0 deletions
23
services/oauth/crypto.ts
Normal file
23
services/oauth/crypto.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { createHash, randomBytes } from 'crypto'
|
||||
|
||||
function base64URLEncode(buffer: Buffer): string {
|
||||
return buffer
|
||||
.toString('base64')
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_')
|
||||
.replace(/=/g, '')
|
||||
}
|
||||
|
||||
export function generateCodeVerifier(): string {
|
||||
return base64URLEncode(randomBytes(32))
|
||||
}
|
||||
|
||||
export function generateCodeChallenge(verifier: string): string {
|
||||
const hash = createHash('sha256')
|
||||
hash.update(verifier)
|
||||
return base64URLEncode(hash.digest())
|
||||
}
|
||||
|
||||
export function generateState(): string {
|
||||
return base64URLEncode(randomBytes(32))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue