summaryrefslogtreecommitdiff
path: root/internal/authorization/util.go
diff options
context:
space:
mode:
authorJames Elliott <james-d-elliott@users.noreply.github.com>2024-03-05 20:11:16 +1100
committerGitHub <noreply@github.com>2024-03-05 19:11:16 +1000
commitfb50f1a70c66d96391a3e9cae5721c9c78c75d8d (patch)
treef49313d4452fbfb8072210c30d93602b81739a75 /internal/authorization/util.go
parentc70c83f74593c1ed75c2195e2dba74a5dfcd30cc (diff)
feat: oauth2 authorization bearer (#6774)
This implements user authorization utilizing the OAuth 2.0 bearer scheme (i.e. RFC6750) for both the authorize code grant and client credentials grant. This effectively allows application "passwords" when used with the client credentials grant. Closes #2023, Closes #188. Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
Diffstat (limited to 'internal/authorization/util.go')
-rw-r--r--internal/authorization/util.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/internal/authorization/util.go b/internal/authorization/util.go
index 04ce482e4..e8b5990ae 100644
--- a/internal/authorization/util.go
+++ b/internal/authorization/util.go
@@ -42,9 +42,10 @@ func (l Level) String() string {
}
func stringSliceToRegexpSlice(strings []string) (regexps []regexp.Regexp, err error) {
+ var pattern *regexp.Regexp
+
for _, str := range strings {
- pattern, err := regexp.Compile(str)
- if err != nil {
+ if pattern, err = regexp.Compile(str); err != nil {
return nil, err
}
@@ -56,17 +57,23 @@ func stringSliceToRegexpSlice(strings []string) (regexps []regexp.Regexp, err er
func schemaSubjectToACLSubject(subjectRule string) (subject SubjectMatcher) {
if strings.HasPrefix(subjectRule, prefixUser) {
- user := strings.Trim(subjectRule[len(prefixUser):], " ")
+ user := strings.Trim(subjectRule[lenPrefixUser:], " ")
return AccessControlUser{Name: user}
}
if strings.HasPrefix(subjectRule, prefixGroup) {
- group := strings.Trim(subjectRule[len(prefixGroup):], " ")
+ group := strings.Trim(subjectRule[lenPrefixGroup:], " ")
return AccessControlGroup{Name: group}
}
+ if strings.HasPrefix(subjectRule, prefixOAuth2Client) {
+ clientID := strings.Trim(subjectRule[lenPrefixOAuth2Client:], " ")
+
+ return AccessControlClient{Provider: "OAuth2", ID: clientID}
+ }
+
return nil
}