initial commit
This commit is contained in:
commit
6d0890e280
68 changed files with 5986 additions and 0 deletions
33
pkg/oidc/code_challenge.go
Normal file
33
pkg/oidc/code_challenge.go
Normal file
|
@ -0,0 +1,33 @@
|
|||
package oidc
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
|
||||
"github.com/caos/oidc/pkg/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
CodeChallengeMethodPlain CodeChallengeMethod = "plain"
|
||||
CodeChallengeMethodS256 CodeChallengeMethod = "S256"
|
||||
)
|
||||
|
||||
type CodeChallengeMethod string
|
||||
|
||||
type CodeChallenge struct {
|
||||
Challenge string
|
||||
Method CodeChallengeMethod
|
||||
}
|
||||
|
||||
func NewSHACodeChallenge(code string) string {
|
||||
return utils.HashString(sha256.New(), code)
|
||||
}
|
||||
|
||||
func VerifyCodeChallenge(c *CodeChallenge, codeVerifier string) bool {
|
||||
if c == nil {
|
||||
return false //TODO: ?
|
||||
}
|
||||
if c.Method == CodeChallengeMethodS256 {
|
||||
codeVerifier = NewSHACodeChallenge(codeVerifier)
|
||||
}
|
||||
return codeVerifier == c.Challenge
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue