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

Add WebAuthnUpdate #148

Merged
merged 4 commits into from
Nov 1, 2023
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
2 changes: 1 addition & 1 deletion stytch/config/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package config

const APIVersion = "11.4.1"
const APIVersion = "11.4.2"
1 change: 1 addition & 0 deletions stytch/consumer/users/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ type WebAuthnRegistration struct {
UserAgent string `json:"user_agent,omitempty"`
Verified bool `json:"verified,omitempty"`
AuthenticatorType string `json:"authenticator_type,omitempty"`
Name string `json:"name,omitempty"`
}

// CreateResponse: Response type for `Users.Create`.
Expand Down
25 changes: 25 additions & 0 deletions stytch/consumer/webauthn.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,28 @@ func (c *WebAuthnClient) AuthenticateWithClaims(

return &retVal, err
}

func (c *WebAuthnClient) Update(
ctx context.Context,
body *webauthn.UpdateParams,
) (*webauthn.UpdateResponse, error) {
var jsonBody []byte
var err error
if body != nil {
jsonBody, err = json.Marshal(body)
if err != nil {
return nil, stytcherror.NewClientLibraryError("error marshaling request body")
}
}

var retVal webauthn.UpdateResponse
err = c.C.NewRequest(
ctx,
"PUT",
fmt.Sprintf("/v1/webauthn/%s", body.WebAuthnRegistrationID),
nil,
jsonBody,
&retVal,
)
return &retVal, err
}
31 changes: 25 additions & 6 deletions stytch/consumer/webauthn/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ type AuthenticateParams struct {

// AuthenticateStartParams: Request type for `WebAuthn.AuthenticateStart`.
type AuthenticateStartParams struct {
// UserID: The `user_id` of an active user the WebAuthn registration should be tied to.
UserID string `json:"user_id,omitempty"`
// Domain: The domain for WebAuthn. Defaults to `window.location.hostname`.
Domain string `json:"domain,omitempty"`
// UserID: The `user_id` of an active user the WebAuthn registration should be tied to.
UserID string `json:"user_id,omitempty"`
ReturnPasskeyCredentialOptions bool `json:"return_passkey_credential_options,omitempty"`
}

// RegisterParams: Request type for `WebAuthn.Register`.
Expand All @@ -57,7 +58,11 @@ type RegisterParams struct {
UserID string `json:"user_id,omitempty"`
// PublicKeyCredential: The response of the
// [navigator.credentials.create()](https://www.w3.org/TR/webauthn-2/#sctn-createCredential).
PublicKeyCredential string `json:"public_key_credential,omitempty"`
PublicKeyCredential string `json:"public_key_credential,omitempty"`
SessionToken string `json:"session_token,omitempty"`
SessionDurationMinutes int32 `json:"session_duration_minutes,omitempty"`
SessionJWT string `json:"session_jwt,omitempty"`
SessionCustomClaims map[string]any `json:"session_custom_claims,omitempty"`
}

// RegisterStartParams: Request type for `WebAuthn.RegisterStart`.
Expand All @@ -70,7 +75,12 @@ type RegisterStartParams struct {
UserAgent string `json:"user_agent,omitempty"`
// AuthenticatorType: The requested authenticator type of the WebAuthn device. The two valid value are
// platform and cross-platform. If no value passed, we assume both values are allowed.
AuthenticatorType string `json:"authenticator_type,omitempty"`
AuthenticatorType string `json:"authenticator_type,omitempty"`
ReturnPasskeyCredentialOptions bool `json:"return_passkey_credential_options,omitempty"`
}
type UpdateParams struct {
WebAuthnRegistrationID string `json:"webauthn_registration_id,omitempty"`
Name string `json:"name,omitempty"`
}

// AuthenticateResponse: Response type for `WebAuthn.Authenticate`.
Expand Down Expand Up @@ -127,11 +137,15 @@ type RegisterResponse struct {
// UserID: The unique ID of the affected User.
UserID string `json:"user_id,omitempty"`
// WebAuthnRegistrationID: The unique ID for the WebAuthn registration.
WebAuthnRegistrationID string `json:"webauthn_registration_id,omitempty"`
WebAuthnRegistrationID string `json:"webauthn_registration_id,omitempty"`
SessionToken string `json:"session_token,omitempty"`
SessionJWT string `json:"session_jwt,omitempty"`
User users.User `json:"user,omitempty"`
// StatusCode: The HTTP status code of the response. Stytch follows standard HTTP response status code
// patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX
// are server errors.
StatusCode int32 `json:"status_code,omitempty"`
StatusCode int32 `json:"status_code,omitempty"`
Session *sessions.Session `json:"session,omitempty"`
}

// RegisterStartResponse: Response type for `WebAuthn.RegisterStart`.
Expand All @@ -149,3 +163,8 @@ type RegisterStartResponse struct {
// are server errors.
StatusCode int32 `json:"status_code,omitempty"`
}
type UpdateResponse struct {
RequestID string `json:"request_id,omitempty"`
StatusCode int32 `json:"status_code,omitempty"`
WebAuthnRegistration *users.WebAuthnRegistration `json:"webauthn_registration,omitempty"`
}
Loading