Skip to content

Conversation

Bewinxed
Copy link
Collaborator

@Bewinxed Bewinxed commented Sep 13, 2025

What kind of change does this PR introduce?

Feature improvement / API cleanup

What is the current behavior?

  • The API returns credential_creation_options and credential_request_options as separate fields at the root level, requiring clients to check which is null
  • OpenAPI spec doesn't match actual server output (missing publicKey wrapper that go-webauthn library adds)
  • Field naming inconsistent with W3C spec (web_authn vs standard webauthn)

What is the new behavior?

  1. Challenge response structure changed to discriminated union:
  • Before: Check null fields {credential_creation_options?: ..., credential_request_options?: ...}
  • After: Single typed field {type: "create" | "request", credential_options: {publicKey: ...}}
  1. Verify request structure unified:
  • Before: {creation_response?: ..., assertion_response?: ...}
  • After: {type: "create" | "request", credential_response: ...}
  1. RPOrigins changed from comma-separated string to string array (matches go-webauthn v3 expectations)

Additional context

This makes the PR for the auth-js library easier.

@hf
Copy link
Contributor

hf commented Sep 19, 2025

Tested, works beautifully! Let's merge on Monday.

@hf hf force-pushed the bewinxed/webauthn-support branch from c0231f2 to 551dcd3 Compare September 23, 2025 13:59
@coveralls
Copy link

Pull Request Test Coverage Report for Build 17948586214

Details

  • 13 of 36 (36.11%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.008%) to 67.708%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/api/mfa.go 13 36 36.11%
Files with Coverage Reduction New Missed Lines %
internal/api/mfa.go 2 57.98%
Totals Coverage Status
Change from base Build 17947966352: 0.008%
Covered Lines: 13004
Relevant Lines: 19206

💛 - Coveralls

@hf hf force-pushed the bewinxed/webauthn-support branch from 551dcd3 to ddc2d19 Compare September 24, 2025 13:01
@hf hf merged commit 68cb8d2 into master Sep 24, 2025
5 checks passed
@hf hf deleted the bewinxed/webauthn-support branch September 24, 2025 13:17
hf added a commit to supabase/auth-js that referenced this pull request Sep 24, 2025
## What kind of change does this PR introduce?

**Feature** - This PR introduces YubiKey support for Multi-Factor
Authentication (MFA) via WebAuthn, enabling users to authenticate with
hardware security keys.

## What is the current behavior?

Currently, Supabase Auth JS supports two MFA methods:
  - TOTP (Time-based One-Time Password) authenticators
  - SMS-based verification
 
## What is the new behavior?

This PR adds full WebAuthn support to the authentication library, the
defaults enable yubikey support at the moment, but it allows the user to
override some parameters client-side to use other types of passkey
methods.

The PR adds the 'webauthn' factor type, to `listFactors`, `enroll()`,
`challenge()`, and `verify()`

(De)serialization of the webauthn reponse/credential object is done
behind the scenes via dedicated objects.

it also adds a new `experimental` namespace `.mfa.webauthn` which has a
`.register()` and `.authenticate()` methods, these methods allows
**single click** yubikey 2FA addition with a single function call.

additionally, we have `webauthn.{enroll|challenge|verify}()`, which
abstract away some of the logic surrounding enrollment, interaction with
the verifier, and have defaults for factortype etc.

### Two ways to use the new api:
#### Single Step
```typescript
const { data, error } = await client.mfa.webauthn.register({
				friendlyName: `Security Key ${new Date().toLocaleDateString()}`,
				rpId: window.location.hostname,
				rpOrigins: [window.location.origin]
			}, {
				authenticatorSelection: {
					authenticatorAttachment: 'platform',
					residentKey: 'discouraged',
					userVerification: 'discouraged',
					requireResidentKey: false
				}
			});

			if (error) throw error;

			console.log(data); // <- session
```
#### Multi Step Composition
```typescript
const { enroll, challenge, verify } = new WebAuthnApi(client);
		return enroll({
			friendlyName: params.friendlyName
		})
			.then(async ({ data, error }) => {
				if (!data) {
					throw error;
				}
				console.log(`enrolled factor, id: ${data.id}`, 'success');
				return await challenge({
					factorId: data?.id,
					webauthn: {
						rpId: params.rpId,
						rpOrigins: params.rpOrigins
					},
					signal: undefined
				});
			})
			.then(async ({ data, error }) => {
				if (!data) {
					throw error;
				}
				console.log(`challenged factor, id: ${data.factorId}`, 'success');
				return await verify({
					factorId: data.factorId,
					challengeId: data.challengeId,
					webauthn: {
						rpId: params.rpId,
						rpOrigins: params.rpOrigins,
						type: data.webauthn.type,
						credential_response: data.webauthn.credential_response
					}
				});
			})
			.then(({ data, error }) => {
				if (!data) {
					throw error;
				}
				console.log(`verified factor, id: ${data.access_token}`, 'success');
				return data;
			});
```

## Additional context

While this PR focuses on YubiKey support, the architecture is designed
to accommodate additional authenticator types in future releases
(platform authenticators, passkeys, etc.) without requiring significant
refactoring.

I've added `webauthn.dom.ts` and `webauthn.errors.ts` which attempt to
augment the typescript interfaces for webauthn since they are out of
date and there are some new features that its not aware of yet but are
publicly available in all major browsers.

For all such types, and due to the complexity of the API, I've added
comprehensive jsdocs for each parameter with reference to the w3a spec
for reference on their usage.

in all webauthn related methods, I've added the ability to **override**
any of the parameters we pass by default to the
`credentials.{get|create}()` method for convenience.

This PR is dependent on my previous PR for streamlining types
#1116

and this PR for `auth` supabase/auth#2163

---------

Co-authored-by: Stojan Dimitrovski <[email protected]>
issuedat pushed a commit that referenced this pull request Sep 30, 2025
## What kind of change does this PR introduce?

Feature improvement / API cleanup

## What is the current behavior?

- The API returns credential_creation_options and
credential_request_options as separate fields at the root level,
requiring clients to check which is null
- OpenAPI spec doesn't match actual server output (missing publicKey
wrapper that go-webauthn library adds)
- Field naming inconsistent with W3C spec (web_authn vs standard
webauthn)

## What is the new behavior?

1. Challenge response structure changed to discriminated union:
- Before: Check null fields {credential_creation_options?: ...,
credential_request_options?: ...}
- After: Single typed field {type: "create" | "request",
credential_options: {publicKey: ...}}
2. Verify request structure unified:
- Before: {creation_response?: ..., assertion_response?: ...}
- After: {type: "create" | "request", credential_response: ...}
3. RPOrigins changed from comma-separated string to string array
(matches go-webauthn v3 expectations)

## Additional context

This makes the PR for the auth-js library easier.
mandarini pushed a commit to supabase/supabase-js that referenced this pull request Oct 2, 2025
## What kind of change does this PR introduce?

**Feature** - This PR introduces YubiKey support for Multi-Factor
Authentication (MFA) via WebAuthn, enabling users to authenticate with
hardware security keys.

## What is the current behavior?

Currently, Supabase Auth JS supports two MFA methods:
  - TOTP (Time-based One-Time Password) authenticators
  - SMS-based verification
 
## What is the new behavior?

This PR adds full WebAuthn support to the authentication library, the
defaults enable yubikey support at the moment, but it allows the user to
override some parameters client-side to use other types of passkey
methods.

The PR adds the 'webauthn' factor type, to `listFactors`, `enroll()`,
`challenge()`, and `verify()`

(De)serialization of the webauthn reponse/credential object is done
behind the scenes via dedicated objects.

it also adds a new `experimental` namespace `.mfa.webauthn` which has a
`.register()` and `.authenticate()` methods, these methods allows
**single click** yubikey 2FA addition with a single function call.

additionally, we have `webauthn.{enroll|challenge|verify}()`, which
abstract away some of the logic surrounding enrollment, interaction with
the verifier, and have defaults for factortype etc.

### Two ways to use the new api:
#### Single Step
```typescript
const { data, error } = await client.mfa.webauthn.register({
				friendlyName: `Security Key ${new Date().toLocaleDateString()}`,
				rpId: window.location.hostname,
				rpOrigins: [window.location.origin]
			}, {
				authenticatorSelection: {
					authenticatorAttachment: 'platform',
					residentKey: 'discouraged',
					userVerification: 'discouraged',
					requireResidentKey: false
				}
			});

			if (error) throw error;

			console.log(data); // <- session
```
#### Multi Step Composition
```typescript
const { enroll, challenge, verify } = new WebAuthnApi(client);
		return enroll({
			friendlyName: params.friendlyName
		})
			.then(async ({ data, error }) => {
				if (!data) {
					throw error;
				}
				console.log(`enrolled factor, id: ${data.id}`, 'success');
				return await challenge({
					factorId: data?.id,
					webauthn: {
						rpId: params.rpId,
						rpOrigins: params.rpOrigins
					},
					signal: undefined
				});
			})
			.then(async ({ data, error }) => {
				if (!data) {
					throw error;
				}
				console.log(`challenged factor, id: ${data.factorId}`, 'success');
				return await verify({
					factorId: data.factorId,
					challengeId: data.challengeId,
					webauthn: {
						rpId: params.rpId,
						rpOrigins: params.rpOrigins,
						type: data.webauthn.type,
						credential_response: data.webauthn.credential_response
					}
				});
			})
			.then(({ data, error }) => {
				if (!data) {
					throw error;
				}
				console.log(`verified factor, id: ${data.access_token}`, 'success');
				return data;
			});
```

## Additional context

While this PR focuses on YubiKey support, the architecture is designed
to accommodate additional authenticator types in future releases
(platform authenticators, passkeys, etc.) without requiring significant
refactoring.

I've added `webauthn.dom.ts` and `webauthn.errors.ts` which attempt to
augment the typescript interfaces for webauthn since they are out of
date and there are some new features that its not aware of yet but are
publicly available in all major browsers.

For all such types, and due to the complexity of the API, I've added
comprehensive jsdocs for each parameter with reference to the w3a spec
for reference on their usage.

in all webauthn related methods, I've added the ability to **override**
any of the parameters we pass by default to the
`credentials.{get|create}()` method for convenience.

This PR is dependent on my previous PR for streamlining types
supabase/auth-js#1116

and this PR for `auth` supabase/auth#2163

---------

Co-authored-by: Stojan Dimitrovski <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants