-
Notifications
You must be signed in to change notification settings - Fork 6
/
authorization.go
42 lines (31 loc) · 893 Bytes
/
authorization.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
package smarthome
const ACCEPT_GRANT_FAILED = "ACCEPT_GRANT_FAILED"
type AcceptGrantRequest struct {
Grant Grant `json:"grant"`
Grantee Scope `json:"grantee"`
}
type AcceptGrantResponse struct{}
type Grant struct {
Type string `json:"type"`
Code string `json:"code"`
}
type Scope struct {
Type string `json:"type"`
Token string `json:"token"`
}
type authorization struct {
sm *Smarthome
}
func (a *authorization) AcceptGrant(req AcceptGrantRequest) (AcceptGrantResponse, error) {
if err := a.sm.auth.AcceptGrant(req); err != nil {
return AcceptGrantResponse{}, newError(ACCEPT_GRANT_FAILED, err)
}
return AcceptGrantResponse{}, nil
}
type AuthorizationInterface interface {
AcceptGrant(req AcceptGrantRequest) error
}
type AuthorizationFunc func(req AcceptGrantRequest) error
func (af AuthorizationFunc) AcceptGrant(req AcceptGrantRequest) error {
return af(req)
}