Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added PKCE helper library for swan authentication
- Loading branch information
Showing
8 changed files
with
197 additions
and
139 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -773,4 +773,4 @@ SPEC CHECKSUMS: | |
|
||
PODFILE CHECKSUM: 579ac7919977593ab0196f9f26d3bc979b90364a | ||
|
||
COCOAPODS: 1.9.3 | ||
COCOAPODS: 1.8.4 |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import crypto from 'crypto' | ||
import base64url from 'base64url' | ||
|
||
export const generatePKCEParameters = () => { | ||
console.log( ' made it to generator' ) | ||
const code_verifier = generateRandomString( 64 ) | ||
|
||
const base64Digest = crypto | ||
.createHash( 'sha256' ) | ||
.update( code_verifier ) | ||
.digest( 'base64' ) | ||
|
||
const code_challenge = base64url.fromBase64( base64Digest ) | ||
|
||
const nonce = `${generateRandomNumber ( 11 )}-${generateRandomString( 3 )}` | ||
|
||
const state = `${generateRandomNumber ( 11 )}-${generateRandomString( 3 )}` | ||
|
||
return { | ||
code_challenge, code_verifier, nonce, state | ||
} | ||
} | ||
|
||
const generateRandomString = ( length: number ): string => { | ||
let randomString = '' | ||
const possibleChars = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' | ||
for ( let itr = 0; itr < length; itr++ ) { | ||
randomString += possibleChars.charAt( | ||
Math.floor( Math.random() * possibleChars.length ), | ||
) | ||
} | ||
return randomString | ||
} | ||
|
||
const generateRandomNumber = ( digits: number ): number => Math.floor( Math.random() * 10**digits ) |
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