Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expose provider under amr in access token #1457

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions internal/models/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,37 @@ func (s *Session) CalculateAALAndAMR(user *User) (aal string, amr []AMREntry, er
}

// makes sure that the AMR claims are always ordered most-recent first
sort.Sort(sort.Reverse(sortAMREntries{

// sort in ascending order
sort.Sort(sortAMREntries{
Array: amr,
}))
})

if len(amr) > 0 && amr[len(amr)-1].Method == SSOSAML.String() {
return aal, amr, nil
}
// initial AMR claim is from sso/saml, we need to add information
// about the provider that was used for the authentication
identities := user.Identities
if len(identities) == 1 && identities[0].IsForSSOProvider() {
amr[len(amr)-1].Provider = strings.TrimPrefix(identities[0].Provider, "sso:")
// now reverse for descending order
_ = sort.Reverse(sortAMREntries{
Array: amr,
})

lastIndex := len(amr) - 1

if lastIndex > -1 && amr[lastIndex].Method == SSOSAML.String() {
// initial AMR claim is from sso/saml, we need to add information
// about the provider that was used for the authentication
identities := user.Identities

if len(identities) == 1 {
identity := identities[0]

if identity.IsForSSOProvider() {
amr[lastIndex].Provider = strings.TrimPrefix(identity.Provider, "sso:")
}
}

// otherwise we can't identify that this user account has only
// one SSO identity, so we are not encoding the provider at
// this time
}
// otherwise we can't identify that this user account has only
// one SSO identity, so we are not encoding the provider at
// this time

return aal, amr, nil
}

Expand Down
Loading