> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Passkeys

> Implement passkey authentication in Unity.

> [!WARNING]
>
> Passkey registration and authentication only work on native devices (iOS/Android), not in the Unity Editor.

## Register a passkey

```csharp theme={"system"}
await DynamicSDK.Instance.Passkeys.RegisterPasskey();
```

## List passkeys

```csharp theme={"system"}
List<UserPasskey> passkeys = await DynamicSDK.Instance.Passkeys.GetPasskeys();

foreach (var pk in passkeys)
{
    Debug.Log($"Passkey: {pk.Id}, created: {pk.CreatedAt}");
}
```

## Authenticate with passkey (MFA)

```csharp theme={"system"}
var result = await DynamicSDK.Instance.Passkeys.AuthenticatePasskeyMFA(
    new MfaCreateToken { SingleUse = true });

string token = result?.MfaToken ?? result?.Jwt;
```

## Sign in with a passkey from a related domain

Passkeys are bound to the Relying Party ID (RP ID) they were registered under, which is normally your domain. If your users registered passkeys on a different domain, for example a previous domain you are migrating away from, pass that domain as `relatedOriginRpId` so they can keep signing in with their existing passkeys instead of registering new ones.

```csharp theme={"system"}
await DynamicSDK.Instance.Auth.Passkey.SignIn("old.example.com");

// or via the passkeys module
await DynamicSDK.Instance.Passkeys.SignInWithPasskey("old.example.com");

// the same parameter is available on AuthenticatePasskeyMFA
await DynamicSDK.Instance.Passkeys.AuthenticatePasskeyMFA(
    new MfaCreateToken { SingleUse = true },
    relatedOriginRpId: "old.example.com");
```

Two conditions apply:

* `relatedOriginRpId` must be the RP ID the passkey was registered under, as a bare hostname such as `old.example.com`.
* That domain must link the two origins by hosting `https://old.example.com/.well-known/webauthn` with your current domain in its `origins` list:

```json theme={"system"}
{ "origins": ["https://app.example.com"] }
```

This uses the WebAuthn related origins feature. See [Related Origin Requests](https://passkeys.dev/docs/advanced/related-origins/) for the underlying mechanism.

## Delete a passkey

```csharp theme={"system"}
await DynamicSDK.Instance.Passkeys.DeletePasskey(new DeletePasskeyRequest
{
    CredentialId = passkey.CredentialId,
    PasskeyId = passkey.Id,
});
```

## Complete example

```csharp theme={"system"}
using DynamicSDK.Core;
using UnityEngine;
using System.Collections.Generic;

public class PasskeyManager : MonoBehaviour
{
    private List<UserPasskey> _passkeys = new List<UserPasskey>();
    
    public async void RegisterNewPasskey()
    {
        try
        {
            await DynamicSDK.Instance.Passkeys.RegisterPasskey();
            Debug.Log("Passkey registered successfully!");
            
            // Refresh passkey list
            await LoadPasskeys();
        }
        catch (System.Exception ex)
        {
            Debug.LogError($"Passkey registration failed: {ex.Message}");
        }
    }
    
    public async void LoadPasskeys()
    {
        try
        {
            _passkeys = await DynamicSDK.Instance.Passkeys.GetPasskeys();
            
            Debug.Log($"Found {_passkeys.Count} passkey(s):");
            foreach (var pk in _passkeys)
            {
                Debug.Log($"  ID: {pk.Id}");
                Debug.Log($"  Created: {pk.CreatedAt}");
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError($"Failed to load passkeys: {ex.Message}");
        }
    }
    
    public async void AuthenticateWithPasskey()
    {
        try
        {
            var result = await DynamicSDK.Instance.Passkeys.AuthenticatePasskeyMFA(
                new MfaCreateToken { SingleUse = true });
            
            string token = result?.MfaToken ?? result?.Jwt;
            
            if (!string.IsNullOrEmpty(token))
            {
                Debug.Log("Passkey authentication successful!");
            }
        }
        catch (System.Exception ex)
        {
            Debug.LogError($"Passkey authentication failed: {ex.Message}");
        }
    }
    
    public async void DeletePasskey(UserPasskey passkey)
    {
        try
        {
            await DynamicSDK.Instance.Passkeys.DeletePasskey(new DeletePasskeyRequest
            {
                CredentialId = passkey.CredentialId,
                PasskeyId = passkey.Id,
            });
            
            Debug.Log("Passkey deleted successfully!");
            
            // Refresh passkey list
            await LoadPasskeys();
        }
        catch (System.Exception ex)
        {
            Debug.LogError($"Failed to delete passkey: {ex.Message}");
        }
    }
}
```

## Next steps

* [MFA](https://docs.dynamic.xyz/docs/unity/mfa.md) - Multi-factor authentication with TOTP
* [Authentication](https://docs.dynamic.xyz/docs/unity/authentication.md) - Other authentication methods


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.