-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start using go-oidc-middleware (#302)
* remove claimsClient * add oidcHandler * fix error formatting * update tests to work with middleware * update readme
- Loading branch information
1 parent
fce56e7
commit aecace7
Showing
10 changed files
with
325 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package handlers | ||
|
||
import "fmt" | ||
|
||
// azureClaims contains the claims used by the Azure AD Access Token (v2) | ||
type azureClaims struct { | ||
sub string | ||
username string | ||
objectID string | ||
groups []string | ||
} | ||
|
||
// toAzureClaims converts the raw claims from context.Value() to azureClaims | ||
func toAzureClaims(rawClaims map[string]interface{}) (azureClaims, error) { | ||
rawSub, ok := rawClaims["sub"] | ||
if !ok { | ||
return azureClaims{}, fmt.Errorf("unable to find sub claim") | ||
} | ||
|
||
sub, ok := rawSub.(string) | ||
if !ok { | ||
return azureClaims{}, fmt.Errorf("unable to typecast sub to string: %v", rawSub) | ||
} | ||
|
||
isServicePrincipal := false | ||
rawUsername, ok := rawClaims["preferred_username"] | ||
if !ok { | ||
isServicePrincipal = true | ||
} | ||
|
||
username := "" | ||
if !isServicePrincipal { | ||
username, ok = rawUsername.(string) | ||
if !ok { | ||
return azureClaims{}, fmt.Errorf("unable to typecast preferred_username to string: %v", rawUsername) | ||
} | ||
} | ||
|
||
rawObjectID, ok := rawClaims["oid"] | ||
if !ok { | ||
return azureClaims{}, fmt.Errorf("unable to find oid claim") | ||
} | ||
|
||
objectID, ok := rawObjectID.(string) | ||
if !ok { | ||
return azureClaims{}, fmt.Errorf("unable to typecast oid to string: %v", rawObjectID) | ||
} | ||
|
||
rawGroups := rawClaims["groups"] | ||
groups, ok := rawGroups.([]string) | ||
if !ok { | ||
// if we are unable to typecast, set groups to empty | ||
groups = []string{} | ||
} | ||
|
||
return azureClaims{ | ||
sub: sub, | ||
username: username, | ||
objectID: objectID, | ||
groups: groups, | ||
}, nil | ||
} |
Oops, something went wrong.