forked from maxzerbini/oauth
/
verifier.go
55 lines (46 loc) · 1.77 KB
/
verifier.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
package oauth
import (
"errors"
"net/http"
)
type TestUserVerifier struct {
}
// ValidateUser validates username and password returning an error if the user credentials are wrong
func (*TestUserVerifier) ValidateUser(username, password, scope string, req *http.Request) error {
if username == "user01" && password == "12345" {
return nil
}
return errors.New("Wrong user")
}
// ValidateClient validates clientId and secret returning an error if the client credentials are wrong
func (*TestUserVerifier) ValidateClient(clientID, clientSecret, scope string, req *http.Request) error {
if clientID == "abcdef" && clientSecret == "12345" {
return nil
}
return errors.New("Wrong client")
}
// AddClaims provides additional claims to the token
func (*TestUserVerifier) AddClaims(credential, tokenID, tokenType, scope string) (map[string]string, error) {
claims := make(map[string]string)
claims["customerId"] = "1001"
claims["customerData"] = `{"OrderDate":"2016-12-14","OrderId":"9999"}`
return claims, nil
}
// StoreTokenId saves the token Id generated for the user
func (*TestUserVerifier) StoreTokenId(credential, tokenId, refreshTokenID, tokenType string) error {
return nil
}
// AddProperties provides additional information to the token response
func (*TestUserVerifier) AddProperties(credential, tokenId, tokenType string, scope string) (map[string]string, error) {
props := make(map[string]string)
props["customerName"] = "Gopher"
return props, nil
}
// ValidateTokenId validates token Id
func (*TestUserVerifier) ValidateTokenId(credential, tokenId, refreshTokenID, tokenType string) error {
return nil
}
// ValidateCode validates token Id
func (*TestUserVerifier) ValidateCode(clientID, clientSecret, code, redirectURI string, req *http.Request) (string, error) {
return "", nil
}