Skip to content

Commit

Permalink
add option to use empty namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jdolitsky committed Jan 31, 2020
1 parent 4a2423a commit 9bd9c66
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,21 @@ type (
TokenDecoder *TokenDecoder
AnonymousActions []string
AccessEntryType string
DefaultNamespace string
}

// BasicAuthAuthorizerOptions is TODO
AuthorizerOptions struct {
Realm string
Service string
Username string
Password string
PublicKey []byte
PublicKeyPath string
AnonymousActions []string
AccessEntryType string
Realm string
Service string
Username string
Password string
PublicKey []byte
PublicKeyPath string
AnonymousActions []string
AccessEntryType string
DefaultNamespace string
EmptyDefaultNamespace bool
}

// Permission is TODO
Expand All @@ -81,6 +84,20 @@ func NewAuthorizer(opts *AuthorizerOptions) (*Authorizer, error) {
authorizer.AccessEntryType = opts.AccessEntryType
}

if opts.EmptyDefaultNamespace {
authorizer.DefaultNamespace = ""
} else if opts.DefaultNamespace != "" {
authorizer.DefaultNamespace = opts.DefaultNamespace
} else {
authorizer.DefaultNamespace = DefaultNamespace
}

if opts.AccessEntryType == "" {
authorizer.AccessEntryType = AccessEntryType
} else {
authorizer.AccessEntryType = opts.AccessEntryType
}

if opts.Username != "" && opts.Password != "" {

// Basic
Expand Down Expand Up @@ -178,7 +195,7 @@ func (authorizer *Authorizer) authorizeBearerAuth(authHeader string, action stri

if !allowed {
if namespace == "" {
namespace = DefaultNamespace
namespace = authorizer.DefaultNamespace
}
wwwAuthenticateHeader = fmt.Sprintf("Bearer realm=\"%s\",service=\"%s\",scope=\"%s:%s:%s\"",
authorizer.Realm, authorizer.Service, authorizer.AccessEntryType, namespace, action)
Expand Down

0 comments on commit 9bd9c66

Please sign in to comment.