In order to launch this app:
git clone git@github.com:descope-sample-apps/b2b-react-sample-app.git
Copy .env.example to .env and set your Descope project ID. The rest are optional:
REACT_APP_DESCOPE_PROJECT_ID="YOUR PROJECT ID" // Required for Descope authentication
REACT_APP_DESCOPE_SIGN_IN_FLOW_ID="sign-up-or-in" // Optional, if you would like to use a flow other than sign-up-or-in
REACT_APP_DESCOPE_MANAGEMENT_KEY="YOUR MANAGEMENT KEY" // Optional, if you would like to run E2E tests
REACT_APP_DESCOPE_BASE_URL="http://localhost:8000" // Optional, if you would like to use a different base URL (used by the app)
DESCOPE_BASE_URL="http://localhost:8000" // Optional, the same base URL for the API functions in `api/`
You can get your project-id here. You can get this flow-id from the Flows page here.
You can use npm or yarn, but we recommend using yarn. If it isn't already installed on your machine, the instructions on how to do so can be found here. After yarn is installed, run this command:
yarn install
Run this command to start the app:
yarn start
Browse to http://localhost:3000
- pass project id, base url, and flow id as search params in the URL
// You can pass one or more of the following search params
// project: YOUR_PROJECT_ID
// baseUrl: YOUR_BASE_URL
// flow: YOUR_FLOW_ID
http://localhost:3000/?project=YOUR_PROJECT_ID&baseUrl=YOUR_BASE_URL&flow=YOUR_FLOW_ID
- Pass
AuthProviderprops as search params in the URL
// prefix the prop name with `auth-provider.`
// it will convert prop from kebab-case to camelCase
// e.g. `auth-provider.refresh-cookie-name` will be converted to `refreshCookieName`
// e.g. `auth-provider.persist-tokens` will be converted to `persistTokens`
http://localhost:3000/?auth-provider.refresh-cookie-name=DSR1&auth-provider.persist-tokens=false
This app contains a user invitation route that uses a magic link. To use it, go to your project configuration and do the following
- Set the "User Invitation Redirect URL" to a URL with the path of
auth/invitation(e.g.http://localhost:3000/auth/invitation) - Check the Add a "Magic Link token to the invitation link" checkbox, so that the token is sent in the invitation email
To run Cypress E2E tests:
yarn run cypress open
The sign in page shows Google One Tap once the login flow has loaded. One Tap needs your own Google OAuth client (Descope's default Google credentials don't support it).
- In Google Cloud, create an OAuth client of type "Web application":
- Authorized JavaScript origins:
http://localhostandhttp://localhost:3000 - Authorized redirect URIs:
http://localhost:3000andhttps://api.descope.com/v1/oauth/callback
- Authorized JavaScript origins:
- In the Descope console, go to Authentication Methods -> Social Login:
- Set the Trigger Method to "Enable API & SDK" (One Tap is called from the SDK, not from a flow)
- Open Google, select "Use my own account", fill in the client ID and secret, add the
Implicitgrant type and save
One Tap is only shown for the project set in .env. When you pass a different project in the URL (?project=...), One Tap is skipped.
New Google clients can take a few minutes to start working. If One Tap isn't configured, the app keeps working with the regular login flow.
To test Management Widgets or SSO Setup functionality, you'll need to have a user configured with a tenant and the Tenant Admin role assigned.
To learn more please see the Descope Documentation and API reference page.
If you need help you can contact us