Download the sample React application
To view a simple example of a React application, clone the Auth JS repository and follow the set up procedure:
Clone the Auth JS repository
Clone the Auth JS repository and navigate to the top-level folder.
Install the dependencies
Install the dependencies in the okta-auth-js
folder:
Add a configuration file
Create and add a configuration file (testenv
) to the okta-auth-js
root folder. The testenv
file contains the configuration values for your Okta app integration. See Create an app integration for details on these values.
Run the sample application
Navigate to the project folder and run the sample application. Click Login and sign in with a user from your Okta org. After a successful authentication, the user's access token appears on the page.
Create a new React app (optional)
If you don't have an existing React app, you can quickly create a new app by using Create React App (opens new window):
Go into your root app directory to view the created files:
Install dependencies
Add the latest version of Okta Auth JS (opens new window) (@okta/okta-auth-js
), the latest version Okta React SDK (opens new window)(@okta/okta-react
), and the react-router-dom
libraries to your React app. Install the dependencies using a package manager in your root app directory:
Note: The sample code in this use case requires react-router-dom
version 5.x. Certain objects used in the sample code don't exist in reactor-router-dom
version 6.x.