---
schema_version: "1"
id: 0947348b03766790207002e72b570b66e8fdc0d95f594329737243a4998d48c7
title: JavaScript Examples for Headless Identity APIs
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/security/headless-identity-impl-guide/guides/headless-identity/headless-identity-javascript.md
canonical_url: https://developer.salesforce.com/docs/platform/headless-identity-impl-guide/guide/headless-identity-javascript.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 840a4fcefa7a641f9bb8010b893b7d9c5a9067241cc2d73484737af279e28b4d
products:
  - Headless Identity Implementation Guide
  - Security
---

# JavaScript Examples for Headless Identity APIs

Postman is great for testing and learning how to set up headless identity flows, but it doesn’t show you how your app can interact with Headless Identity APIs. Use these high-level JavaScript examples to understand how your app can call these APIs in a real-world implementation. Like the rest of this guide, the examples here apply to single-page apps, also known as public clients. These examples don’t show you how to use these flows with client-server apps or private clients.

|Required Editions|
|-----------------|
|Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience|
|Available in: **Enterprise**, **Unlimited**, and **Developer** Editions|

These examples are for demonstration only and aren’t meant to be used in production. Always test code before deploying it to a production environment.

Unlike the Postman examples, these examples use the Proof Key for Code Exchange (PKCE) extension, which improves security. We strongly recommend that you always use PKCE when configuring these flows with public clients.

The examples present a simplified overview of each headless flow for public clients. For in-depth descriptions of the flows for both public and private clients, see these resources in Salesforce Help.

-   [Headless Identity APIs for Customers and Partners](https://help.salesforce.com/s/articleView?id=xcloud.headless_identity_customers_overview.htm&type=5)
-   [Authorization Code and Credentials Flow for Public Clients](https://help.salesforce.com/s/articleView?id=xcloud.remoteaccess_authcodecreds_singlepageapp.htm&type=5)
-   [Authorization Code and Credentials Flow for Private Clients](https://help.salesforce.com/s/articleView?id=xcloud.remoteaccess_authorization_code_credentials_flow.htm&type=5)
-   [Headless Registration Flow for Public Clients](https://help.salesforce.com/s/articleView?id=xcloud.remoteaccess_headless_registration_public_clients.htm&type=5)
-   [Headless Registration Flow for Private Clients](https://help.salesforce.com/s/articleView?id=xcloud.remoteaccess_headless_registration_private_clients.htm&type=5)
-   [Headless Forgot Password Flow](https://help.salesforce.com/s/articleView?id=xcloud.remoteaccess_headless_forgot_password_flow.htm&type=5)—You can use this resource for public and private clients.

-   **[Headless Login JavaScript Examples](https://developer.salesforce.com/docs/platform/headless-identity-impl-guide/guide/headless-identity-javascript-login.md)**  


    Use these high-level examples to understand how to implement headless login for a single-page app.

-   **[Headless Registration JavaScript Examples](https://developer.salesforce.com/docs/platform/headless-identity-impl-guide/guide/headless-identity-registration-javascript.md)**  


    Use these high-level examples to understand how to implement headless registration for a single-page app.

-   **[Headless Forgot Password JavaScript Examples](https://developer.salesforce.com/docs/platform/headless-identity-impl-guide/guide/headless-identity-javascript-forgotpassword.md)**  


    Use these high-level examples to understand how to implement the Headless Forgot Password Flow for a single-page app.

-   **[Building a Native Single Sign-On Experience JavaScript Examples](https://developer.salesforce.com/docs/platform/headless-identity-impl-guide/guide/headless-identity-javascript-sso.md)**  


    Use these high-level examples to understand how to create a native single sign-on (SSO) experience for a single-page app. This configuration uses a redirect-based flow to make it seem like your app natively integrates with an SSO provider. It isn’t technically headless, but the user experience is the same as the headless flows.

-   **[Getting User Info JavaScript Examples](https://developer.salesforce.com/docs/platform/headless-identity-impl-guide/guide/headless-identity-javascript-getuserinfo.md)**  


    When you get an access token via headless registration or headless login, you can retrieve user information with a request to the User Info endpoint. Use this example to understand how.


