This project provides an example framework for building a single-page application (SPA) to externally authenticate users using the Auth0 platform. The example framework uses the PassportJS middleware and Express web application framework. Once a user authenticates through the SPA, you can use your PureWeb project’s ClientID and Client Secret to request credentials for access to the PureWeb platform. You can then use the credentials to submit launch requests and initiate agents on the PureWeb platform.
A launch request prompts the PureWeb platform to initialize a game stream and connect the stream to web browsers. Agents connect to the PureWeb platform to either consume or contribute data.
The environment variables required to configure this example framework are stored in the packages/.env
file.
To configure environment variables:
- Copy the example file provided,
packages/.env-example
, to a newpackages/.env
file. - Add the account configuration for your Auth0 account to the
.env
file; see Set up an Auth0 account. - Add the account configuration for your PureWeb account to the
.env
file; see Set up a PureWeb account.
- Create an Auth0 account.
- Create a regular web application (from the left panel in your account) and go to the Settings tab for your new application.
- In the
.env
file you copied earlier, add or update the values for the following variables with the corresponding values on the Settings tab:
AUTH0_CLIENT_ID
AUTH0_DOMAIN
AUTH0_CLIENT_SECRET
- In the Auth0 Settings tab, set
Allowable Callback URLs
to:http://localhost:3000/callback, http://localhost:8000/callback
- Finally, set
Allowed Logout URLs
to:http://localhost:3000/, http://localhost:8000/
- Sign in to the PureWeb Console.
- Create a trial account if you don't already have one, and upload your project to the PureWeb console.
- Click the cog icon in your project to open the Project Settings page.
- Add or update the value for the
PUREWEB_PROJECT_CLIENT_ID
variable in the.env
file you copied earlier with the Client ID on the Project Settings page. - Add or update the value for the
PUREWEB_PROJECT_CLIENT_SECRET
variable in the.env
file you copied earlier with the Client Secret on the Project Settings page.
- Install the required NPM packages:
yarn install
Note: The required PureWeb library @pureweb/platform-admin-sdk is automatically installed via NPM.
- Run the server:
yarn dev
This builds the code and runs a local development server (at http://localhost:8000).
In a separate terminal window, run the client:
yarn ui
This launches the client in a new browser window (at http://localhost:3000).
You should now be able to create an account and sign in. You can either create an account using an email/password combination, or using Google Single Sign-on (SSO).
Once you successfully log in, click the PureWeb Credentials button to acquire credentials to the PureWeb platform.
To view your user account information from Auth0, click the User Profile button.
The Auth0 and express portions of this example borrow heavily from auth0-blog/wab-portal-express