Documentation ¶
Overview ¶
Proof Key for Code Exchange (PKCE) helps public clients to get access tokens and refresh tokens. PKCE is based on RFC7636, more on that can be found at https://tools.ietf.org/html/rfc7636 and https://auth0.com/docs/flows/authorization-code-flow-with-proof-key-for-code-exchange-pkce.
Index ¶
Examples ¶
Constants ¶
View Source
const LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~"
LETTERS according to https://tools.ietf.org/html/rfc7636#section-4.1
Variables ¶
This section is empty.
Functions ¶
func GenerateRandomString ¶
GenerateRandomString returns a random string of a given length
Types ¶
type Pkce ¶
type Pkce struct { // Optional, RandomString, this will be converted to Pkce.ChallengeCode RandomString string // Optional, Length of the Pkce.VerifyCode. When RandomString is provided, the Length is ignored. // The value should be minimum 43 and maximum 128. Length int }
func (*Pkce) ChallengeCode ¶
ChallengeCode returns a challenge code as mentioned in https://tools.ietf.org/html/rfc7636#section-4.2. The code is based on
code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
Example ¶
p := Pkce{ RandomString: "45d7820e694481f399e7fb9c444f0cb63301a7254d1401443835d9af2c9a6a5ec5b243c3470feb945336025964ef05c8d2f0e44baf76762ba6136914", } code, err := p.ChallengeCode() if err != nil { panic(err) } fmt.Println(code)
Output: iQoF8w9kq5RnuMdisRXypyOoMCF7FGz-ro7dwHjC28U
Example (GeneratedString) ¶
p := Pkce{ Length: 60, } code, err := p.VerifyCode() if err != nil { panic(err) } challengeCode, err := p.ChallengeCode() if err != nil { panic(err) } fmt.Println(code, challengeCode)
Output:
func (*Pkce) VerifyCode ¶
When Pkce.RandomString is provided, VerifyCode is similar to it if not, VerifyCode returns a random string based on Pkce.Length.
Example ¶
p := Pkce{ RandomString: "ThisIsAVeryBiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiigRandomString", } code, err := p.VerifyCode() if err != nil { panic(err) } fmt.Println(code)
Output: ThisIsAVeryBiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiigRandomString
Example (GeneratedString) ¶
p := Pkce{ Length: 60, } code, err := p.VerifyCode() if err != nil { panic(err) } fmt.Println(code)
Output:
Click to show internal directories.
Click to hide internal directories.