2022-03-03 11:20:43 +00:00
|
|
|
package handlers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
|
2022-03-03 23:46:38 +00:00
|
|
|
"github.com/go-webauthn/webauthn/protocol"
|
|
|
|
"github.com/go-webauthn/webauthn/webauthn"
|
2022-03-03 11:20:43 +00:00
|
|
|
|
|
|
|
"github.com/authelia/authelia/v4/internal/middlewares"
|
2022-03-06 05:47:40 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/model"
|
2022-03-03 11:20:43 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/session"
|
|
|
|
)
|
|
|
|
|
2022-03-06 05:47:40 +00:00
|
|
|
func getWebAuthnUser(ctx *middlewares.AutheliaCtx, userSession session.UserSession) (user *model.WebauthnUser, err error) {
|
|
|
|
user = &model.WebauthnUser{
|
2022-03-03 11:20:43 +00:00
|
|
|
Username: userSession.Username,
|
|
|
|
DisplayName: userSession.DisplayName,
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.DisplayName == "" {
|
|
|
|
user.DisplayName = user.Username
|
|
|
|
}
|
|
|
|
|
|
|
|
if user.Devices, err = ctx.Providers.StorageProvider.LoadWebauthnDevicesByUsername(ctx, userSession.Username); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return user, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func newWebauthn(ctx *middlewares.AutheliaCtx) (w *webauthn.WebAuthn, err error) {
|
|
|
|
var (
|
|
|
|
u *url.URL
|
|
|
|
)
|
|
|
|
|
|
|
|
if u, err = ctx.GetOriginalURL(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rpID := u.Hostname()
|
|
|
|
origin := fmt.Sprintf("%s://%s", u.Scheme, u.Host)
|
|
|
|
|
|
|
|
config := &webauthn.Config{
|
|
|
|
RPDisplayName: ctx.Configuration.Webauthn.DisplayName,
|
|
|
|
RPID: rpID,
|
|
|
|
RPOrigin: origin,
|
|
|
|
RPIcon: "",
|
|
|
|
|
|
|
|
AttestationPreference: ctx.Configuration.Webauthn.ConveyancePreference,
|
|
|
|
AuthenticatorSelection: protocol.AuthenticatorSelection{
|
|
|
|
AuthenticatorAttachment: protocol.CrossPlatform,
|
|
|
|
UserVerification: ctx.Configuration.Webauthn.UserVerification,
|
2022-03-03 23:46:38 +00:00
|
|
|
RequireResidentKey: protocol.ResidentKeyNotRequired(),
|
2022-03-03 11:20:43 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
Timeout: int(ctx.Configuration.Webauthn.Timeout.Milliseconds()),
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Logger.Tracef("Creating new Webauthn RP instance with ID %s and Origin %s", config.RPID, config.RPOrigin)
|
|
|
|
|
|
|
|
return webauthn.New(config)
|
|
|
|
}
|