Skip to content

Commit c2bb1ca

Browse files
committed
Support authenticatorAttachment for create/get return values.
This is now supported by Chrome and Safari (15.4).
1 parent 53bece9 commit c2bb1ca

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

src/webauthn-json/basic/api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export async function create(
3535
const credential = (await navigator.credentials.create(
3636
createRequestFromJSON(requestJSON),
3737
)) as PublicKeyCredential;
38+
console.log(credential);
3839
return createResponseToJSON(credential);
3940
}
4041

src/webauthn-json/basic/json.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { Base64urlString } from "../base64url";
22

3+
interface PublicKeyCredentialJSON {
4+
id: string;
5+
type: PublicKeyCredentialType;
6+
rawId: Base64urlString;
7+
// TODO: This field is technically not optional in the spec, but Firefox hasn't implemented it.
8+
authenticatorAttachment?: AuthenticatorAttachment;
9+
}
10+
311
// Intermediate type needed for attaching client outputs to WebAuthn API call
412
// results before converting to JSON.
513

@@ -9,12 +17,14 @@ interface CredPropsAuthenticationExtensionsClientOutputsJSON {
917

1018
interface AuthenticationExtensionsClientOutputsJSON
1119
extends AuthenticationExtensionsClientOutputs {
20+
// TODO: This field is technically not optional in the spec, but Firefox hasn't implemented it.
1221
appidExclude?: boolean;
1322
credProps?: CredPropsAuthenticationExtensionsClientOutputsJSON;
1423
}
1524

1625
export interface PublicKeyCredentialWithClientExtensionResults
1726
extends PublicKeyCredential {
27+
authenticatorAttachment?: string;
1828
clientExtensionResults?: AuthenticationExtensionsClientOutputsJSON;
1929
}
2030

@@ -77,12 +87,12 @@ export interface AuthenticatorAttestationResponseJSON {
7787
clientDataJSON: Base64urlString;
7888
attestationObject: Base64urlString;
7989
transports: string[];
90+
// This field is technically not optional in the spec, but Firefox hasn't implemented it.
91+
authenticatorAttachment?: AuthenticatorAttachment;
8092
}
8193

82-
export interface PublicKeyCredentialWithAttestationJSON {
83-
id: string;
84-
type: PublicKeyCredentialType;
85-
rawId: Base64urlString;
94+
export interface PublicKeyCredentialWithAttestationJSON
95+
extends PublicKeyCredentialJSON {
8696
response: AuthenticatorAttestationResponseJSON;
8797
clientExtensionResults: SimpleClientExtensionResultsJSON;
8898
}
@@ -113,10 +123,8 @@ interface AuthenticatorAssertionResponseJSON {
113123
userHandle: Base64urlString | null;
114124
}
115125

116-
export interface PublicKeyCredentialWithAssertionJSON {
117-
type: PublicKeyCredentialType;
118-
id: string;
119-
rawId: Base64urlString;
126+
export interface PublicKeyCredentialWithAssertionJSON
127+
extends PublicKeyCredentialJSON {
120128
response: AuthenticatorAssertionResponseJSON;
121129
clientExtensionResults: SimpleClientExtensionResultsJSON;
122130
}

src/webauthn-json/basic/schema.ts

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const publicKeyCredentialWithAttestation: Schema = {
5656
type: required(copy),
5757
id: required(copy),
5858
rawId: required(convert),
59+
authenticatorAttachment: optional(copy),
5960
response: required({
6061
clientDataJSON: required(convert),
6162
attestationObject: required(convert),
@@ -91,6 +92,7 @@ export const publicKeyCredentialWithAssertion: Schema = {
9192
type: required(copy),
9293
id: required(copy),
9394
rawId: required(convert),
95+
authenticatorAttachment: optional(copy),
9496
response: required({
9597
clientDataJSON: required(convert),
9698
authenticatorData: required(convert),

src/webauthn-json/webauthn-schema.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe("webauthn schema", () => {
6262
type: "public-key",
6363
id: "URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENT",
6464
rawId: new Uint8Array([1, 2, 3, 4]),
65+
authenticatorAttachment: "cross-platform",
6566
response: {
6667
clientDataJSON: new Uint8Array([9, 10, 11, 12]),
6768
attestationObject: new Uint8Array([13, 14, 15, 16]),
@@ -84,6 +85,7 @@ describe("webauthn schema", () => {
8485
type: "public-key",
8586
id: "URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENT",
8687
rawId: "AQIDBA",
88+
authenticatorAttachment: "cross-platform",
8789
response: {
8890
attestationObject: "DQ4PEA",
8991
clientDataJSON: "CQoLDA",
@@ -103,6 +105,7 @@ describe("webauthn schema", () => {
103105
type: "public-key",
104106
id: "URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENT",
105107
rawId: new Uint8Array([1, 2, 3, 4]),
108+
authenticatorAttachment: "cross-platform",
106109
response: {
107110
clientDataJSON: new Uint8Array([9, 10, 11, 12]),
108111
attestationObject: new Uint8Array([13, 14, 15, 16]),
@@ -124,6 +127,7 @@ describe("webauthn schema", () => {
124127
type: "public-key",
125128
id: "URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENT",
126129
rawId: "AQIDBA",
130+
authenticatorAttachment: "cross-platform",
127131
response: {
128132
attestationObject: "DQ4PEA",
129133
clientDataJSON: "CQoLDA",
@@ -176,6 +180,7 @@ describe("webauthn schema", () => {
176180
type: "public-key",
177181
id: "URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENT",
178182
rawId: new Uint8Array([1, 2, 3, 4]),
183+
authenticatorAttachment: "cross-platform",
179184
response: {
180185
authenticatorData: new Uint8Array([5, 6, 7, 8]),
181186
clientDataJSON: new Uint8Array([9, 10, 11, 12]),
@@ -195,6 +200,7 @@ describe("webauthn schema", () => {
195200
type: "public-key",
196201
id: "URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENTIAL_ID-URL_SAFE_BASE_64_CREDENT",
197202
rawId: "AQIDBA",
203+
authenticatorAttachment: "cross-platform",
198204
response: {
199205
authenticatorData: "BQYHCA",
200206
clientDataJSON: "CQoLDA",

0 commit comments

Comments
 (0)