2016-06-03 01:35:18 +05:30
|
|
|
package scope
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Scope prefix which indicates initiation of a cross-client authentication flow.
|
|
|
|
// See https://developers.google.com/identity/protocols/CrossClientAuth
|
|
|
|
ScopeGoogleCrossClient = "audience:server:client_id:"
|
2016-07-16 04:30:59 +05:30
|
|
|
|
|
|
|
// ScopeGroups indicates that groups should be added to the ID Token.
|
|
|
|
ScopeGroups = "groups"
|
2016-06-03 01:35:18 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
type Scopes []string
|
|
|
|
|
|
|
|
func (s Scopes) OfflineAccess() bool {
|
|
|
|
return s.HasScope("offline_access")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Scopes) HasScope(scope string) bool {
|
|
|
|
for _, curScope := range s {
|
|
|
|
if curScope == scope {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s Scopes) CrossClientIDs() []string {
|
|
|
|
clients := []string{}
|
|
|
|
for _, scope := range s {
|
|
|
|
if strings.HasPrefix(scope, ScopeGoogleCrossClient) {
|
|
|
|
clients = append(clients, scope[len(ScopeGoogleCrossClient):])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return clients
|
|
|
|
}
|
2016-06-10 04:26:37 +05:30
|
|
|
|
|
|
|
func (s Scopes) Contains(other Scopes) bool {
|
|
|
|
rScopes := map[string]struct{}{}
|
|
|
|
for _, scope := range s {
|
|
|
|
rScopes[scope] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, scope := range other {
|
|
|
|
if _, ok := rScopes[scope]; !ok {
|
2016-06-24 20:59:45 +05:30
|
|
|
if scope == "" {
|
|
|
|
continue
|
|
|
|
}
|
2016-06-10 04:26:37 +05:30
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|