Skip to content

Commit

Permalink
providers: Use authd defined auth modes for CurrentAuthenticationMode…
Browse files Browse the repository at this point in the history
…sOffered
  • Loading branch information
3v1n0 committed Feb 11, 2025
1 parent 1f11e6b commit 96afa8a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
15 changes: 9 additions & 6 deletions internal/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (b *Broker) GetAuthenticationModes(sessionID string, supportedUILayouts []m

var authModes []auth.Mode
for _, id := range availableModes {
authModes = append(authModes, auth.NewMode(id, supportedAuthModes[id]))
authModes = append(authModes, supportedAuthModes[id])
}

if len(authModes) == 0 {
Expand All @@ -282,8 +282,8 @@ func (b *Broker) GetAuthenticationModes(sessionID string, supportedUILayouts []m
return auth.NewModeMaps(authModes)
}

func (b *Broker) supportedAuthModesFromLayout(supportedUILayouts []layouts.UILayout) (supportedModes map[string]string) {
supportedModes = make(map[string]string)
func (b *Broker) supportedAuthModesFromLayout(supportedUILayouts []layouts.UILayout) (supportedModes map[string]auth.Mode) {
supportedModes = make(map[string]auth.Mode)
for _, layout := range supportedUILayouts {
kind, supportedEntries := layouts.ParseItems(layout.GetEntry())
if kind != layouts.Optional && kind != layouts.Required {
Expand All @@ -299,16 +299,19 @@ func (b *Broker) supportedAuthModesFromLayout(supportedUILayouts []layouts.UILay
if rc := layout.RendersQrcode; rc != nil && !*rc {
deviceAuthID = authmodes.Device
}
supportedModes[deviceAuthID] = "Device Authentication"
supportedModes[deviceAuthID] = auth.NewMode(deviceAuthID,
"Device Authentication")

case layouts.Form:
if slices.Contains(supportedEntries, entries.CharsPassword) {
supportedModes[authmodes.Password] = "Local Password Authentication"
supportedModes[authmodes.Password] = auth.NewMode(authmodes.Password,
"Local Password Authentication")
}

case layouts.NewPassword:
if slices.Contains(supportedEntries, entries.CharsPassword) {
supportedModes[authmodes.NewPassword] = "Define your local password"
supportedModes[authmodes.NewPassword] = auth.NewMode(authmodes.NewPassword,
"Define your local password")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/providers/noprovider/noprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (p NoProvider) AuthOptions() []oauth2.AuthCodeOption {
// CurrentAuthenticationModesOffered returns the generic authentication modes supported by the provider.
func (p NoProvider) CurrentAuthenticationModesOffered(
sessionMode string,
supportedAuthModes map[string]string,
supportedAuthModes map[string]auth.Mode,
tokenExists bool,
providerReachable bool,
endpoints map[string]struct{},
Expand Down
3 changes: 2 additions & 1 deletion internal/providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/coreos/go-oidc/v3/oidc"
"github.com/ubuntu/authd-oidc-brokers/internal/providers/info"
"github.com/ubuntu/authd/brokers/auth"
"golang.org/x/oauth2"
)

Expand All @@ -16,7 +17,7 @@ type Provider interface {
CheckTokenScopes(token *oauth2.Token) error
CurrentAuthenticationModesOffered(
sessionMode string,
supportedAuthModes map[string]string,
supportedAuthModes map[string]auth.Mode,
tokenExists bool,
providerReachable bool,
endpoints map[string]struct{},
Expand Down

0 comments on commit 96afa8a

Please sign in to comment.