-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmock.go
70 lines (56 loc) · 1.39 KB
/
mock.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
package grpc
import (
"context"
"encoding/json"
"flamingo.me/flamingo/v3/core/auth"
"flamingo.me/flamingo/v3/framework/config"
"golang.org/x/oauth2"
)
type mockCallIdentifier struct {
identifier string
subject string
claims []byte
}
var _ CallIdentifier = new(mockCallIdentifier)
func mockFactory(cfg config.Map) (CallIdentifier, error) {
var config struct {
Identifier string
Subject string
Claims string
}
if err := cfg.MapInto(&config); err != nil {
return nil, err
}
return &mockCallIdentifier{
identifier: config.Identifier,
subject: config.Subject,
claims: []byte(config.Claims),
}, nil
}
func (identifier *mockCallIdentifier) Identifier() string {
return identifier.identifier
}
type mockIdentity struct {
identifier string
subject string
claims []byte
}
func (identity *mockIdentity) Broker() string {
return identity.identifier
}
func (identity *mockIdentity) Subject() string {
return identity.subject
}
func (identity *mockIdentity) AccessTokenClaims(into interface{}) error {
return json.Unmarshal(identity.claims, into)
}
func (identity *mockIdentity) TokenSource() oauth2.TokenSource {
return nil
}
func (identifier *mockCallIdentifier) Identify(ctx context.Context) (auth.Identity, error) {
return &mockIdentity{
identifier: identifier.identifier,
subject: identifier.subject,
claims: identifier.claims,
}, nil
}