Skip to content

Commit

Permalink
Make origin accept a function.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderson1993 committed Oct 6, 2023
1 parent 5dfb341 commit c71dc75
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remix-auth-webauthn",
"version": "0.0.8",
"version": "0.0.10",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"author": "Alex Anderson",
Expand Down
2 changes: 1 addition & 1 deletion src/handleFormSubmit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function handleFormSubmit(
}

const target = event.currentTarget;
type = event.nativeEvent.submitter.value || target.type.value || type;
type = event?.nativeEvent?.submitter?.value || target.type?.value || type;
event.preventDefault();

const responseValue =
Expand Down
14 changes: 11 additions & 3 deletions src/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ export class WebAuthnStrategy<User> extends Strategy<

rpName: string | ((request: Request) => Promise<string> | string);
rpID: string | ((request: Request) => Promise<string> | string);
origin: string | string[];
origin:
| string
| string[]
| ((request: Request) => Promise<string | string[]> | string | string[]);
getUserAuthenticators: (
user: User | null
) => Promise<WebAuthnAuthenticator[]> | WebAuthnAuthenticator[];
Expand Down Expand Up @@ -177,6 +180,11 @@ export class WebAuthnStrategy<User> extends Strategy<
: this.rpID,
};

const origin =
typeof this.origin === "function"
? await this.origin(request)
: this.origin;

if (request.method === "GET") {
let authenticators: WebAuthnAuthenticator[] = [];
let userDetails: UserDetails | null = null;
Expand Down Expand Up @@ -252,7 +260,7 @@ export class WebAuthnStrategy<User> extends Strategy<
const verification = await verifyRegistrationResponse({
response: data as RegistrationResponseJSON,
expectedChallenge,
expectedOrigin: this.origin,
expectedOrigin: origin,
expectedRPID: rp.id,
});

Expand Down Expand Up @@ -293,7 +301,7 @@ export class WebAuthnStrategy<User> extends Strategy<
const verification = await verifyAuthenticationResponse({
response: authenticationData,
expectedChallenge,
expectedOrigin: this.origin,
expectedOrigin: origin,
expectedRPID: rp.id,
authenticator: {
...authenticator,
Expand Down

0 comments on commit c71dc75

Please sign in to comment.