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

# Public Client Integration

> Create provisional accounts directly from the client when you don't have a backend server.

## Authentication for Public Clients

> [!WARNING]
>
> This method requires enabling **Public Client** for your app. Most games will not want to ship with this enabled. [Learn more](https://docs.discord.com/developers/discord-social-sdk/core-concepts/oauth2-scopes.md#oauth2-client-types)

> [!WARNING]
>
> Use Public Client Integration only if you don't have a server-authoritative backend and therefore require a Public Client for authentication.

If you have `Public Client` enabled on your Discord app, you can use the following code to authenticate your players with the external provider directly from the client — no backend required. Before using this method, you must [configure your identity provider](https://docs.discord.com/developers/discord-social-sdk/development-guides/provisional-accounts/identity-providers.md) in the Developer Portal.

```cpp theme={"system"}
// filepath: your_game/auth_manager.cpp
void AuthenticateUser(std::shared_ptr<discordpp::Client> client) {
    // Get your external auth token (Steam, OIDC, etc.)
    std::string externalToken = GetExternalAuthToken();

    // Get provisional token from Discord
    client->GetProvisionalToken(DISCORD_APPLICATION_ID,
        discordpp::AuthenticationExternalAuthType::OIDC,
        externalToken,
        [client](discordpp::ClientResult result, std::string accessToken, std::string refreshToken, discordpp::AuthorizationTokenType tokenType, int32_t expiresIn, std::string scope) {
        if (result.Successful()) {
            std::cout << "🔓 Provisional token received! Establishing connection...\n";
            client->UpdateToken(discordpp::AuthorizationTokenType::Bearer, accessToken, [client](discordpp::ClientResult result) {
                client->Connect();
            });
        } else {
            std::cerr << "❌ Provisional token request failed: " << result.Error() << std::endl;
        }
    });
}
```

> [!WARNING]
>
> Tokens issued to a Public Client through \[`Client::GetProvisionalToken`] expire after **1 hour**, rather than the 7 days of a server-issued token. Use \[`Client::SetTokenExpirationCallback`] to request a fresh token before it expires — see [Refreshing Access Tokens](https://docs.discord.com/developers/discord-social-sdk/development-guides/provisional-accounts/managing-accounts.md#refreshing-access-tokens).

### How the Flow Works

```mermaid theme={"system"}
sequenceDiagram
    autonumber
    actor P as Player
    participant Prov as External Provider<br/>(OIDC, Steam, EOS)
    participant C as Game Client (SDK)
    participant D as Discord

    P->>Prov: Authenticate
    Prov-->>C: External auth token
    C->>D: GetProvisionalToken(app_id, auth_type, external_token)
    alt No account / provisional account exists
        D-->>C: Access token
        C->>D: UpdateToken() → Connect()
    else Full Discord account exists
        D-->>C: Error (use OAuth2 flow)
    end
```

Once authentication is complete, you can use the access token as you would a full Discord user's access token. See [Managing Provisional Accounts](https://docs.discord.com/developers/discord-social-sdk/development-guides/provisional-accounts/managing-accounts.md) for token refresh, storage, and display names.

## Error Handling

Common error codes and solutions when creating a provisional account:

| Code | Meaning | Solution |
| - | - | - |
| 530000 | Application not configured | Contact Discord support to enable provisional accounts for your application |
| 530001 | Expired ID token | Request a new token from your identity provider |
| 530004 | Token too old | Request a new token (tokens over 1 week old are rejected) |
| 530006 | Username generation failed | Retry the operation (temporary error) |
| 530007 | Invalid client secret | Verify or regenerate your client secret in the Developer Portal |
| 530010 | User account non-provisional | User already linked to Discord account - use standard OAuth2 flow |

If you are using OIDC, you may encounter more specific errors:

| Code | Meaning | Solution |
| - | - | - |
| 530002 | Invalid issuer | Verify the `iss` claim in your ID token exactly matches the issuer URL in your OIDC configuration |
| 530003 | Invalid audience | Verify the `aud` claim in your ID token includes the client ID in your OIDC configuration |
| 530008 | OIDC configuration not found | Verify your issuer URL is correct, accessible over HTTPS, and serves a valid discovery document without HTTP redirects |
| 530009 | OIDC JWKS not found | Verify your JWKS endpoint is accessible over HTTPS without HTTP redirects |
| 530020 | Invalid OIDC JWT token | Verify your ID token is properly signed and uses a supported algorithm |
| 530027 | Missing `kid` header | Ensure your ID token includes a `kid` (Key ID) header in the JWT header identifying the signing key |

***

## Next Steps

> [card] [Managing Provisional Accounts](https://docs.discord.com/developers/discord-social-sdk/development-guides/provisional-accounts/managing-accounts.md)
>
> Refresh access tokens and set display names.

> [card] [Merging Accounts](https://docs.discord.com/developers/discord-social-sdk/development-guides/provisional-accounts/merging-accounts.md)
>
> Merge a provisional account into a full Discord account.

> [card] [Unmerging Accounts](https://docs.discord.com/developers/discord-social-sdk/development-guides/provisional-accounts/unmerging-accounts.md)
>
> Sever the link between a Discord account and a provisional account.

Need help? Join the [Discord Developers Server](https://discord.gg/discord-developers) and share questions in the `#social-sdk-dev-help` channel for support from the community.

If you encounter a bug while working with the Social SDK, please report it here:  [https://dis.gd/social-sdk-bug-report](https://dis.gd/social-sdk-bug-report)

***

## Change Log

| Date | Changes |
| - | - |
| October 5, 2026 | Note the 1 hour lifetime of Public Client tokens |
| July 14, 2026 | Split the provisional accounts guide into its own section |
| March 17, 2025 | Initial release |

[`Client::GetProvisionalToken`]: https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1Client.html#a8003130b6c46e54ac68442483bf0480c

[`Client::SetTokenExpirationCallback`]: https://discord.com/developers/docs/social-sdk/classdiscordpp_1_1Client.html#aab5bfc76809ea22e79f2f7a067ac4519
