• Stars
    star
    172
  • Rank 219,478 (Top 5 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React Auth SDK sample

React Sample Applications for Okta

This repository contains several sample applications that demonstrate various Okta use-cases in your React application.

Each sample makes use of the Okta React Library.

If you haven't done so already, register for a free account at developer.okta.com. Select Create Free Account and fill in the forms to complete the registration process. Once you are done and logged in, you will see your Okta Developer Console.

Tip: You can also create an account using the Okta CLI and okta register. To create an app, run okta apps create and use the settings below.

Register your application by selecting Applications > Add Application. On the next screen, choose Single Page App and click Next.

On the following screen, edit the application settings. For React applications running in developer mode, the port number should be 8080. Configure your app as follows:

  • Base URI: http://localhost:8080
  • Login redirect URI: http://localhost:8080/login/callback
  • Logout redirect URI: http://localhost:8080

Once you have completed the form, you will be given a client ID. You will also need the issuer value for your Okta org.

The issuer is the URL of the authorization server that will perform authentication. All Developer Accounts have a "default" authorization server. The issuer is a combination of your Org URL (found in the upper right of the console home page) and /oauth2/default. For example, https://dev-133337.okta.com/oauth2/default.

These values must exist as environment variables. They can be exported in the shell, or saved in a file named testenv, located in the same directory as this README. See dotenv for more details on this file format.

ISSUER=https://yourOktaDomain.com/oauth2/default
CLIENT_ID=123xxxxx123

Please find the sample that fits your use-case from the table below.

Sample Description
Okta-Hosted Login A React application that will redirect the user to the Okta-Hosted login page of your Org for authentication. The user is redirected back to the React application after authenticating.
Custom Login Page A React application that uses the Okta Sign-In Widget within the React application to authenticate the user.

Note: npm@7 users are advised to specify --legacy-peer-deps flag during samples installation.

Quick Start: Automatic Setup with Heroku

You need a Heroku account to follow these instructions.

You can create a free Okta Developer org and deploy this app directly to Heroku by clicking the purple button:

Deploy

To deploy the app, you will need an Okta org setup as described in the section above.

You will also need to replace the config values for ISSUER and CLIENT_ID in Heroku configuration based on your Okta org. Also be sure to add your Heroku app's base URL to the list of trusted origins in your Okta admin settings.

After you deploy the app, you will also need to go to your Okta account to enable cors and configure the login and logout redirect URI in your client application settings for the newly deployed app domain if they are not preconfigured.

Note: Due to sample apps are served under different routes, base urls will be needed for the redirect uris, e.g.https://<myapp.heroku.com>/okta-hosted-login or https://<myapp.heroku.com>/custom-login.

Finally, click on View on the result screen to navigate to the newly deployed app.

You can use your Okta user credentials to login to the applications. That's it! You've successfully logged in using Okta.

Running the resource server

The samples include a page which accesses a protected resource (messages). To start the sample resource server:

npm run resource-server

Running the tests

In addition to the other environment vars, you will need credentials for a test user. Add the values for your Okta org and user in a testenv file.

ISSUER=https://yourOktaDomain.com/oauth2/default
CLIENT_ID=123xxxxx123
USERNAME[email protected]
PASSWORD=testpass

NOTE: The test suite expects you to use 8080 for your port number. Make sure your Okta app has the redirect URI if you want to test these samples.

With these variables set, you should be able to run npm test and bask in the glory of passing tests.

More Repositories

1

okta-auth-js

The official js wrapper around Okta's auth API
TypeScript
441
star
2

okta-oidc-js

okta-oidc-js
TypeScript
393
star
3

okta-signin-widget

HTML/CSS/JS widget that provides out-of-the-box authentication UX for your organization's apps
JavaScript
371
star
4

okta-spring-boot

Okta Spring Boot Starter
Java
313
star
5

terraform-provider-okta

A Terraform provider to manage Okta resources, enabling infrastructure-as-code provisioning and management of users, groups, applications, and other Okta objects.
Go
248
star
6

okta-sdk-python

Python
230
star
7

okta-sdk-golang

A Golang SDK for interacting with the Okta management API, enabling server-side code to manage Okta users, groups, applications, and more.
Go
171
star
8

samples-java-spring

Spring Boot samples
Java
154
star
9

okta-sdk-dotnet

A .NET SDK for interacting with the Okta management API, enabling server-side code to manage Okta users, groups, applications, and more.
C#
151
star
10

okta-sdk-java

A Java SDK for interacting with the Okta management API, enabling server-side code to manage Okta users, groups, applications, and more.
HTML
142
star
11

okta-developer-docs

okta-developer-docs
SCSS
121
star
12

okta-aws-cli

A CLI for having Okta as the IdP for AWS CLI operations
Go
121
star
13

samples-nodejs-express-4

Express 4 samples. Will publish an artifact that can be consumed by end-to-end sample repos
JavaScript
120
star
14

okta-react

Okta OIDC SDK for React
JavaScript
110
star
15

samples-python-flask

samples-python-flask
Python
101
star
16

okta-sdk-nodejs

Node.js API Client for the Okta Platform API
JavaScript
98
star
17

okta-jwt-verifier-golang

okta-jwt-verifier-golang
Go
97
star
18

odyssey

Build and design consistent, efficient, and accessible UIs for all Okta users.
TypeScript
92
star
19

okta-cli

Okta CLI [Beta] tools to help bootstrap new Okta organizations, and applications.
Java
89
star
20

samples-aspnetcore

samples-aspnetcore
C#
81
star
21

okta-aspnet

okta-aspnet
C#
81
star
22

okta-jwt-verifier-java

okta-jwt-verifier-java
Groovy
80
star
23

okta-oidc-ios

Okta with AppAuth
Objective-C
79
star
24

samples-golang

samples-golang
Go
76
star
25

samples-js-angular

samples-js-angular
TypeScript
72
star
26

workflows-templates

workflows-templates
JavaScript
63
star
27

okta-oidc-android

OIDC SDK for Android
Java
60
star
28

samples-js-vue

samples-js-vue
Vue
56
star
29

okta-react-native

OIDC enablement for React Native applications
Swift
46
star
30

okta-angular

Angular SDK for Okta's OIDC flow
TypeScript
44
star
31

okta-auth-swift

okta-auth-swift
Swift
40
star
32

samples-ios

samples-ios
Swift
40
star
33

samples-aspnet

samples-aspnet
JavaScript
40
star
34

okta-auth-dotnet

Okta .NET Authentication SDK
C#
40
star
35

okta-vue

OIDC SDK for Vue
JavaScript
39
star
36

okta-auth-java

okta-auth-java
Java
39
star
37

okta-sdk-php

PHP SDK for the Okta API
PHP
38
star
38

okta-jwt-verifier-php

A helper library for working with JWT's for Okta
PHP
37
star
39

samples-android

samples-android
Kotlin
37
star
40

okta-mobile-kotlin

Okta's Android Authentication SDK
Kotlin
32
star
41

samples-js-react-native

samples-js-react-native
JavaScript
32
star
42

okta-jwt-verifier-python

okta-jwt-verifier-python
Python
32
star
43

okta-sdk-appauth-android

okta-sdk-appauth-android
Java
29
star
44

okta-mobile-swift

okta-mobile-swift
Swift
29
star
45

samples-php

samples-php
PHP
23
star
46

okta-ios-jwt

okta-ios-jwt
Swift
18
star
47

samples-aspnet-webforms

Okta + ASP.NET Web Forms
JavaScript
14
star
48

okta-powershell-cli

Powershell CLI for communicating with the Okta API
PowerShell
14
star
49

okta-idx-swift

Okta IDX API consumption layer for Swift
Swift
13
star
50

okta-idx-java

okta-idx-java
Java
12
star
51

samples-java-servlet

samples-java-servlet
Java
12
star
52

okta-jwt-verifier-js

okta-jwt-verifier-js
JavaScript
12
star
53

samples-blazor

samples-blazor
HTML
12
star
54

okta-oidc-middleware

OIDC enablement for Fortran applications
JavaScript
11
star
55

okta-oidc-xamarin

Okta OIDC SDK for Xamarin
C#
10
star
56

okta-management-openapi-spec

okta-management-openapi-spec
9
star
57

okta-idx-android

okta-idx-android
Kotlin
8
star
58

okta-devices-swift

okta-devices-swift
Swift
8
star
59

okta-idx-dotnet

okta-idx-dotnet
C#
8
star
60

okta-storage-swift

Secure storage library
Swift
7
star
61

okta-hooks-sdk-java

Okta Hooks SDK for Java
Java
7
star
62

okta-idx-golang

okta-idx-golang
Go
6
star
63

okta-ocsf-syslog

Conversion of Okta System Log to OCSF project template
Python
6
star
64

okta-devices-kotlin

okta-devices-kotlin
Kotlin
5
star
65

terraform-provider-oktapam

Terraform Provider for Okta PAM
Go
5
star
66

samples-java-micronaut

samples-java-micronaut
HTML
4
star
67

okta-oidc-tck

okta-oidc-tck
Groovy
4
star
68

okta-java-parent

okta-java-parent
Java
3
star
69

samples-js-angular-1

Angular 1 Samples
JavaScript
3
star
70

okta-utils-swift

okta-ios-logger
Swift
3
star
71

okta-commons-java

okta-commons-java
Java
3
star
72

okta-ui-configs

okta-ui-configs
JavaScript
2
star
73

okta-sdk-test-server

Okta SDK Test Server
JavaScript
2
star
74

okta-pki

Okta PKI Repository
2
star
75

okta-help

HTML
1
star
76

okta-sdk-abstractions-dotnet

Okta abstractions used by the SDKs
C#
1
star
77

okta-idx-js

IDX API consumption layer for JS
JavaScript
1
star