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

Bump WebAuthN SDKs #260

Merged
merged 1 commit into from
Oct 9, 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
17 changes: 17 additions & 0 deletions dist/b2c/webauthn.js

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

43 changes: 40 additions & 3 deletions lib/b2c/webauthn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { fetchConfig } from "../shared";
import { request } from "../shared";
import { Session } from "./sessions";
import { User } from "./users";
import { User, WebAuthnRegistration } from "./users";

// Request type for `webauthn.authenticate`.
export interface WebAuthnAuthenticateRequest {
Expand Down Expand Up @@ -84,10 +84,11 @@ export interface WebAuthnAuthenticateResponse {

// Request type for `webauthn.authenticateStart`.
export interface WebAuthnAuthenticateStartRequest {
// The `user_id` of an active user the WebAuthn registration should be tied to.
user_id: string;
// The domain for WebAuthn. Defaults to `window.location.hostname`.
domain: string;
// The `user_id` of an active user the WebAuthn registration should be tied to.
user_id?: string;
return_passkey_credential_options?: boolean;
}

// Response type for `webauthn.authenticateStart`.
Expand Down Expand Up @@ -117,6 +118,10 @@ export interface WebAuthnRegisterRequest {
* [navigator.credentials.create()](https://www.w3.org/TR/webauthn-2/#sctn-createCredential).
*/
public_key_credential: string;
session_token?: string;
session_duration_minutes?: number;
session_jwt?: string;
session_custom_claims?: Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any
}

// Response type for `webauthn.register`.
Expand All @@ -130,11 +135,14 @@ export interface WebAuthnRegisterResponse {
user_id: string;
// The unique ID for the WebAuthn registration.
webauthn_registration_id: string;
session_token: string;
session_jwt: string;
/**
* 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.
*/
status_code: number;
session?: Session;
}

// Request type for `webauthn.registerStart`.
Expand All @@ -150,6 +158,7 @@ export interface WebAuthnRegisterStartRequest {
* cross-platform. If no value passed, we assume both values are allowed.
*/
authenticator_type?: string;
return_passkey_credential_options?: boolean;
}

// Response type for `webauthn.registerStart`.
Expand All @@ -170,6 +179,17 @@ export interface WebAuthnRegisterStartResponse {
status_code: number;
}

export interface WebAuthnUpdateRequest {
webauthn_registration_id: string;
name: string;
}

export interface WebAuthnUpdateResponse {
request_id: string;
status_code: number;
webauthn_registration?: WebAuthnRegistration;
}

export class WebAuthn {
private fetchConfig: fetchConfig;

Expand Down Expand Up @@ -283,4 +303,21 @@ export class WebAuthn {
data,
});
}

/**
* @param data {@link WebAuthnUpdateRequest}
* @returns {@link WebAuthnUpdateResponse}
* @async
* @throws A {@link StytchError} on a non-2xx response from the Stytch API
* @throws A {@link RequestError} when the Stytch API cannot be reached
*/
update(data: WebAuthnUpdateRequest): Promise<WebAuthnUpdateResponse> {
return request<WebAuthnUpdateResponse>(this.fetchConfig, {
method: "PUT",
url: `/v1/webauthn/${data.webauthn_registration_id}`,
data: {
name: data.name,
},
});
}
}
30 changes: 28 additions & 2 deletions types/lib/b2c/webauthn.d.ts

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

Loading