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

feat: webauthn: support discoverable credentials #601

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
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
12 changes: 0 additions & 12 deletions go/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1043,18 +1043,6 @@ components:
example: [email protected]
format: email
type: string
userHandle:
description: User identifier for webauthn
example: 2c35b6f3-c4b9-48e3-978a-d4d0f1d42e24
pattern: \b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b
type: string
x-go-type-import:
name: uuid
path: "github.com/google/uuid"
x-go-type: uuid.UUID
oneOf:
- required: [email]
- required: [userHandle]

SignUpWebauthnRequest:
type: object
Expand Down
133 changes: 66 additions & 67 deletions go/api/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

122 changes: 0 additions & 122 deletions go/api/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 20 additions & 13 deletions go/controller/post_signin_webauthn.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ func webauthnCredentials(
return creds, nil
}

func (ctrl *Controller) postSigninWebauthnDiscoverableLogin( //nolint:ireturn
logger *slog.Logger,
) (api.PostSigninWebauthnResponseObject, error) {
creation, apiErr := ctrl.Webauthn.BeginDiscoverableLogin(logger)
if apiErr != nil {
return ctrl.sendError(apiErr), nil
}

return api.PostSigninWebauthn200JSONResponse(creation.Response), nil
}

func (ctrl *Controller) PostSigninWebauthn( //nolint:ireturn
ctx context.Context,
request api.PostSigninWebauthnRequestObject,
Expand All @@ -49,16 +60,11 @@ func (ctrl *Controller) PostSigninWebauthn( //nolint:ireturn
return ctrl.sendError(ErrDisabledEndpoint), nil
}

var user sql.AuthUser
var apiErr *APIError
switch {
case request.Body.UserHandle != nil:
user, apiErr = ctrl.wf.GetUser(ctx, *request.Body.UserHandle, logger)
case request.Body.Email != nil:
user, apiErr = ctrl.wf.GetUserByEmail(ctx, string(*request.Body.Email), logger)
default:
return ctrl.sendError(ErrInvalidRequest), nil
if request.Body.Email == nil {
return ctrl.postSigninWebauthnDiscoverableLogin(logger)
}

user, apiErr := ctrl.wf.GetUserByEmail(ctx, string(*request.Body.Email), logger)
if apiErr != nil {
return ctrl.sendError(apiErr), nil
}
Expand All @@ -74,10 +80,11 @@ func (ctrl *Controller) PostSigninWebauthn( //nolint:ireturn
}

waUser := WebauthnUser{
ID: user.ID,
Name: user.DisplayName,
Email: user.Email.String,
Credentials: creds,
ID: user.ID,
Name: user.DisplayName,
Email: user.Email.String,
Credentials: creds,
Discoverable: false,
}

creation, apiErr := ctrl.Webauthn.BeginLogin(waUser, logger)
Expand Down
Loading
Loading