forked from go-oauth2/oauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
const.go
72 lines (61 loc) · 1.51 KB
/
const.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package oauth2
import (
"crypto/sha256"
"encoding/base64"
)
// ResponseType the type of authorization request
type ResponseType string
// define the type of authorization request
const (
Code ResponseType = "code"
Token ResponseType = "token"
)
func (rt ResponseType) String() string {
return string(rt)
}
// GrantType authorization model
type GrantType string
// define authorization model
const (
AuthorizationCode GrantType = "authorization_code"
PasswordCredentials GrantType = "password"
ClientCredentials GrantType = "client_credentials"
Refreshing GrantType = "refresh_token"
Implicit GrantType = "__implicit"
)
func (gt GrantType) String() string {
if gt == AuthorizationCode ||
gt == PasswordCredentials ||
gt == ClientCredentials ||
gt == Refreshing {
return string(gt)
}
return ""
}
// CodeChallengeMethod PCKE method
type CodeChallengeMethod string
const (
// CodeChallengePlain PCKE Method
CodeChallengePlain CodeChallengeMethod = "plain"
// CodeChallengeS256 PCKE Method
CodeChallengeS256 CodeChallengeMethod = "S256"
)
func (ccm CodeChallengeMethod) String() string {
if ccm == CodeChallengePlain ||
ccm == CodeChallengeS256 {
return string(ccm)
}
return ""
}
// Validate code challenge
func (ccm CodeChallengeMethod) Validate(cc, ver string) bool {
switch ccm {
case CodeChallengePlain:
return cc == ver
case CodeChallengeS256:
s256 := sha256.Sum256([]byte(ver))
return base64.URLEncoding.EncodeToString(s256[:]) == cc
default:
return false
}
}