https://github.com/oktadev/okta-react-user-auth-example
React and User Authentication
https://github.com/oktadev/okta-react-user-auth-example
authentication javascript react reactjs
Last synced: 7 months ago
JSON representation
React and User Authentication
- Host: GitHub
- URL: https://github.com/oktadev/okta-react-user-auth-example
- Owner: oktadev
- License: apache-2.0
- Created: 2019-02-27T15:07:06.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T14:03:54.000Z (about 3 years ago)
- Last Synced: 2025-06-03T03:47:47.373Z (8 months ago)
- Topics: authentication, javascript, react, reactjs
- Language: JavaScript
- Homepage:
- Size: 2.8 MB
- Stars: 7
- Watchers: 6
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Example App Using React and Okta
This example app shows how to create a simple web app using React and Okta for authentication. This looks up Chuck Norris jokes, replacing the name Chuck Norris with the user's own name if they are signed in.
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
**Prerequisites**: [Node.js](https://nodejs.org/en/) and [Yarn](https://yarnpkg.com/lang/en/).
## Getting Started
To install this example application, run the following commands:
```bash
git clone git@github.com:oktadeveloper/okta-react-user-auth-example.git
cd okta-react-user-auth-example
yarn
```
This will install a local copy of the project. You will need to set up some environment variables before the app will run properly.
To integrate Okta's Identity Platform for user authentication, you'll first need to:
* [Sign up for a free Okta Developer account](https://www.okta.com/developer/signup/)
* You will get a URL similar to `https://dev-123456.oktapreview.com`.
* Save this URL for later
* You will also use this URL to login to your Okta account
You will need to create an application in Okta:
* Log in to your Okta account, then navigate to **Applications** and click the **Add Application** button
* Select **Single-Page App** and click **Next**
* Give your application a name (e.g. "My React App")
* Change the **Base URI** to `http://localhost:3000/` and the **Login redirect URI** to `http://localhost:3000/implicit/callback`, then click **Done**
* Save your **Client ID** for later
Your Okta application should have settings similar to the following:

Now create a file called `.env.local` in the project root and add the following variables, replacing the values with your own from the previous steps.
**.env.local**
```bash
REACT_APP_OKTA_CLIENT_ID={yourClientId}
REACT_APP_OKTA_ORG_URL=https://{yourOktaOrgUrl}
```
Now you can run the React frontend with the following command:
```bash
yarn start
```
## Links
This example uses the [Okta React SDK](https://github.com/okta/okta-oidc-js/tree/master/packages/okta-react).
## Help
Please [raise an issue](https://github.com/oktadeveloper/okta-react-user-auth-example/issues) if you find a problem with the example application, or visit our [Okta Developer Forums](https://devforum.okta.com/). You can also email [developers@okta.com](mailto:developers@okta.com) if would like to create a support ticket.
## License
Apache 2.0, see [LICENSE](LICENSE).