This repository has been archived by the owner on Sep 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
scope.go
125 lines (115 loc) · 2.22 KB
/
scope.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package models
import (
"strings"
)
// - account
// :read
// :address
// :modify
// :delete
// - addresses
// :read
// :modify
// :delete
// - applications
// :read
// :modify
// :delete
// - emails
// :send
// :read
// :modify
// :delete
// - keys
// :read
// :modify
// :delete
// - labels
// :read
// :modify
// :delete
// - resources
// :create
// :read
// :modify
// :delete
// - threads
// :read
// :modify
// :delete
// - tokens
// :read
// :oauth
// :logout
// :modify
// :delete
var Scopes = map[string]struct{}{
"password_grant": {},
"admin": {},
"account": {},
"account:read": {},
"account:address": {},
"account:modify": {},
"account:delete": {},
"addresses": {},
"addresses:read": {},
"addresses:modify": {},
"addresses:delete": {},
"applications": {},
"applications:read": {},
"applications:modify": {},
"applications:delete": {},
"emails": {},
"emails:send": {},
"emails:read": {},
"emails:modify": {},
"emails:delete": {},
"keys": {},
"keys:read": {},
"labels": {},
"labels:read": {},
"labels:modify": {},
"labels:delete": {},
"resources": {},
"resources:read": {},
"resources:modify": {},
"resources:delete": {},
"threads": {},
"threads:read": {},
"threads:modify": {},
"threads:delete": {},
"tokens": {},
"tokens:read": {},
"tokens:oauth": {},
"tokens:logout": {},
"tokens:modify": {},
"tokens:delete": {},
}
func InScope(scope []string, what []string) bool {
// Transform scope into a hashmap
hm := map[string]struct{}{}
for _, x := range scope {
hm[x] = struct{}{}
}
// Check the scope contents
for _, x := range what {
found := false
if _, ok := hm["password_grant"]; x != "admin" && ok {
return true
}
if _, ok := hm[x]; ok {
found = true
} else {
if strings.Contains(x, ":") {
parts := strings.SplitN(x, ":", 2)
if _, ok := hm[parts[0]]; ok {
found = true
}
}
}
if !found {
return false
}
}
return true
}