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

Getting "Type Error" on IOS #375

Open
awolfson1987 opened this issue Feb 5, 2023 · 8 comments
Open

Getting "Type Error" on IOS #375

awolfson1987 opened this issue Feb 5, 2023 · 8 comments

Comments

@awolfson1987
Copy link

awolfson1987 commented Feb 5, 2023

Hi,

I'm trying to work with WebAuthn for the first time. Everything works well on Android and Windows, however on IOS, I'm getting TypeError: Type Error when calling navigator.credentials.create or navigator.credentials.get.

Here is an example screen shot of the publicKey I'm using on create:

image

My JavaScript looks pretty much the same as in your demo code.

Tried with Safari and Chrome, on IOS versions 15.5 and 16.3, on all I get the same error.

Any help would be appreciated.

@awolfson1987 awolfson1987 changed the title Getting "Type Error" when using WebAuthn on IOS Getting "Type Error" on IOS Feb 5, 2023
@Regenhardt
Copy link
Contributor

Same error for both browsers makes sense, since chrome on iOS is actually also Safari in secret.

Can you share the whole error message? Does it say exactly which property has the wrong type?

In case you have the same problem I had when I started:
When you get the options object options, don't use it like credentials.create(options), but wrap it in another object instead:
navigator.credentials.create({ publicKey: options })

@awolfson1987
Copy link
Author

awolfson1987 commented Feb 6, 2023

Same error for both browsers makes sense, since chrome on iOS is actually also Safari in secret.

Can you share the whole error message? Does it say exactly which property has the wrong type?

In case you have the same problem I had when I started: When you get the options object options, don't use it like credentials.create(options), but wrap it in another object instead: navigator.credentials.create({ publicKey: options })

That is all I'm getting in the error.

Already using as object:

try {
        newCredential = await navigator.credentials.create({
            publicKey: makeCredentialOptions
        });
    }
    catch (e) {
        alert(e.toString());
        return;
    }

@Regenhardt
Copy link
Contributor

If e.toString() only gives you this small error message, and you can't debug into this code to look at the whole thing, you could output the whole object:

alert(JSON.stringify(e));

@awolfson1987
Copy link
Author

tried what you suggested, now it only shows {} in the alert.

@awolfson1987
Copy link
Author

awolfson1987 commented Feb 6, 2023

I found the solution, so apparently when calling RequestNewCredential or GetAssertionOptions to create the options (I'm using .NET framework and not .NET core), with the most basic settings, it returns objects for attestation and userVerification, instead of just strings, which fails on IOS. Added 2 lines to overwrite it on JavaScript:

makeCredentialOptions.attestation = "none";

try {
    credential = await navigator.credentials.create({ publicKey: makeCredentialOptions });
}
catch (e) {
    
}
makeAssertionOptions.userVerification = "discouraged";

try {
    credential = await navigator.credentials.get({ publicKey: makeAssertionOptions });
}
catch (e) {
    
}

@Regenhardt
Copy link
Contributor

Doesn't userVerification = "discouraged" mean you don't want to actively request an authentication device from the user though?

@awolfson1987
Copy link
Author

Doesn't userVerification = "discouraged" mean you don't want to actively request an authentication device from the user though?

Thank you for that, I will probably change that, I just wanted to add the solution to the main problem, the value can be changed as preferred.

@Simonl9l
Copy link

@awolfson1987 I've has a lot of success using the simplewebauthn/browser npm package, and seem to work well on all platforms.

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

No branches or pull requests

3 participants