Skip to content

API compatibility with navigator.credentials.get/create #34

@kzlar

Description

@kzlar

Hi @peterferguson,

Appreciate the work on this plugin!

I'm using https://github.com/better-auth/better-auth/ (which uses https://github.com/MasterKale/SimpleWebAuthn under the hood) to facilitate passkey usage on my website, and wanted to add the same functionality to my expo app, and so I was very happy to find this repo 🥳

I'm still in the PoC phase so I tried the following setup:

import * as ReactNativePasskeys from 'react-native-passkeys'
// Pass SimpleWebAuthn checks
globalThis.PublicKeyCredential = () => {}
// Initialize global credentials API
navigator.credentials = {
  get: ReactNativePasskeys.get,
  create: ReactNativePasskeys.create
}

This succeeds in the basic task of letting my use existing better-auth/simplewebauthn code along with this plugin, however upon actually trying to create a passkey, the app crashes.
From what I can tell, the reason is that the API options don't exactly match up. I looked up the types and it's pretty clear:

export declare function create(request: Omit<PublicKeyCredentialCreationOptionsJSON, 'extensions'> & {
    extensions?: {
        largeBlob?: AuthenticationExtensionsLargeBlobInputs;
    };
} & Pick<CredentialCreationOptions, 'signal'>): Promise<RegistrationResponseJSON | null>;

It seems like this plugin "flattens" CredentialCreationOptions.publicKey.
Is there a particular reason for it? Are you open to amending the API to conform to the web standard?

P.S. the actual crash comes from

let crossPlatformCredentialProvider = ASAuthorizationSecurityKeyPublicKeyCredentialProvider(relyingPartyIdentifier: request.rp.id!)
but in general some argument validation is probably not a bad idea, if you'd be open to it I can try to add a PR to add it.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions