├── .bacon.yml ├── .eslintignore ├── .eslintrc.js ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug-report.yml │ ├── config.yml │ └── feature-request.yml ├── PULL_REQUEST_TEMPLATE.md ├── SECURITY.md └── workflows │ └── dispatch-downstream-update-samples-event.yml ├── .gitignore ├── .travis.yml ├── .vscode └── launch.json ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── babel.config.js ├── build.js ├── env ├── .eslintrc ├── index.js └── package.json ├── generator ├── .eslintrc ├── README.md ├── _templates │ └── samples │ │ ├── config │ │ └── new │ │ │ ├── package.json.t │ │ │ └── vite.config.js.t │ │ ├── env │ │ └── new │ │ │ ├── index.js.t │ │ │ └── okta-env.js.t │ │ └── license-banner.t ├── config.js ├── gulpfile.js │ ├── common.js │ ├── index.js │ ├── samples.js │ └── util.js ├── package.json └── yarn.lock ├── jest.config.js ├── package.json ├── rollup.config.js ├── samples ├── custom-login │ ├── .gitignore │ ├── README.md │ ├── bs-config.js │ ├── env │ │ ├── index.js │ │ └── okta-env.js │ ├── index.html │ ├── package.json │ ├── src │ │ ├── App.css │ │ ├── App.jsx │ │ ├── App.test.jsx │ │ ├── AuthRequiredModal.jsx │ │ ├── CorsErrorModal.jsx │ │ ├── Home.jsx │ │ ├── Login.jsx │ │ ├── Messages.jsx │ │ ├── Navbar.jsx │ │ ├── Profile.jsx │ │ ├── config.js │ │ ├── index.css │ │ ├── index.jsx │ │ ├── logo.svg │ │ └── polyfills.js │ └── vite.config.js ├── doc-direct-auth │ ├── .gitignore │ ├── bs-config.js │ ├── env │ │ ├── index.js │ │ └── okta-env.js │ ├── index.html │ ├── package.json │ ├── src │ │ ├── App.jsx │ │ ├── Home.jsx │ │ ├── Login.jsx │ │ ├── LoginForm.jsx │ │ ├── Protected.jsx │ │ ├── config.js │ │ └── index.jsx │ └── vite.config.js ├── doc-embedded-widget │ ├── .gitignore │ ├── bs-config.js │ ├── env │ │ ├── index.js │ │ └── okta-env.js │ ├── index.html │ ├── package.json │ ├── src │ │ ├── App.jsx │ │ ├── Home.jsx │ │ ├── Login.jsx │ │ ├── OktaSignInWidget.jsx │ │ ├── Protected.jsx │ │ ├── config.js │ │ └── index.jsx │ └── vite.config.js ├── okta-hosted-login │ ├── .gitignore │ ├── README.md │ ├── bs-config.js │ ├── env │ │ ├── index.js │ │ └── okta-env.js │ ├── index.html │ ├── package.json │ ├── src │ │ ├── App.css │ │ ├── App.jsx │ │ ├── App.test.jsx │ │ ├── AuthRequiredModal.jsx │ │ ├── CorsErrorModal.jsx │ │ ├── Home.jsx │ │ ├── Messages.jsx │ │ ├── Navbar.jsx │ │ ├── Profile.jsx │ │ ├── config.js │ │ ├── index.css │ │ ├── index.jsx │ │ ├── logo.svg │ │ └── polyfills.js │ └── vite.config.js └── routing │ ├── reach-router │ ├── README.md │ ├── bs-config.js │ ├── env │ │ ├── index.js │ │ └── okta-env.js │ ├── index.html │ ├── package.json │ ├── src │ │ ├── App.tsx │ │ ├── assets │ │ │ └── logo.svg │ │ ├── components │ │ │ ├── Footer.tsx │ │ │ ├── Loading.tsx │ │ │ ├── Nav.tsx │ │ │ ├── Routes.tsx │ │ │ └── SecureRoutes.tsx │ │ ├── config.ts │ │ ├── index.css │ │ ├── index.tsx │ │ ├── pages │ │ │ ├── Home.tsx │ │ │ └── Protected.tsx │ │ └── react-app-env.d.ts │ ├── tsconfig.json │ ├── tsconfig.node.json │ └── vite.config.js │ ├── react-router-dom-v5-hash │ ├── README.md │ ├── bs-config.js │ ├── env │ │ ├── index.js │ │ └── okta-env.js │ ├── index.html │ ├── package.json │ ├── src │ │ ├── App.tsx │ │ ├── assets │ │ │ └── logo.svg │ │ ├── components │ │ │ ├── Footer.tsx │ │ │ ├── Loading.tsx │ │ │ ├── LoginCallback.tsx │ │ │ ├── Nav.tsx │ │ │ ├── Routes.tsx │ │ │ └── SecureRoute.tsx │ │ ├── config.ts │ │ ├── index.css │ │ ├── index.tsx │ │ ├── pages │ │ │ ├── Home.tsx │ │ │ └── Protected.tsx │ │ └── react-app-env.d.ts │ ├── tsconfig.json │ ├── tsconfig.node.json │ └── vite.config.js │ ├── react-router-dom-v5 │ ├── README.md │ ├── bs-config.js │ ├── env │ │ ├── index.js │ │ └── okta-env.js │ ├── index.html │ ├── package.json │ ├── src │ │ ├── App.tsx │ │ ├── assets │ │ │ └── logo.svg │ │ ├── components │ │ │ ├── Footer.tsx │ │ │ ├── Loading.tsx │ │ │ ├── Nav.tsx │ │ │ ├── Routes.tsx │ │ │ └── SecureRoute.tsx │ │ ├── config.ts │ │ ├── index.css │ │ ├── index.tsx │ │ ├── pages │ │ │ ├── Home.tsx │ │ │ └── Protected.tsx │ │ └── react-app-env.d.ts │ ├── tsconfig.json │ ├── tsconfig.node.json │ └── vite.config.js │ ├── react-router-dom-v6-hash │ ├── README.md │ ├── bs-config.js │ ├── env │ │ ├── index.js │ │ └── okta-env.js │ ├── index.html │ ├── package.json │ ├── src │ │ ├── App.tsx │ │ ├── assets │ │ │ └── logo.svg │ │ ├── components │ │ │ ├── Footer.tsx │ │ │ ├── Loading.tsx │ │ │ ├── LoginCallback.tsx │ │ │ ├── Nav.tsx │ │ │ ├── Routes.tsx │ │ │ └── SecureRoute.tsx │ │ ├── config.ts │ │ ├── index.css │ │ ├── index.tsx │ │ ├── pages │ │ │ ├── Home.tsx │ │ │ └── Protected.tsx │ │ └── react-app-env.d.ts │ ├── tsconfig.json │ ├── tsconfig.node.json │ └── vite.config.js │ └── react-router-dom-v6 │ ├── .gitignore │ ├── README.md │ ├── bs-config.js │ ├── env │ ├── index.js │ └── okta-env.js │ ├── index.html │ ├── package.json │ ├── src │ ├── App.tsx │ ├── assets │ │ └── logo.svg │ ├── components │ │ ├── Footer.tsx │ │ ├── Loading.tsx │ │ ├── Nav.tsx │ │ ├── Routes.tsx │ │ └── SecureRoute.tsx │ ├── config.ts │ ├── index.css │ ├── index.tsx │ ├── pages │ │ ├── Home.tsx │ │ └── Protected.tsx │ └── vite-env.d.ts │ ├── tsconfig.json │ ├── tsconfig.node.json │ └── vite.config.js ├── scripts ├── downstream │ └── create-downstream-for-authjs.sh ├── e2e-v6.sh ├── e2e.sh ├── lint.sh ├── publish.sh ├── semgrep.sh ├── setup.sh ├── snyk.sh ├── travis.sh ├── unit-v6.sh ├── unit.sh └── utils │ ├── local.sh │ ├── siw-platform-scripts.sh │ └── sync-ws-auth-js.sh ├── src ├── .eslintrc.js ├── LoginCallback.tsx ├── OktaContext.ts ├── OktaError.tsx ├── SecureRoute.tsx ├── Security.tsx ├── index.ts └── withOktaAuth.tsx ├── test ├── apps │ ├── test-harness-app │ │ ├── .env.development │ │ ├── .gitignore │ │ ├── index.html │ │ ├── package.json │ │ ├── src │ │ │ ├── App.css │ │ │ ├── App.tsx │ │ │ ├── CustomLogin.tsx │ │ │ ├── Home.tsx │ │ │ ├── Protected.tsx │ │ │ ├── SessionTokenLogin.tsx │ │ │ ├── WidgetLogin.tsx │ │ │ ├── index.css │ │ │ ├── index.tsx │ │ │ ├── logo.svg │ │ │ ├── react-app-env.d.ts │ │ │ └── vite-env.d.ts │ │ ├── tsconfig.json │ │ ├── tsconfig.node.json │ │ └── vite.config.js │ └── v6-app │ │ ├── .env.development │ │ ├── .gitignore │ │ ├── index.html │ │ ├── package.json │ │ ├── src │ │ ├── App.css │ │ ├── App.tsx │ │ ├── CustomLogin.tsx │ │ ├── Home.tsx │ │ ├── Protected.tsx │ │ ├── SecureRoute.tsx │ │ ├── SessionTokenLogin.tsx │ │ ├── WidgetLogin.tsx │ │ ├── index.css │ │ ├── index.tsx │ │ ├── logo.svg │ │ ├── react-app-env.d.ts │ │ └── vite-env.d.ts │ │ ├── tsconfig.json │ │ ├── tsconfig.node.json │ │ └── vite.config.js ├── e2e │ ├── .eslintrc.js │ ├── babel.config.js │ ├── package.json │ ├── page-objects │ │ ├── authenticators-page.js │ │ ├── direct-auth-login-form.js │ │ ├── messages-page.js │ │ ├── mfa-challenge-page.js │ │ ├── okta-oie-signin-page.js │ │ ├── okta-signin-page.js │ │ ├── router-sample-page.js │ │ ├── shared │ │ │ ├── authenticated-home-page.js │ │ │ ├── login-home-page.js │ │ │ ├── profile-page.js │ │ │ └── protected-page.js │ │ └── test-harness-app │ │ │ ├── app-page.js │ │ │ ├── index.js │ │ │ ├── login-callback-page.js │ │ │ ├── protected-page.js │ │ │ └── sessionToken-signin-page.js │ ├── runner.js │ ├── specs │ │ ├── custom-login.js │ │ ├── doc-direct-auth.js │ │ ├── doc-embedded-widget.js │ │ ├── okta-hosted-login.js │ │ ├── router-sample.js │ │ └── test-harness-app.js │ └── wdio.conf.js └── jest │ ├── .eslintrc.js │ ├── loginCallback.test.tsx │ ├── oktaError.test.tsx │ ├── reactRouterV6.test.tsx │ ├── secureRoute.test.tsx │ ├── security.test.tsx │ ├── setup.ts │ └── tsconfig.json ├── tsconfig.json ├── util ├── license-template.txt └── maintain-banners.js └── yarn.lock /.bacon.yml: -------------------------------------------------------------------------------- 1 | test_suites: 2 | - name: lint 3 | script_path: /root/okta/okta-react/scripts 4 | sort_order: '1' 5 | timeout: '60' 6 | script_name: lint 7 | criteria: MERGE 8 | queue_name: small 9 | - name: unit 10 | script_path: /root/okta/okta-react/scripts 11 | sort_order: '2' 12 | timeout: '10' 13 | script_name: unit 14 | criteria: MERGE 15 | queue_name: small 16 | - name: e2e 17 | script_path: /root/okta/okta-react/scripts 18 | sort_order: '3' 19 | timeout: '15' 20 | script_name: e2e 21 | criteria: MERGE 22 | queue_name: small 23 | - name: unit-v6 24 | script_path: /root/okta/okta-react/scripts 25 | sort_order: '4' 26 | timeout: '10' 27 | script_name: unit-v6 28 | criteria: MERGE 29 | queue_name: small 30 | - name: e2e-v6 31 | script_path: /root/okta/okta-react/scripts 32 | sort_order: '5' 33 | timeout: '15' 34 | script_name: e2e-v6 35 | criteria: MERGE 36 | queue_name: small 37 | - name: publish 38 | script_path: /root/okta/okta-react/scripts 39 | sort_order: '6' 40 | timeout: '60' 41 | script_name: publish 42 | criteria: MERGE 43 | queue_name: small 44 | - name: semgrep 45 | script_path: /root/okta/okta-react/scripts 46 | sort_order: '7' 47 | timeout: '10' 48 | script_name: semgrep 49 | criteria: MERGE 50 | queue_name: small -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | /scripts 4 | build 5 | test/apps/react-routing/e2e -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | // https://eslint.org/docs/user-guide/configuring 2 | 3 | const packageJson = require('./package.json'); 4 | const devDependencies = Object.keys(packageJson.devDependencies || {}); 5 | 6 | module.exports = { 7 | root: true, 8 | parserOptions: { 9 | sourceType: 'module', 10 | ecmaVersion: 2020 11 | }, 12 | extends: [ 13 | 'eslint:recommended', 14 | 'plugin:react/recommended', 15 | ], 16 | plugins: [ 17 | 'react', 18 | 'react-hooks' 19 | ], 20 | rules: { 21 | 'react/prop-types': 0, 22 | }, 23 | settings: { 24 | react: { 25 | version: '16.8', 26 | } 27 | }, 28 | overrides: [ 29 | { 30 | // NodeJS build tools 31 | files: [ 32 | 'build.js', 33 | 'env.js', 34 | 'util/**/*', 35 | 'config-overrides.js', 36 | 'protractor.conf.js', 37 | '.eslintrc.js', 38 | 'babel.config.js', 39 | 'jest.config.js', 40 | 'vite.config.js', 41 | 'bs-config.js' 42 | ], 43 | plugins: ['node'], 44 | env: { 45 | node: true, 46 | es6: true 47 | }, 48 | rules: { 49 | 'node/no-unpublished-require': ['error', { 50 | 'allowModules': devDependencies 51 | }] 52 | } 53 | }, 54 | { 55 | // rollup.config.js 56 | files: ['rollup.config.js'], 57 | parserOptions: { 58 | sourceType: 'module', 59 | ecmaVersion: 2020 60 | }, 61 | env: { 62 | node: true 63 | } 64 | }, 65 | { 66 | files: ['samples/**/*'], 67 | env: { 68 | node: true, 69 | browser: true 70 | } 71 | } 72 | ] 73 | } 74 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | generated/**/* linguist-generated=true 2 | samples/**/bs-config.js linguist-generated=true 3 | samples/**/vite.config.js linguist-generated=true 4 | samples/**/package.json linguist-generated=true 5 | samples/routing/**/bs-config.js linguist-generated=true 6 | samples/routing/**/vite.config.js linguist-generated=true 7 | samples/routing/**/package.json linguist-generated=true -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: Report a bug you encountered with the Okta React SDK 3 | labels: [ bug ] 4 | body: 5 | - type: textarea 6 | id: problem 7 | attributes: 8 | label: Describe the bug 9 | description: | 10 | Please be as detailed as possible. This will help us address the bug in a timely manner. 11 | placeholder: What is expected to happen... What is the actual behavior? 12 | validations: 13 | required: true 14 | 15 | - type: textarea 16 | id: repro 17 | attributes: 18 | label: Reproduction Steps? 19 | description: | 20 | Please provide as much detail as possible to help us reproduce your bug. 21 | A reproduction repo is very helpful for us as well. 22 | validations: 23 | required: true 24 | 25 | - type: textarea 26 | id: sdkVersion 27 | attributes: 28 | label: SDK Versions 29 | description: | 30 | Output of `npx envinfo --system --npmPackages '{@okta/*,react*}' --binaries --browsers` 31 | validations: 32 | required: true 33 | 34 | - type: textarea 35 | id: additional 36 | attributes: 37 | label: Additional Information 38 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: Developer Forum 3 | url: https://devforum.okta.com/ 4 | about: Get help with building your applicaiton on the Okta Platform. 5 | blank_issues_enabled: false 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 2 | description: Request a new feature for this SDK? 3 | labels: [ enhancement ] 4 | body: 5 | - type: textarea 6 | id: description 7 | attributes: 8 | label: Describe the feature request? 9 | description: | 10 | Please leave a helpful description of the feature request here. 11 | validations: 12 | required: true 13 | 14 | - type: textarea 15 | id: resources 16 | attributes: 17 | label: New or Affected Resource(s) 18 | description: | 19 | Please list the new or affected resources 20 | validations: 21 | required: true 22 | 23 | - type: textarea 24 | id: documentation 25 | attributes: 26 | label: Provide a documentation link 27 | description: | 28 | Please provide any links to the documentation that is at 29 | https://developer.okta.com/. This will help us with this 30 | feature request. 31 | 32 | - type: textarea 33 | id: additional 34 | attributes: 35 | label: Additional Information? 36 | 37 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## PR Checklist 2 | Please check if your PR fulfills the following requirements: 3 | 4 | - [ ] The commit message follows our [guidelines](/okta/okta-react/blob/master/CONTRIBUTING.md#commit) 5 | - [ ] Tests for the changes have been added (for bug fixes / features) 6 | - [ ] Docs have been added / updated (for bug fixes / features) 7 | 8 | 9 | ## PR Type 10 | What kind of change does this PR introduce? 11 | 12 | - [ ] Bugfix 13 | - [ ] Feature 14 | - [ ] Code style update (formatting, local variables) 15 | - [ ] Refactoring (no functional changes, no api changes) 16 | - [ ] Adding Tests 17 | - [ ] Build related changes 18 | - [ ] CI related changes 19 | - [ ] Documentation changes 20 | - [ ] Other... Please describe: 21 | 22 | 23 | ## What is the current behavior? 24 | 25 | 26 | Issue Number: N/A 27 | 28 | 29 | ## What is the new behavior? 30 | 31 | 32 | ## Does this PR introduce a breaking change? 33 | - [ ] Yes 34 | - [ ] No 35 | 36 | 37 | 38 | 39 | ## Other information 40 | 41 | 42 | ## Reviewers 43 | 44 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Report a Vulnerability 4 | At Okta we take the protection of our customers’ data very seriously. If you need to report a vulnerability, please visit https://www.okta.com/vulnerability-reporting-policy/ for more information. 5 | -------------------------------------------------------------------------------- /.github/workflows/dispatch-downstream-update-samples-event.yml: -------------------------------------------------------------------------------- 1 | name: Dispatch Downstream Update Samples Event 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | 7 | release: 8 | types: [ released ] 9 | 10 | workflow_dispatch: 11 | 12 | jobs: 13 | dispatch: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - uses: actions/checkout@v3 18 | - uses: actions/setup-node@v2 19 | with: 20 | node-version: 14 21 | - run: npm install semver execa@5.1.1 22 | 23 | - name: Dispatch event 24 | uses: actions/github-script@v6 25 | with: 26 | github-token: ${{secrets.OKTA_433527}} 27 | script: | 28 | const semverMajor = require('semver/functions/major'); 29 | const execa = require('execa'); 30 | // get version from package.json 31 | const pkgJsonVersion = require('./package.json').version; 32 | // get latest version from registry 33 | const { stdout: latestPublishedVersion } = await execa('npm', ['view', '@okta/okta-react', 'version']); 34 | github.rest.repos.createDispatchEvent({ 35 | owner: context.repo.owner, 36 | repo: 'samples-js-react', 37 | event_type: 'update-samples', 38 | client_payload: { 39 | context, 40 | // indicates if downstream repo should auto merge the generated samples 41 | // merge when 1) in a "released" workflow or 2) non-breaking change 42 | merge: context.workflow === 'released' || semverMajor(pkgJsonVersion) === semverMajor(latestPublishedVersion) 43 | } 44 | }); 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist 2 | build2 3 | node_modules 4 | .DS_Store 5 | testenv 6 | /test-reports 7 | .yalc 8 | yalc.lock 9 | .yarnrc 10 | .yarn 11 | .env -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '12.13.0' 4 | 5 | addons: 6 | chrome: stable 7 | 8 | services: 9 | - xvfb 10 | 11 | jdk: 12 | - default-jdk 13 | 14 | install: 15 | - yarn install --frozen-lockfile 16 | 17 | script: 18 | - bash ./scripts/snyk.sh 19 | - bash ./scripts/travis.sh 20 | 21 | before_install: 22 | - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.13.0 23 | - export PATH="$HOME/.yarn/bin:$PATH" 24 | - sudo apt-get update 25 | - sudo apt-get install -y libappindicator1 26 | 27 | notifications: 28 | slack: 29 | on_pull_requests: false 30 | on_success: never 31 | on_failure: always 32 | rooms: 33 | - secure: llwX53NUK+utV8UEFtzXTt5OuhXg+rx/Y3beFNBp7nwASI1k1cpYk8gHhDM6Kj14ydDGtwYd6bL4QcKWWzrA8Hc7EPpXyfgfxF7lDVxIbm62E3rSwqf2XpoNAo0EzcPvjwAGsQnydQUiQR7tR0JTzaHTX+685XreQeQyZXiIB9eWxXCaAkVCRfuoxngcAOXNw1IRMzaRt0pyYbu4qZ0RAA4bLwjlc5RqhAUllGszxX7KCSIJwAa4kXIYT/EsBC1mKeyCdvihvFYp6rPjTDL/J8w8+r9v9SVq8n6/LMcRdEpl8gOIQ3+oLzB1UcX5zWItrVqSXZ221d6z432Vu+mR5olhbcxULkfVZwtTW6tiR/5JkGxI08k5aZAmZupOjMlJN2UJtBxkAUhthCLKPXsrwU0RnW7pOeiH5CKECCsT9S06ZW2VvEJ+CZ1WOqzYtp18Kcq/VqbFqX/ubEy80m0YgnDugLGcwEUrDZFn44g+hu2B59TJMudeOTWEEk6bdy+XTNY4Ufd0uqCoHwBZQICKIXqhxMuxcRYdbFeguTzwu1R7OYagwL9S0PC/RoqrhoiN3vs/KTEVZp7yZLZautT/0cbuDQzfZzJ6RXJZzzNmrQ7Wof9lrNObJgDDdL+dZW9Umv7ELpTjqJicOlih6USjtMq+e+tBiUl/mHMFVnxbZX8= 34 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Jest current file", 11 | "program": "${workspaceFolder}/node_modules/jest/bin/jest", 12 | "args": [ 13 | "--runInBand", 14 | "--no-cache", 15 | "${relativeFile}" 16 | ], 17 | "console": "integratedTerminal", 18 | "internalConsoleOptions": "neverOpen" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | const presets = [ 2 | '@babel/preset-react' 3 | ]; 4 | const plugins = []; 5 | 6 | if (process.env.NODE_ENV === 'test') { 7 | // Convert to commonJS when running in jest 8 | presets.unshift(['@babel/preset-env', { 9 | modules: 'commonjs' 10 | }]); 11 | } 12 | 13 | module.exports = { presets, plugins }; 14 | -------------------------------------------------------------------------------- /build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const shell = require('shelljs'); 4 | const chalk = require('chalk'); 5 | const fs = require('fs'); 6 | 7 | const NPM_DIR = `dist`; 8 | const BUNDLE_CMD = 'yarn bundle'; 9 | const BANNER_CMD = `yarn banners`; 10 | 11 | shell.echo(`Start building...`); 12 | 13 | shell.rm(`-Rf`, `${NPM_DIR}/*`); 14 | 15 | // Bundle with rollup 16 | if (shell.exec(BUNDLE_CMD).code !== 0) { 17 | shell.echo(chalk.red(`Error: Rollup failed`)); 18 | shell.exit(1); 19 | } 20 | 21 | // Maintain banners 22 | if (shell.exec(BANNER_CMD).code !== 0) { 23 | shell.echo(chalk.red(`Error: Maintain banners failed`)); 24 | shell.exit(1); 25 | } 26 | 27 | shell.echo(chalk.green(`Bundling completed`)); 28 | 29 | shell.cp(`-Rf`, [`package.json`, `LICENSE`, `*.md`], `${NPM_DIR}`); 30 | 31 | shell.echo(`Modifying final package.json`); 32 | let packageJSON = JSON.parse(fs.readFileSync(`./${NPM_DIR}/package.json`)); 33 | delete packageJSON.private; // remove private flag 34 | delete packageJSON.scripts; // remove all scripts 35 | delete packageJSON.jest; // remove jest section 36 | delete packageJSON['jest-junit']; // remove jest-junit section 37 | delete packageJSON.workspaces; // remove yarn workspace section 38 | 39 | // Remove "build/" from the entrypoint paths. 40 | ['main', 'module', 'types'].forEach(function(key) { 41 | if (packageJSON[key]) { 42 | packageJSON[key] = packageJSON[key].replace(`${NPM_DIR}/`, ''); 43 | } 44 | }); 45 | 46 | fs.writeFileSync(`./${NPM_DIR}/package.json`, JSON.stringify(packageJSON, null, 4)); 47 | 48 | shell.echo(chalk.green(`End building`)); 49 | -------------------------------------------------------------------------------- /env/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "commonjs": true, 4 | "es6": true, 5 | "node": true 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /env/index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | const dotenv = require('dotenv'); 14 | const fs = require('fs'); 15 | const path = require('path'); 16 | 17 | const TESTENV_FILE = 'testenv'; 18 | 19 | function setEnvironmentVars(envConfig) { 20 | Object.keys(envConfig).forEach((k) => { 21 | if (process.env[k] !== envConfig[k]) { 22 | console.log(`Setting a new value for environment variable "${k}"`); 23 | } 24 | process.env[k] = envConfig[k]; 25 | }); 26 | } 27 | 28 | function getPath(currDir = __dirname) { 29 | let res, prevDir; 30 | // stop when find testenv file or reach to root dir 31 | while (!fs.existsSync(res) && currDir !== prevDir) { 32 | prevDir = currDir; 33 | res = path.resolve(currDir, TESTENV_FILE); 34 | currDir = path.resolve(currDir, '..'); 35 | } 36 | return fs.existsSync(res) ? res : null; 37 | } 38 | 39 | function setEnvironmentVarsFromTestEnv(currDir) { 40 | const testEnvPath = getPath(currDir); 41 | if (!testEnvPath) { 42 | return; 43 | } 44 | const envConfig = dotenv.parse(fs.readFileSync(testEnvPath)); 45 | setEnvironmentVars(envConfig); 46 | } 47 | 48 | module.exports = { 49 | setEnvironmentVarsFromTestEnv 50 | }; 51 | -------------------------------------------------------------------------------- /env/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@okta/env", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "private": true, 6 | "dependencies": { 7 | "dotenv": "^8.2.0" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /generator/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "commonjs": true, 4 | "es6": true, 5 | "node": true 6 | }, 7 | "parserOptions": { 8 | "ecmaVersion": 2018 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /generator/_templates/samples/config/new/package.json.t: -------------------------------------------------------------------------------- 1 | --- 2 | to: ../samples/<%= dest %>/package.json 3 | force: true 4 | --- 5 | { 6 | "comment": "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'", 7 | "name": "<%= pkgName %>", 8 | "private": true, 9 | "version": "0.3.0", 10 | "scripts": { 11 | "prestart": "STANDALONE_SAMPLE_BUILD=1 vite build", 12 | "start": "vite preview", 13 | "dev": "vite", 14 | "build": "vite build", 15 | "preview": "vite preview" 16 | }, 17 | "dependencies": { 18 | "react": "^17.0.2", 19 | "react-dom": "^17.0.2", 20 | <% if (reactRouterDomVersion !== 'false') { -%> 21 | "react-router-dom": "<%= reactRouterDomVersion %>", 22 | <% } -%> 23 | "@okta/okta-auth-js": "<%= oktaAuthJsVersion %>", 24 | <% if (useSiw === 'true') { -%> 25 | "@okta/okta-signin-widget": "^<%= siwVersion %>", 26 | <% } -%> 27 | <% if (useSemanticUi === 'true') { -%> 28 | "semantic-ui-css": "2.4.1", 29 | "semantic-ui-react": "2.0.3", 30 | <% } -%> 31 | <% if (usePolyfill === 'true') { -%> 32 | "text-encoding": "0.7.0", 33 | <% } -%> 34 | <% if (reachRouterVersion !== 'false') { -%> 35 | "@reach/router":"<%= reachRouterVersion %>", 36 | "@types/reach__router": "<%= reachRouterVersion %>", 37 | <% } -%> 38 | "@okta/okta-react": "*" 39 | }, 40 | "devDependencies": { 41 | "@vitejs/plugin-react": "^1.3.2", 42 | "vite": "^2.8.0", 43 | "dotenv": "^16.0.0" 44 | } 45 | } -------------------------------------------------------------------------------- /generator/_templates/samples/env/new/index.js.t: -------------------------------------------------------------------------------- 1 | --- 2 | to: ../samples/<%= dest %>/env/index.js 3 | force: true 4 | --- 5 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 6 | 7 | export default function () { 8 | let oktaEnv; 9 | try { 10 | oktaEnv = require('@okta/env'); 11 | } catch (err) { 12 | if (err.code === 'MODULE_NOT_FOUND') { 13 | // try local env module 14 | oktaEnv = require('./okta-env'); 15 | return oktaEnv; 16 | } 17 | 18 | throw err; 19 | } 20 | 21 | return oktaEnv; 22 | } 23 | -------------------------------------------------------------------------------- /generator/_templates/samples/env/new/okta-env.js.t: -------------------------------------------------------------------------------- 1 | --- 2 | to: ../samples/<%= dest %>/env/okta-env.js 3 | --- 4 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 5 | <%- include(`${cwd}/../env/index.js`) %> -------------------------------------------------------------------------------- /generator/_templates/samples/license-banner.t: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ -------------------------------------------------------------------------------- /generator/gulpfile.js/common.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | const { src } = require('gulp'); 14 | const clean = require('gulp-clean'); 15 | const { install } = require('./util'); 16 | 17 | const BUILD_DIR = '../generated'; 18 | 19 | const cleanTask = () => 20 | src(`${BUILD_DIR}`, { read: false, allowEmpty: true }) 21 | .pipe(clean({ force: true })); 22 | 23 | const installTask = done => { 24 | install(); 25 | done(); 26 | }; 27 | 28 | module.exports = { 29 | install: installTask, 30 | clean: cleanTask 31 | }; 32 | -------------------------------------------------------------------------------- /generator/gulpfile.js/index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | const { series } = require('gulp'); 14 | const commonTasks = require('./common'); 15 | const samplesTasks = require('./samples'); 16 | 17 | module.exports = { 18 | default: series( 19 | samplesTasks['generate:samples'], 20 | commonTasks.install 21 | ), 22 | ...commonTasks, 23 | ...samplesTasks, 24 | }; 25 | -------------------------------------------------------------------------------- /generator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@okta/generator", 3 | "version": "1.0.0", 4 | "description": "Generator for samples, docs and snippets", 5 | "private": true, 6 | "scripts": { 7 | "gulp": "HYGEN_OVERWRITE=1 gulp", 8 | "generate": "HYGEN_OVERWRITE=1 gulp" 9 | }, 10 | "engines": { 11 | "node": ">=12.0.0" 12 | }, 13 | "dependencies": { 14 | "gulp": "^5.0.0", 15 | "hygen": "^6.2.0", 16 | "gulp-clean": "^0.4.0", 17 | "gulp-rename": "^2.0.0", 18 | "merge-stream": "^2.0.0", 19 | "shelljs": "^0.8.5" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | coverageDirectory: '/test-reports/coverage', 3 | collectCoverage: true, 4 | collectCoverageFrom: [ 5 | './src/**', 6 | '!./test/**' 7 | ], 8 | globals: { 9 | AUTH_JS: { minSupportedVersion: '5.3.1' }, 10 | PACKAGE_NAME: 'okta-react-test', 11 | PACKAGE_VERSION: '3.14.15', 12 | SKIP_VERSION_CHECK: '1' 13 | }, 14 | reporters: [ 15 | 'default', 16 | 'jest-junit' 17 | ], 18 | restoreMocks: true, 19 | moduleNameMapper: { 20 | // avoid react conflict in yarn workspace 21 | '^react$': '/node_modules/react', 22 | '^react-dom$': '/node_modules/react-dom', 23 | '^react-router-dom$': '/node_modules/react-router-dom' 24 | }, 25 | roots: [ 26 | './test/jest' 27 | ], 28 | setupFiles: [ 29 | './test/jest/setup.ts' 30 | ], 31 | testEnvironment: 'jsdom', 32 | transform: { 33 | '^.+\\.tsx?$': ['ts-jest', { 34 | diagnostics: { 35 | warnOnly: true 36 | }, 37 | tsconfig: '/test/jest/tsconfig.json', 38 | isolatedModules: true 39 | }] 40 | }, 41 | }; 42 | -------------------------------------------------------------------------------- /samples/custom-login/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | 26 | package-lock.json 27 | yarn.lock 28 | -------------------------------------------------------------------------------- /samples/custom-login/bs-config.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | module.exports = { 4 | port: process.env.PORT || 8080, 5 | logLevel: 'silent', 6 | files: ['./dist/**/*.{html,htm,css,js}'], 7 | server: { 8 | baseDir: './dist', 9 | middleware: { 10 | 0: null 11 | } 12 | }, 13 | open: false 14 | }; 15 | -------------------------------------------------------------------------------- /samples/custom-login/env/index.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | export default function () { 4 | let oktaEnv; 5 | try { 6 | oktaEnv = require('@okta/env'); 7 | } catch (err) { 8 | if (err.code === 'MODULE_NOT_FOUND') { 9 | // try local env module 10 | oktaEnv = require('./okta-env'); 11 | return oktaEnv; 12 | } 13 | 14 | throw err; 15 | } 16 | 17 | return oktaEnv; 18 | } 19 | -------------------------------------------------------------------------------- /samples/custom-login/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/custom-login/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'", 3 | "name": "@okta/samples.react.custom-login", 4 | "private": true, 5 | "version": "0.3.0", 6 | "scripts": { 7 | "prestart": "STANDALONE_SAMPLE_BUILD=1 vite build", 8 | "start": "vite preview", 9 | "dev": "vite", 10 | "build": "vite build", 11 | "preview": "vite preview" 12 | }, 13 | "dependencies": { 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-router-dom": "5.2.0", 17 | "@okta/okta-auth-js": "*", 18 | "@okta/okta-signin-widget": "^6.7.1", 19 | "semantic-ui-css": "2.4.1", 20 | "semantic-ui-react": "2.0.3", 21 | "text-encoding": "0.7.0", 22 | "@okta/okta-react": "*" 23 | }, 24 | "devDependencies": { 25 | "@vitejs/plugin-react": "^1.3.2", 26 | "vite": "^2.8.0", 27 | "dotenv": "^16.0.0" 28 | } 29 | } -------------------------------------------------------------------------------- /samples/custom-login/src/App.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | .App { 14 | text-align: center; 15 | } 16 | 17 | .App-logo { 18 | animation: App-logo-spin infinite 20s linear; 19 | height: 80px; 20 | } 21 | 22 | .App-header { 23 | background-color: #222; 24 | height: 150px; 25 | padding: 20px; 26 | color: white; 27 | } 28 | 29 | .App-title { 30 | font-size: 1.5em; 31 | } 32 | 33 | .App-intro { 34 | font-size: large; 35 | } 36 | 37 | @keyframes App-logo-spin { 38 | from { transform: rotate(0deg); } 39 | to { transform: rotate(360deg); } 40 | } 41 | -------------------------------------------------------------------------------- /samples/custom-login/src/App.test.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import ReactDOM from 'react-dom'; 15 | import { MemoryRouter } from 'react-router-dom'; 16 | import { act } from 'react-dom/test-utils'; 17 | import App from './App'; 18 | 19 | jest.mock('./Login', () => () =>
Login
); 20 | 21 | let container; 22 | beforeEach(() => { 23 | container = document.createElement('div'); 24 | document.body.appendChild(container); 25 | }); 26 | 27 | afterEach(() => { 28 | document.body.removeChild(container); 29 | container = null; 30 | }); 31 | 32 | it('renders title link', async () => { 33 | await act(async () => { 34 | ReactDOM.render(, container); 35 | }); 36 | 37 | const linkElement = container.querySelector('a'); 38 | expect(linkElement.textContent.trim()).toBe('Okta-React Sample Project'); 39 | }); 40 | -------------------------------------------------------------------------------- /samples/custom-login/src/config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | const CLIENT_ID = process.env.CLIENT_ID || '{clientId}'; 14 | const ISSUER = process.env.ISSUER || 'https://{yourOktaDomain}.com/oauth2/default'; 15 | const OKTA_TESTING_DISABLEHTTPSCHECK = process.env.OKTA_TESTING_DISABLEHTTPSCHECK || false; 16 | const BASENAME = import.meta.env.BASE_URL || ''; 17 | // BASENAME includes trailing slash 18 | const REDIRECT_URI = `${window.location.origin}${BASENAME}login/callback`; 19 | const USE_INTERACTION_CODE = process.env.USE_INTERACTION_CODE === 'true' || false; 20 | 21 | export default { 22 | oidc: { 23 | clientId: CLIENT_ID, 24 | issuer: ISSUER, 25 | redirectUri: REDIRECT_URI, 26 | scopes: ['openid', 'profile', 'email'], 27 | pkce: true, 28 | disableHttpsCheck: OKTA_TESTING_DISABLEHTTPSCHECK, 29 | useInteractionCode: USE_INTERACTION_CODE, 30 | }, 31 | resourceServer: { 32 | messagesUrl: 'http://localhost:8000/api/messages', 33 | }, 34 | app: { 35 | basename: BASENAME, 36 | }, 37 | }; 38 | -------------------------------------------------------------------------------- /samples/custom-login/src/index.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | body { 14 | margin: 0; 15 | padding: 0; 16 | font-family: sans-serif; 17 | } -------------------------------------------------------------------------------- /samples/custom-login/src/index.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import ReactDOM from 'react-dom'; 15 | import { BrowserRouter as Router } from 'react-router-dom'; 16 | import 'semantic-ui-css/semantic.min.css'; 17 | import './polyfills'; 18 | import App from './App'; 19 | import config from './config'; 20 | import './index.css'; 21 | 22 | /* eslint-disable react/jsx-filename-extension */ 23 | ReactDOM.render( 24 | 25 | 26 | , 27 | document.getElementById('root'), 28 | ); 29 | -------------------------------------------------------------------------------- /samples/custom-login/src/polyfills.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | // polyfill TextEncoder for IE Edge 14 | import { TextEncoder } from 'text-encoding'; 15 | 16 | if (typeof window.TextEncoder === 'undefined') { 17 | window.TextEncoder = TextEncoder; 18 | } 19 | -------------------------------------------------------------------------------- /samples/doc-direct-auth/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /samples/doc-direct-auth/bs-config.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | module.exports = { 4 | port: process.env.PORT || 8080, 5 | logLevel: 'silent', 6 | files: ['./dist/**/*.{html,htm,css,js}'], 7 | server: { 8 | baseDir: './dist', 9 | middleware: { 10 | 0: null 11 | } 12 | }, 13 | open: false 14 | }; 15 | -------------------------------------------------------------------------------- /samples/doc-direct-auth/env/index.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | export default function () { 4 | let oktaEnv; 5 | try { 6 | oktaEnv = require('@okta/env'); 7 | } catch (err) { 8 | if (err.code === 'MODULE_NOT_FOUND') { 9 | // try local env module 10 | oktaEnv = require('./okta-env'); 11 | return oktaEnv; 12 | } 13 | 14 | throw err; 15 | } 16 | 17 | return oktaEnv; 18 | } 19 | -------------------------------------------------------------------------------- /samples/doc-direct-auth/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/doc-direct-auth/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'", 3 | "name": "@okta/samples.react.doc-direct-auth", 4 | "private": true, 5 | "version": "0.3.0", 6 | "scripts": { 7 | "prestart": "STANDALONE_SAMPLE_BUILD=1 vite build", 8 | "start": "vite preview", 9 | "dev": "vite", 10 | "build": "vite build", 11 | "preview": "vite preview" 12 | }, 13 | "dependencies": { 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-router-dom": "5.2.0", 17 | "@okta/okta-auth-js": "*", 18 | "@okta/okta-react": "*" 19 | }, 20 | "devDependencies": { 21 | "@vitejs/plugin-react": "^1.3.2", 22 | "vite": "^2.8.0", 23 | "dotenv": "^16.0.0" 24 | } 25 | } -------------------------------------------------------------------------------- /samples/doc-direct-auth/src/Home.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Link, useHistory } from 'react-router-dom'; 15 | import { useOktaAuth } from '@okta/okta-react'; 16 | 17 | const Home = () => { 18 | const { authState, oktaAuth } = useOktaAuth(); 19 | const history = useHistory(); 20 | 21 | const handleLogin = () => { 22 | history.push('/login'); 23 | }; 24 | 25 | const handleLogout = () => { 26 | oktaAuth.signOut(); 27 | }; 28 | 29 | if (!authState) { 30 | return
Loading...
; 31 | } 32 | 33 | return ( 34 |
35 | Home 36 |
37 | Protected 38 |
39 | { 40 | authState.isAuthenticated 41 | ? 42 | : 43 | } 44 |
45 | ); 46 | }; 47 | 48 | export default Home; 49 | -------------------------------------------------------------------------------- /samples/doc-direct-auth/src/Login.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Redirect } from 'react-router-dom'; 15 | import { useOktaAuth } from '@okta/okta-react'; 16 | import LoginForm from './LoginForm'; 17 | 18 | const Login = () => { 19 | const { authState } = useOktaAuth(); 20 | 21 | if (!authState) { 22 | return
Loading...
; 23 | } 24 | 25 | return authState.isAuthenticated 26 | ? 27 | : ; 28 | }; 29 | 30 | export default Login; 31 | -------------------------------------------------------------------------------- /samples/doc-direct-auth/src/Protected.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | 15 | const Home = () =>

Protected

; 16 | 17 | export default Home; 18 | -------------------------------------------------------------------------------- /samples/doc-direct-auth/src/config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | const CLIENT_ID = process.env.SPA_CLIENT_ID || process.env.CLIENT_ID || '{clientId}'; 14 | const ISSUER = process.env.ISSUER || 'https://{yourOktaDomain}.com/oauth2/default'; 15 | const REDIRECT_URI = `${window.location.origin}/login/callback`; 16 | 17 | export default { 18 | oidc: { 19 | clientId: CLIENT_ID, 20 | issuer: ISSUER, 21 | redirectUri: REDIRECT_URI, 22 | scopes: ['openid', 'profile', 'email'], 23 | pkce: true, 24 | }, 25 | widget: { 26 | baseUrl: ISSUER.replace('/oauth2/default', ''), 27 | clientId: CLIENT_ID, 28 | redirectUri: `${window.location.origin}/login/callback`, 29 | authParams: { 30 | // If your app is configured to use the Implicit flow 31 | // instead of the Authorization Code with Proof of Code Key Exchange (PKCE) 32 | // you will need to uncomment the below line 33 | // pkce: false 34 | }, 35 | // Additional documentation on config options can be found at https://github.com/okta/okta-signin-widget#basic-config-options 36 | }, 37 | }; 38 | -------------------------------------------------------------------------------- /samples/doc-direct-auth/src/index.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import ReactDOM from 'react-dom'; 15 | import { BrowserRouter as Router } from 'react-router-dom'; 16 | import App from './App'; 17 | 18 | ReactDOM.render( 19 | 20 | 21 | , 22 | document.getElementById('root'), 23 | ); 24 | -------------------------------------------------------------------------------- /samples/doc-embedded-widget/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /samples/doc-embedded-widget/bs-config.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | module.exports = { 4 | port: process.env.PORT || 8080, 5 | logLevel: 'silent', 6 | files: ['./dist/**/*.{html,htm,css,js}'], 7 | server: { 8 | baseDir: './dist', 9 | middleware: { 10 | 0: null 11 | } 12 | }, 13 | open: false 14 | }; 15 | -------------------------------------------------------------------------------- /samples/doc-embedded-widget/env/index.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | export default function () { 4 | let oktaEnv; 5 | try { 6 | oktaEnv = require('@okta/env'); 7 | } catch (err) { 8 | if (err.code === 'MODULE_NOT_FOUND') { 9 | // try local env module 10 | oktaEnv = require('./okta-env'); 11 | return oktaEnv; 12 | } 13 | 14 | throw err; 15 | } 16 | 17 | return oktaEnv; 18 | } 19 | -------------------------------------------------------------------------------- /samples/doc-embedded-widget/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/doc-embedded-widget/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'", 3 | "name": "@okta/samples.react.doc-embedded-widget", 4 | "private": true, 5 | "version": "0.3.0", 6 | "scripts": { 7 | "prestart": "STANDALONE_SAMPLE_BUILD=1 vite build", 8 | "start": "vite preview", 9 | "dev": "vite", 10 | "build": "vite build", 11 | "preview": "vite preview" 12 | }, 13 | "dependencies": { 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-router-dom": "5.2.0", 17 | "@okta/okta-auth-js": "*", 18 | "@okta/okta-signin-widget": "^6.7.1", 19 | "@okta/okta-react": "*" 20 | }, 21 | "devDependencies": { 22 | "@vitejs/plugin-react": "^1.3.2", 23 | "vite": "^2.8.0", 24 | "dotenv": "^16.0.0" 25 | } 26 | } -------------------------------------------------------------------------------- /samples/doc-embedded-widget/src/Home.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Link, useHistory } from 'react-router-dom'; 15 | import { useOktaAuth } from '@okta/okta-react'; 16 | 17 | const Home = () => { 18 | const { authState, oktaAuth } = useOktaAuth(); 19 | const history = useHistory(); 20 | 21 | const handleLogin = () => { 22 | history.push('/login'); 23 | }; 24 | 25 | const handleLogout = () => { 26 | oktaAuth.signOut(); 27 | }; 28 | 29 | if (!authState) { 30 | return
Loading...
; 31 | } 32 | 33 | return ( 34 |
35 | Home 36 |
37 | Protected 38 |
39 | { 40 | authState.isAuthenticated 41 | ? 42 | : 43 | } 44 |
45 | ); 46 | }; 47 | 48 | export default Home; 49 | -------------------------------------------------------------------------------- /samples/doc-embedded-widget/src/Login.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Redirect } from 'react-router-dom'; 15 | import { useOktaAuth } from '@okta/okta-react'; 16 | import OktaSignInWidget from './OktaSignInWidget'; 17 | 18 | const Login = ({ config }) => { 19 | const { oktaAuth, authState } = useOktaAuth(); 20 | const onSuccess = (tokens) => { 21 | oktaAuth.handleLoginRedirect(tokens); 22 | }; 23 | 24 | const onError = (err) => { 25 | console.log('error logging in', err); 26 | }; 27 | 28 | if (!authState) { 29 | return
Loading...
; 30 | } 31 | 32 | return authState.isAuthenticated 33 | ? 34 | : ; 35 | }; 36 | 37 | export default Login; 38 | -------------------------------------------------------------------------------- /samples/doc-embedded-widget/src/OktaSignInWidget.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React, { useEffect, useRef } from 'react'; 14 | import OktaSignIn from '@okta/okta-signin-widget'; 15 | import '@okta/okta-signin-widget/dist/css/okta-sign-in.min.css'; 16 | import config from './config'; 17 | 18 | const OktaSignInWidget = ({ onSuccess, onError }) => { 19 | const widgetRef = useRef(); 20 | useEffect(() => { 21 | if (!widgetRef.current) { 22 | return false; 23 | } 24 | 25 | const widget = new OktaSignIn(config.widget); 26 | widget 27 | .showSignInToGetTokens({ el: widgetRef.current }) 28 | .then(onSuccess) 29 | .catch(onError); 30 | 31 | return () => widget.remove(); 32 | }, [onSuccess, onError]); 33 | 34 | return (
); 35 | }; 36 | 37 | export default OktaSignInWidget; 38 | -------------------------------------------------------------------------------- /samples/doc-embedded-widget/src/Protected.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | 15 | const Home = () =>

Protected

; 16 | 17 | export default Home; 18 | -------------------------------------------------------------------------------- /samples/doc-embedded-widget/src/index.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import ReactDOM from 'react-dom'; 15 | import { BrowserRouter as Router } from 'react-router-dom'; 16 | import App from './App'; 17 | 18 | ReactDOM.render( 19 | 20 | 21 | , 22 | document.getElementById('root'), 23 | ); 24 | -------------------------------------------------------------------------------- /samples/okta-hosted-login/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | 26 | package-lock.json 27 | yarn.lock 28 | 29 | -------------------------------------------------------------------------------- /samples/okta-hosted-login/bs-config.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | module.exports = { 4 | port: process.env.PORT || 8080, 5 | logLevel: 'silent', 6 | files: ['./dist/**/*.{html,htm,css,js}'], 7 | server: { 8 | baseDir: './dist', 9 | middleware: { 10 | 0: null 11 | } 12 | }, 13 | open: false 14 | }; 15 | -------------------------------------------------------------------------------- /samples/okta-hosted-login/env/index.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | export default function () { 4 | let oktaEnv; 5 | try { 6 | oktaEnv = require('@okta/env'); 7 | } catch (err) { 8 | if (err.code === 'MODULE_NOT_FOUND') { 9 | // try local env module 10 | oktaEnv = require('./okta-env'); 11 | return oktaEnv; 12 | } 13 | 14 | throw err; 15 | } 16 | 17 | return oktaEnv; 18 | } 19 | -------------------------------------------------------------------------------- /samples/okta-hosted-login/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/okta-hosted-login/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'", 3 | "name": "@okta/samples.react.okta-hosted-login", 4 | "private": true, 5 | "version": "0.3.0", 6 | "scripts": { 7 | "prestart": "STANDALONE_SAMPLE_BUILD=1 vite build", 8 | "start": "vite preview", 9 | "dev": "vite", 10 | "build": "vite build", 11 | "preview": "vite preview" 12 | }, 13 | "dependencies": { 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-router-dom": "5.2.0", 17 | "@okta/okta-auth-js": "*", 18 | "semantic-ui-css": "2.4.1", 19 | "semantic-ui-react": "2.0.3", 20 | "text-encoding": "0.7.0", 21 | "@okta/okta-react": "*" 22 | }, 23 | "devDependencies": { 24 | "@vitejs/plugin-react": "^1.3.2", 25 | "vite": "^2.8.0", 26 | "dotenv": "^16.0.0" 27 | } 28 | } -------------------------------------------------------------------------------- /samples/okta-hosted-login/src/App.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | .App { 14 | text-align: center; 15 | } 16 | 17 | .App-logo { 18 | animation: App-logo-spin infinite 20s linear; 19 | height: 80px; 20 | } 21 | 22 | .App-header { 23 | background-color: #222; 24 | height: 150px; 25 | padding: 20px; 26 | color: white; 27 | } 28 | 29 | .App-title { 30 | font-size: 1.5em; 31 | } 32 | 33 | .App-intro { 34 | font-size: large; 35 | } 36 | 37 | @keyframes App-logo-spin { 38 | from { transform: rotate(0deg); } 39 | to { transform: rotate(360deg); } 40 | } 41 | -------------------------------------------------------------------------------- /samples/okta-hosted-login/src/App.test.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import ReactDOM from 'react-dom'; 15 | import { MemoryRouter } from 'react-router-dom'; 16 | import { act } from 'react-dom/test-utils'; 17 | import App from './App'; 18 | 19 | let container; 20 | beforeEach(() => { 21 | container = document.createElement('div'); 22 | document.body.appendChild(container); 23 | }); 24 | 25 | afterEach(() => { 26 | document.body.removeChild(container); 27 | container = null; 28 | }); 29 | 30 | it('renders title link', async () => { 31 | await act(async () => { 32 | ReactDOM.render(, container); 33 | }); 34 | 35 | const linkElement = container.querySelector('a'); 36 | expect(linkElement.textContent.trim()).toBe('Okta-React Sample Project'); 37 | }); 38 | -------------------------------------------------------------------------------- /samples/okta-hosted-login/src/config.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | const CLIENT_ID = process.env.CLIENT_ID || '{clientId}'; 14 | const ISSUER = process.env.ISSUER || 'https://{yourOktaDomain}.com/oauth2/default'; 15 | const OKTA_TESTING_DISABLEHTTPSCHECK = process.env.OKTA_TESTING_DISABLEHTTPSCHECK || false; 16 | const BASENAME = import.meta.env.BASE_URL || ''; 17 | // BASENAME includes trailing slash 18 | const REDIRECT_URI = `${window.location.origin}${BASENAME}login/callback`; 19 | 20 | export default { 21 | oidc: { 22 | clientId: CLIENT_ID, 23 | issuer: ISSUER, 24 | redirectUri: REDIRECT_URI, 25 | scopes: ['openid', 'profile', 'email'], 26 | pkce: true, 27 | disableHttpsCheck: OKTA_TESTING_DISABLEHTTPSCHECK, 28 | }, 29 | resourceServer: { 30 | messagesUrl: 'http://localhost:8000/api/messages', 31 | }, 32 | app: { 33 | basename: BASENAME, 34 | }, 35 | }; 36 | -------------------------------------------------------------------------------- /samples/okta-hosted-login/src/index.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | body { 14 | margin: 0; 15 | padding: 0; 16 | font-family: sans-serif; 17 | } -------------------------------------------------------------------------------- /samples/okta-hosted-login/src/index.jsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import ReactDOM from 'react-dom'; 15 | import { BrowserRouter as Router } from 'react-router-dom'; 16 | import 'semantic-ui-css/semantic.min.css'; 17 | import './polyfills'; 18 | import App from './App'; 19 | import config from './config'; 20 | import './index.css'; 21 | 22 | /* eslint-disable react/jsx-filename-extension */ 23 | ReactDOM.render( 24 | 25 | 26 | , 27 | document.getElementById('root'), 28 | ); 29 | -------------------------------------------------------------------------------- /samples/okta-hosted-login/src/polyfills.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | // polyfill TextEncoder for IE Edge 14 | import { TextEncoder } from 'text-encoding'; 15 | 16 | if (typeof window.TextEncoder === 'undefined') { 17 | window.TextEncoder = TextEncoder; 18 | } 19 | -------------------------------------------------------------------------------- /samples/routing/reach-router/README.md: -------------------------------------------------------------------------------- 1 | # Okta Reach Router Sample App 2 | 3 | Sample app to demonstrate how to use `reach-router` with `@okta/okta-react`. 4 | 5 | ## Install 6 | ```bash 7 | $ git clone https://github.com/okta/okta-react.git 8 | $ yarn 9 | ``` 10 | 11 | ## Configure 12 | Add an `testenv` file with the following fields 13 | ``` 14 | CLIENT_ID= 15 | ISSUER= 16 | ``` 17 | 18 | ## Start 19 | ```bash 20 | $ yarn workspace @okta/samples.react.reach-router start 21 | ``` 22 | OR 23 | ```bash 24 | $ cd ./samples/reach-router 25 | $ yarn start 26 | ``` 27 | -------------------------------------------------------------------------------- /samples/routing/reach-router/bs-config.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | module.exports = { 4 | port: process.env.PORT || 8080, 5 | logLevel: 'silent', 6 | files: ['./dist/**/*.{html,htm,css,js}'], 7 | server: { 8 | baseDir: './dist', 9 | middleware: { 10 | 0: null 11 | } 12 | }, 13 | open: false 14 | }; 15 | -------------------------------------------------------------------------------- /samples/routing/reach-router/env/index.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | export default function () { 4 | let oktaEnv; 5 | try { 6 | oktaEnv = require('@okta/env'); 7 | } catch (err) { 8 | if (err.code === 'MODULE_NOT_FOUND') { 9 | // try local env module 10 | oktaEnv = require('./okta-env'); 11 | return oktaEnv; 12 | } 13 | 14 | throw err; 15 | } 16 | 17 | return oktaEnv; 18 | } 19 | -------------------------------------------------------------------------------- /samples/routing/reach-router/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Reach Router Sample 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/routing/reach-router/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'", 3 | "name": "@okta/samples.react.reach-router", 4 | "private": true, 5 | "version": "0.3.0", 6 | "scripts": { 7 | "prestart": "STANDALONE_SAMPLE_BUILD=1 vite build", 8 | "start": "vite preview", 9 | "dev": "vite", 10 | "build": "vite build", 11 | "preview": "vite preview" 12 | }, 13 | "dependencies": { 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-router-dom": "5.3.0", 17 | "@okta/okta-auth-js": "*", 18 | "@reach/router":"^1.3.4", 19 | "@types/reach__router": "^1.3.4", 20 | "@okta/okta-react": "*" 21 | }, 22 | "devDependencies": { 23 | "@vitejs/plugin-react": "^1.3.2", 24 | "vite": "^2.8.0", 25 | "dotenv": "^16.0.0" 26 | } 27 | } -------------------------------------------------------------------------------- /samples/routing/reach-router/src/App.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | 15 | import { navigate } from '@reach/router'; 16 | import { Security } from '@okta/okta-react'; 17 | import { OktaAuth, toRelativeUrl } from '@okta/okta-auth-js'; 18 | import config from './config'; 19 | 20 | import Footer from './components/Footer'; 21 | import Nav from './components/Nav'; 22 | import Routes from './components/Routes'; 23 | 24 | const oktaAuth = new OktaAuth(config.oidc); 25 | 26 | function App() { 27 | const restoreOriginalUri = (_oktaAuth: any, originalUri: string) => { 28 | navigate(toRelativeUrl(originalUri || '/', window.location.origin), { replace: true }); 29 | }; 30 | 31 | return ( 32 | 33 |
34 |
35 |
37 |
38 | 39 |
40 |
41 |
42 |
43 | ); 44 | } 45 | 46 | export default App; 47 | -------------------------------------------------------------------------------- /samples/routing/reach-router/src/components/Footer.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { useOktaAuth } from '@okta/okta-react'; 15 | 16 | function Footer() { 17 | const { authState, oktaAuth } = useOktaAuth(); 18 | 19 | const handleLogin = () => oktaAuth.signInWithRedirect(); 20 | const handleLogout = () => oktaAuth.signOut(); 21 | 22 | return ( 23 |
24 |
25 | { 26 | !authState || !authState?.isAuthenticated ? 27 | ( 28 | <> 29 |

Please log in

30 | 31 | 32 | ) : 33 | ( 34 | <> 35 |

You're logged in!

36 | 37 | 38 | ) 39 | } 40 |
41 | ); 42 | } 43 | 44 | export default Footer; 45 | -------------------------------------------------------------------------------- /samples/routing/reach-router/src/components/Loading.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | 15 | const Loading: React.FC = () => { 16 | return ( 17 |

Loading...

18 | ); 19 | }; 20 | 21 | export default Loading; 22 | -------------------------------------------------------------------------------- /samples/routing/reach-router/src/components/Nav.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Link } from '@reach/router'; 15 | 16 | const Nav = () => { 17 | return ( 18 | 22 | ); 23 | } 24 | 25 | export default Nav; 26 | -------------------------------------------------------------------------------- /samples/routing/reach-router/src/components/Routes.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Router, RouteComponentProps } from '@reach/router'; 15 | import { LoginCallback } from '@okta/okta-react'; 16 | import { SecureRoutes } from './SecureRoutes'; 17 | 18 | import Home from '../pages/Home'; 19 | import Protected from '../pages/Protected'; 20 | import Loading from './Loading'; 21 | 22 | const OktaLoginCallback: React.FC = () => (} />); 23 | 24 | const AppRoutes = () => { 25 | return ( 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | ); 34 | }; 35 | 36 | export default AppRoutes; 37 | -------------------------------------------------------------------------------- /samples/routing/reach-router/src/config.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | const CLIENT_ID = process.env.CLIENT_ID || '{clientId}'; 14 | const ISSUER = process.env.ISSUER || 'https://{yourOktaDomain}.com/oauth2/default'; 15 | const OKTA_TESTING_DISABLEHTTPSCHECK = process.env.OKTA_TESTING_DISABLEHTTPSCHECK || false; 16 | const BASENAME = process.env.PUBLIC_URL || ''; 17 | const REDIRECT_URI = `${window.location.origin}${BASENAME}/login/callback`; 18 | 19 | export default { 20 | oidc: { 21 | clientId: CLIENT_ID, 22 | issuer: ISSUER, 23 | redirectUri: REDIRECT_URI, 24 | scopes: ['openid', 'profile', 'email'], 25 | pkce: true, 26 | disableHttpsCheck: OKTA_TESTING_DISABLEHTTPSCHECK, 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /samples/routing/reach-router/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | background-color: #282c34; 9 | min-height: 100vh; 10 | display: flex; 11 | flex-direction: column; 12 | align-items: center; 13 | justify-content: center; 14 | font-size: calc(10px + 2vmin); 15 | color: white; 16 | } 17 | 18 | code { 19 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 20 | monospace; 21 | } 22 | 23 | .App { 24 | text-align: center; 25 | } 26 | 27 | .App-logo { 28 | height: 40vmin; 29 | pointer-events: none; 30 | } 31 | 32 | @media (prefers-reduced-motion: no-preference) { 33 | .App-logo { 34 | animation: App-logo-spin infinite 20s linear; 35 | } 36 | } 37 | 38 | .App-link, a { 39 | color: #61dafb; 40 | padding: 0 5px; 41 | } 42 | 43 | @keyframes App-logo-spin { 44 | from { 45 | transform: rotate(0deg); 46 | } 47 | to { 48 | transform: rotate(360deg); 49 | } 50 | } 51 | 52 | form label { 53 | margin: 0 5px; 54 | } -------------------------------------------------------------------------------- /samples/routing/reach-router/src/index.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import ReactDOM from 'react-dom'; 15 | import './index.css'; 16 | import App from './App'; 17 | 18 | 19 | ReactDOM.render( 20 | 21 | 22 | , 23 | document.getElementById('root') 24 | ); 25 | -------------------------------------------------------------------------------- /samples/routing/reach-router/src/pages/Home.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { RouteComponentProps } from '@reach/router'; 15 | 16 | import logo from '../assets/logo.svg'; 17 | 18 | const Home: React.FC = () => { 19 | return ( 20 | <> 21 |

Home

22 | logo 23 | 24 | ); 25 | }; 26 | 27 | export default Home; -------------------------------------------------------------------------------- /samples/routing/reach-router/src/pages/Protected.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { RouteComponentProps } from '@reach/router'; 15 | 16 | import logo from '../assets/logo.svg'; 17 | 18 | const Protected: React.FC = () => { 19 | return ( 20 | <> 21 |

Protected

22 | logo 23 | 24 | ); 25 | }; 26 | 27 | export default Protected; -------------------------------------------------------------------------------- /samples/routing/reach-router/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | /// 14 | -------------------------------------------------------------------------------- /samples/routing/reach-router/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": false, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["src"], 20 | "references": [{ "path": "./tsconfig.node.json" }] 21 | } 22 | -------------------------------------------------------------------------------- /samples/routing/reach-router/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "esnext", 5 | "moduleResolution": "node" 6 | }, 7 | "include": ["vite.config.ts"] 8 | } 9 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/README.md: -------------------------------------------------------------------------------- 1 | # Okta React Router DOM v5 HashRouter Sample App 2 | 3 | Sample app to demonstrate how to use `react-router-dom` v5 with `@okta/okta-react`. 4 | 5 | ## Install 6 | ```bash 7 | $ git clone https://github.com/okta/okta-react.git 8 | $ yarn 9 | ``` 10 | 11 | ## Configure 12 | Add an `testenv` file with the following fields 13 | ``` 14 | CLIENT_ID= 15 | ISSUER= 16 | ``` 17 | 18 | ## Start 19 | ```bash 20 | $ yarn workspace @okta/samples.react.react-router-dom-v5-hash start 21 | ``` 22 | OR 23 | ```bash 24 | $ cd ./samples/react-router-dom-v5-hash 25 | $ yarn start 26 | ``` 27 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/bs-config.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | module.exports = { 4 | port: process.env.PORT || 8080, 5 | logLevel: 'silent', 6 | files: ['./dist/**/*.{html,htm,css,js}'], 7 | server: { 8 | baseDir: './dist', 9 | middleware: { 10 | 0: null 11 | } 12 | }, 13 | open: false 14 | }; 15 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/env/index.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | export default function () { 4 | let oktaEnv; 5 | try { 6 | oktaEnv = require('@okta/env'); 7 | } catch (err) { 8 | if (err.code === 'MODULE_NOT_FOUND') { 9 | // try local env module 10 | oktaEnv = require('./okta-env'); 11 | return oktaEnv; 12 | } 13 | 14 | throw err; 15 | } 16 | 17 | return oktaEnv; 18 | } 19 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | React Router v5 HashRouter Sample 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'", 3 | "name": "@okta/samples.react.react-router-dom-v5-hash", 4 | "private": true, 5 | "version": "0.3.0", 6 | "scripts": { 7 | "prestart": "STANDALONE_SAMPLE_BUILD=1 vite build", 8 | "start": "vite preview", 9 | "dev": "vite", 10 | "build": "vite build", 11 | "preview": "vite preview" 12 | }, 13 | "dependencies": { 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-router-dom": "5.3.0", 17 | "@okta/okta-auth-js": "*", 18 | "@okta/okta-react": "*" 19 | }, 20 | "devDependencies": { 21 | "@vitejs/plugin-react": "^1.3.2", 22 | "vite": "^2.8.0", 23 | "dotenv": "^16.0.0" 24 | } 25 | } -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/src/components/Footer.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { useOktaAuth } from '@okta/okta-react'; 15 | 16 | function Footer() { 17 | const { authState, oktaAuth } = useOktaAuth(); 18 | 19 | const handleLogin = () => oktaAuth.signInWithRedirect(); 20 | const handleLogout = () => oktaAuth.signOut(); 21 | 22 | return ( 23 |
24 |
25 | { 26 | !authState || !authState.isAuthenticated ? 27 | ( 28 | <> 29 |

Please log in

30 | 31 | 32 | ) : 33 | ( 34 | <> 35 |

You're logged in!

36 | 37 | 38 | ) 39 | } 40 |
41 | ); 42 | } 43 | 44 | export default Footer; 45 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/src/components/Loading.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | 15 | const Loading: React.FC = () => { 16 | return ( 17 |

Loading...

18 | ); 19 | }; 20 | 21 | export default Loading; 22 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/src/components/Nav.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Link } from 'react-router-dom'; 15 | 16 | const Nav = () => { 17 | return ( 18 | 22 | ); 23 | } 24 | 25 | export default Nav; 26 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/src/components/Routes.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Switch, Route } from 'react-router-dom'; 15 | import { SecureRoute } from './SecureRoute'; 16 | 17 | import Home from '../pages/Home'; 18 | import Protected from '../pages/Protected'; 19 | import LoginCallback from './LoginCallback'; 20 | import Loading from './Loading'; 21 | 22 | 23 | // NOTE: `loginCallback` *must* be mounted on '/', as it matches the signIn redirect url 24 | const AppRoutes = () => { 25 | return ( 26 | 27 | (} />)} /> 28 | 29 | 30 | 31 | ); 32 | }; 33 | 34 | export default AppRoutes; 35 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/src/config.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | const CLIENT_ID = process.env.CLIENT_ID || '{clientId}'; 14 | const ISSUER = process.env.ISSUER || 'https://{yourOktaDomain}.com/oauth2/default'; 15 | const OKTA_TESTING_DISABLEHTTPSCHECK = process.env.OKTA_TESTING_DISABLEHTTPSCHECK || false; 16 | const BASENAME = process.env.PUBLIC_URL || ''; 17 | const REDIRECT_URI = `${window.location.origin}${BASENAME}/login/callback`; 18 | 19 | export default { 20 | oidc: { 21 | clientId: CLIENT_ID, 22 | issuer: ISSUER, 23 | redirectUri: REDIRECT_URI, 24 | scopes: ['openid', 'profile', 'email'], 25 | pkce: true, 26 | disableHttpsCheck: OKTA_TESTING_DISABLEHTTPSCHECK, 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | background-color: #282c34; 9 | min-height: 100vh; 10 | display: flex; 11 | flex-direction: column; 12 | align-items: center; 13 | justify-content: center; 14 | font-size: calc(10px + 2vmin); 15 | color: white; 16 | } 17 | 18 | code { 19 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 20 | monospace; 21 | } 22 | 23 | .App { 24 | text-align: center; 25 | } 26 | 27 | .App-logo { 28 | height: 40vmin; 29 | pointer-events: none; 30 | } 31 | 32 | @media (prefers-reduced-motion: no-preference) { 33 | .App-logo { 34 | animation: App-logo-spin infinite 20s linear; 35 | } 36 | } 37 | 38 | .App-link, a { 39 | color: #61dafb; 40 | padding: 0 5px; 41 | } 42 | 43 | @keyframes App-logo-spin { 44 | from { 45 | transform: rotate(0deg); 46 | } 47 | to { 48 | transform: rotate(360deg); 49 | } 50 | } 51 | 52 | form label { 53 | margin: 0 5px; 54 | } -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/src/index.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import ReactDOM from 'react-dom'; 15 | import './index.css'; 16 | import App from './App'; 17 | import { HashRouter } from "react-router-dom"; 18 | 19 | 20 | ReactDOM.render( 21 | 22 | 23 | 24 | 25 | , 26 | document.getElementById('root') 27 | ); 28 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/src/pages/Home.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import logo from '../assets/logo.svg'; 15 | 16 | const Home = () => { 17 | return ( 18 | <> 19 |

Home

20 | logo 21 | 22 | ); 23 | }; 24 | 25 | export default Home; -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/src/pages/Protected.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import logo from '../assets/logo.svg'; 15 | 16 | const Protected = () => { 17 | return ( 18 | <> 19 |

Protected

20 | logo 21 | 22 | ); 23 | }; 24 | 25 | export default Protected; -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | /// 14 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": false, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["src"], 20 | "references": [{ "path": "./tsconfig.node.json" }] 21 | } 22 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5-hash/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "esnext", 5 | "moduleResolution": "node" 6 | }, 7 | "include": ["vite.config.ts"] 8 | } 9 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/README.md: -------------------------------------------------------------------------------- 1 | # Okta React Router DOM v5 Sample App 2 | 3 | Sample app to demonstrate how to use `react-router-dom` v5 with `@okta/okta-react`. 4 | 5 | ## Install 6 | ```bash 7 | $ git clone https://github.com/okta/okta-react.git 8 | $ yarn 9 | ``` 10 | 11 | ## Configure 12 | Add an `testenv` file with the following fields 13 | ``` 14 | CLIENT_ID= 15 | ISSUER= 16 | ``` 17 | 18 | ## Start 19 | ```bash 20 | $ yarn workspace @okta/samples.react.react-router-dom-v5 start 21 | ``` 22 | OR 23 | ```bash 24 | $ cd ./samples/react-router-dom-v5 25 | $ yarn start 26 | ``` 27 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/bs-config.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | module.exports = { 4 | port: process.env.PORT || 8080, 5 | logLevel: 'silent', 6 | files: ['./dist/**/*.{html,htm,css,js}'], 7 | server: { 8 | baseDir: './dist', 9 | middleware: { 10 | 0: null 11 | } 12 | }, 13 | open: false 14 | }; 15 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/env/index.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | export default function () { 4 | let oktaEnv; 5 | try { 6 | oktaEnv = require('@okta/env'); 7 | } catch (err) { 8 | if (err.code === 'MODULE_NOT_FOUND') { 9 | // try local env module 10 | oktaEnv = require('./okta-env'); 11 | return oktaEnv; 12 | } 13 | 14 | throw err; 15 | } 16 | 17 | return oktaEnv; 18 | } 19 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | React Router v5 Sample 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'", 3 | "name": "@okta/samples.react.react-router-dom-v5", 4 | "private": true, 5 | "version": "0.3.0", 6 | "scripts": { 7 | "prestart": "STANDALONE_SAMPLE_BUILD=1 vite build", 8 | "start": "vite preview", 9 | "dev": "vite", 10 | "build": "vite build", 11 | "preview": "vite preview" 12 | }, 13 | "dependencies": { 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-router-dom": "5.3.0", 17 | "@okta/okta-auth-js": "*", 18 | "@okta/okta-react": "*" 19 | }, 20 | "devDependencies": { 21 | "@vitejs/plugin-react": "^1.3.2", 22 | "vite": "^2.8.0", 23 | "dotenv": "^16.0.0" 24 | } 25 | } -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/src/App.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | 15 | import { useHistory } from 'react-router-dom'; 16 | import { Security } from '@okta/okta-react'; 17 | import { OktaAuth, toRelativeUrl } from '@okta/okta-auth-js'; 18 | import config from './config'; 19 | 20 | import Footer from './components/Footer'; 21 | import Nav from './components/Nav'; 22 | import Routes from './components/Routes'; 23 | 24 | 25 | const oktaAuth = new OktaAuth(config.oidc); 26 | 27 | function App() { 28 | const history = useHistory(); 29 | const restoreOriginalUri = (_oktaAuth: any, originalUri: string) => { 30 | history.replace(toRelativeUrl(originalUri || '/', window.location.origin)); 31 | }; 32 | 33 | return ( 34 | 35 |
36 |
37 |
39 |
40 | 41 |
42 |
43 |
44 |
45 | ); 46 | } 47 | 48 | export default App; 49 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/src/components/Footer.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { useOktaAuth } from '@okta/okta-react'; 15 | 16 | function Footer() { 17 | const { authState, oktaAuth } = useOktaAuth(); 18 | 19 | const handleLogin = () => oktaAuth.signInWithRedirect(); 20 | const handleLogout = () => oktaAuth.signOut(); 21 | 22 | return ( 23 |
24 |
25 | { 26 | !authState || !authState.isAuthenticated ? 27 | ( 28 | <> 29 |

Please log in

30 | 31 | 32 | ) : 33 | ( 34 | <> 35 |

You're logged in!

36 | 37 | 38 | ) 39 | } 40 |
41 | ); 42 | } 43 | 44 | export default Footer; 45 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/src/components/Loading.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | 15 | const Loading: React.FC = () => { 16 | return ( 17 |

Loading...

18 | ); 19 | }; 20 | 21 | export default Loading; 22 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/src/components/Nav.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Link } from 'react-router-dom'; 15 | 16 | const Nav = () => { 17 | return ( 18 | 22 | ); 23 | } 24 | 25 | export default Nav; 26 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/src/components/Routes.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Switch, Route } from 'react-router-dom'; 15 | import { LoginCallback } from '@okta/okta-react'; 16 | import { SecureRoute } from './SecureRoute'; 17 | 18 | import Home from '../pages/Home'; 19 | import Protected from '../pages/Protected'; 20 | import Loading from './Loading'; 21 | 22 | const AppRoutes = () => { 23 | return ( 24 | 25 | 26 | (} />)} /> 27 | 28 | 29 | ); 30 | }; 31 | 32 | export default AppRoutes; 33 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/src/config.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | const CLIENT_ID = process.env.CLIENT_ID || '{clientId}'; 14 | const ISSUER = process.env.ISSUER || 'https://{yourOktaDomain}.com/oauth2/default'; 15 | const OKTA_TESTING_DISABLEHTTPSCHECK = process.env.OKTA_TESTING_DISABLEHTTPSCHECK || false; 16 | const BASENAME = process.env.PUBLIC_URL || ''; 17 | const REDIRECT_URI = `${window.location.origin}${BASENAME}/login/callback`; 18 | 19 | export default { 20 | oidc: { 21 | clientId: CLIENT_ID, 22 | issuer: ISSUER, 23 | redirectUri: REDIRECT_URI, 24 | scopes: ['openid', 'profile', 'email'], 25 | pkce: true, 26 | disableHttpsCheck: OKTA_TESTING_DISABLEHTTPSCHECK, 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | background-color: #282c34; 9 | min-height: 100vh; 10 | display: flex; 11 | flex-direction: column; 12 | align-items: center; 13 | justify-content: center; 14 | font-size: calc(10px + 2vmin); 15 | color: white; 16 | } 17 | 18 | code { 19 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 20 | monospace; 21 | } 22 | 23 | .App { 24 | text-align: center; 25 | } 26 | 27 | .App-logo { 28 | height: 40vmin; 29 | pointer-events: none; 30 | } 31 | 32 | @media (prefers-reduced-motion: no-preference) { 33 | .App-logo { 34 | animation: App-logo-spin infinite 20s linear; 35 | } 36 | } 37 | 38 | .App-link, a { 39 | color: #61dafb; 40 | padding: 0 5px; 41 | } 42 | 43 | @keyframes App-logo-spin { 44 | from { 45 | transform: rotate(0deg); 46 | } 47 | to { 48 | transform: rotate(360deg); 49 | } 50 | } 51 | 52 | form label { 53 | margin: 0 5px; 54 | } -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/src/index.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import ReactDOM from 'react-dom'; 15 | import './index.css'; 16 | import App from './App'; 17 | import { BrowserRouter } from "react-router-dom"; 18 | 19 | 20 | ReactDOM.render( 21 | 22 | 23 | 24 | 25 | , 26 | document.getElementById('root') 27 | ); 28 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/src/pages/Home.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import logo from '../assets/logo.svg'; 15 | 16 | const Home = () => { 17 | return ( 18 | <> 19 |

Home

20 | logo 21 | 22 | ); 23 | }; 24 | 25 | export default Home; -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/src/pages/Protected.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import logo from '../assets/logo.svg'; 15 | 16 | const Protected = () => { 17 | return ( 18 | <> 19 |

Protected

20 | logo 21 | 22 | ); 23 | }; 24 | 25 | export default Protected; -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | /// 14 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": false, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["src"], 20 | "references": [{ "path": "./tsconfig.node.json" }] 21 | } 22 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v5/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "esnext", 5 | "moduleResolution": "node" 6 | }, 7 | "include": ["vite.config.ts"] 8 | } 9 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/README.md: -------------------------------------------------------------------------------- 1 | # Okta React Router DOM v6 HashRouter Sample App 2 | 3 | Sample app to demonstrate how to use `react-router-dom` v6 with `@okta/okta-react`. 4 | 5 | **NOTE:** This sample is not runnable before fixing issue [#187](https://github.com/okta/okta-react/issues/187). See [this comment](https://github.com/okta/okta-react/issues/187#issuecomment-1043059092) for potential workaround. 6 | 7 | ## Install 8 | ```bash 9 | $ git clone https://github.com/okta/okta-react.git 10 | $ yarn 11 | ``` 12 | 13 | ## Configure 14 | Add an `testenv` file with the following fields 15 | ``` 16 | CLIENT_ID= 17 | ISSUER= 18 | ``` 19 | 20 | ## Start 21 | ```bash 22 | $ yarn workspace @okta/samples.react.react-router-dom-v6-hash start 23 | ``` 24 | OR 25 | ```bash 26 | $ cd ./samples/react-router-dom-v6-hash 27 | $ yarn start 28 | ``` 29 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/bs-config.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | module.exports = { 4 | port: process.env.PORT || 8080, 5 | logLevel: 'silent', 6 | files: ['./dist/**/*.{html,htm,css,js}'], 7 | server: { 8 | baseDir: './dist', 9 | middleware: { 10 | 0: null 11 | } 12 | }, 13 | open: false 14 | }; 15 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/env/index.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | export default function () { 4 | let oktaEnv; 5 | try { 6 | oktaEnv = require('@okta/env'); 7 | } catch (err) { 8 | if (err.code === 'MODULE_NOT_FOUND') { 9 | // try local env module 10 | oktaEnv = require('./okta-env'); 11 | return oktaEnv; 12 | } 13 | 14 | throw err; 15 | } 16 | 17 | return oktaEnv; 18 | } 19 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | React Router v6 HashRouter Sample 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'", 3 | "name": "@okta/samples.react.react-router-dom-v6-hash", 4 | "private": true, 5 | "version": "0.3.0", 6 | "scripts": { 7 | "prestart": "STANDALONE_SAMPLE_BUILD=1 vite build", 8 | "start": "vite preview", 9 | "dev": "vite", 10 | "build": "vite build", 11 | "preview": "vite preview" 12 | }, 13 | "dependencies": { 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-router-dom": "6.2.1", 17 | "@okta/okta-auth-js": "*", 18 | "@okta/okta-react": "*" 19 | }, 20 | "devDependencies": { 21 | "@vitejs/plugin-react": "^1.3.2", 22 | "vite": "^2.8.0", 23 | "dotenv": "^16.0.0" 24 | } 25 | } -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/src/components/Footer.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { useOktaAuth } from '@okta/okta-react'; 15 | 16 | 17 | function Footer() { 18 | const { authState, oktaAuth } = useOktaAuth(); 19 | 20 | const handleLogin = () => oktaAuth.signInWithRedirect(); 21 | const handleLogout = () => oktaAuth.signOut(); 22 | 23 | return ( 24 |
25 |
26 | { 27 | !authState || !authState.isAuthenticated ? 28 | ( 29 | <> 30 |

Please log in

31 | 32 | 33 | ) : 34 | ( 35 | <> 36 |

You're logged in!

37 | 38 | 39 | ) 40 | } 41 |
42 | ); 43 | } 44 | 45 | export default Footer; 46 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/src/components/Loading.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | 15 | const Loading: React.FC = () => { 16 | return ( 17 |

Loading...

18 | ); 19 | }; 20 | 21 | export default Loading; 22 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/src/components/Nav.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Link } from 'react-router-dom'; 15 | 16 | const Nav = () => { 17 | return ( 18 | 22 | ); 23 | }; 24 | 25 | export default Nav; 26 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/src/components/Routes.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Routes, Route } from 'react-router-dom'; 15 | import { RequiredAuth } from './SecureRoute'; 16 | 17 | import Home from '../pages/Home'; 18 | import Protected from '../pages/Protected'; 19 | import LoginCallback from './LoginCallback'; 20 | import Loading from './Loading'; 21 | 22 | 23 | // NOTE: `loginCallback` *must* be mounted on '/', as it matches the signIn redirect url 24 | const AppRoutes = () => { 25 | return ( 26 | 27 | } />} /> 28 | } /> 29 | }> 30 | } /> 31 | 32 | 33 | ); 34 | }; 35 | 36 | export default AppRoutes; 37 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/src/components/SecureRoute.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React, { useEffect } from 'react'; 14 | import { useOktaAuth } from '@okta/okta-react'; 15 | import { toRelativeUrl } from '@okta/okta-auth-js'; 16 | import { Outlet } from 'react-router-dom'; 17 | import Loading from './Loading'; 18 | 19 | 20 | export const RequiredAuth: React.FC = () => { 21 | const { oktaAuth, authState } = useOktaAuth(); 22 | 23 | useEffect(() => { 24 | if (!authState) { 25 | return; 26 | } 27 | 28 | if (!authState?.isAuthenticated) { 29 | const originalUri = toRelativeUrl(window.location.href, window.location.origin); 30 | oktaAuth.setOriginalUri(originalUri); 31 | oktaAuth.signInWithRedirect(); 32 | } 33 | }, [oktaAuth, !!authState, authState?.isAuthenticated]); 34 | 35 | if (!authState || !authState?.isAuthenticated) { 36 | return (); 37 | } 38 | 39 | return (); 40 | } 41 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/src/config.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | const CLIENT_ID = process.env.CLIENT_ID || '{clientId}'; 14 | const ISSUER = process.env.ISSUER || 'https://{yourOktaDomain}.com/oauth2/default'; 15 | const OKTA_TESTING_DISABLEHTTPSCHECK = process.env.OKTA_TESTING_DISABLEHTTPSCHECK || false; 16 | const BASENAME = process.env.PUBLIC_URL || ''; 17 | const REDIRECT_URI = `${window.location.origin}${BASENAME}/login/callback`; 18 | 19 | export default { 20 | oidc: { 21 | clientId: CLIENT_ID, 22 | issuer: ISSUER, 23 | redirectUri: REDIRECT_URI, 24 | scopes: ['openid', 'profile', 'email'], 25 | pkce: true, 26 | disableHttpsCheck: OKTA_TESTING_DISABLEHTTPSCHECK, 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | background-color: #282c34; 9 | min-height: 100vh; 10 | display: flex; 11 | flex-direction: column; 12 | align-items: center; 13 | justify-content: center; 14 | font-size: calc(10px + 2vmin); 15 | color: white; 16 | } 17 | 18 | code { 19 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 20 | monospace; 21 | } 22 | 23 | .App { 24 | text-align: center; 25 | } 26 | 27 | .App-logo { 28 | height: 40vmin; 29 | pointer-events: none; 30 | } 31 | 32 | @media (prefers-reduced-motion: no-preference) { 33 | .App-logo { 34 | animation: App-logo-spin infinite 20s linear; 35 | } 36 | } 37 | 38 | .App-link, a { 39 | color: #61dafb; 40 | padding: 0 5px; 41 | } 42 | 43 | @keyframes App-logo-spin { 44 | from { 45 | transform: rotate(0deg); 46 | } 47 | to { 48 | transform: rotate(360deg); 49 | } 50 | } 51 | 52 | form label { 53 | margin: 0 5px; 54 | } -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/src/index.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import ReactDOM from 'react-dom'; 15 | import './index.css'; 16 | import App from './App'; 17 | import { HashRouter } from "react-router-dom"; 18 | 19 | 20 | ReactDOM.render( 21 | 22 | 23 | 24 | 25 | , 26 | document.getElementById('root') 27 | ); 28 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/src/pages/Home.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import logo from '../assets/logo.svg'; 15 | 16 | const Home = () => { 17 | return ( 18 | <> 19 |

Home

20 | logo 21 | 22 | ); 23 | }; 24 | 25 | export default Home; -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/src/pages/Protected.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import logo from '../assets/logo.svg'; 15 | 16 | const Protected = () => { 17 | return ( 18 | <> 19 |

Protected

20 | logo 21 | 22 | ); 23 | }; 24 | 25 | export default Protected; -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | /// 14 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": false, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["src"], 20 | "references": [{ "path": "./tsconfig.node.json" }] 21 | } 22 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6-hash/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "esnext", 5 | "moduleResolution": "node" 6 | }, 7 | "include": ["vite.config.ts"] 8 | } 9 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/README.md: -------------------------------------------------------------------------------- 1 | # Okta React Router DOM v6 Sample App 2 | 3 | Sample app to demonstrate how to use `react-router-dom` v6 with `@okta/okta-react`. 4 | 5 | **NOTE:** This sample is not runnable before fixing issue [#187](https://github.com/okta/okta-react/issues/187). See [this comment](https://github.com/okta/okta-react/issues/187#issuecomment-1043059092) for potential workaround. 6 | 7 | ## Install 8 | ```bash 9 | $ git clone https://github.com/okta/okta-react.git 10 | $ yarn 11 | ``` 12 | 13 | ## Configure 14 | Add an `testenv` file with the following fields 15 | ``` 16 | CLIENT_ID= 17 | ISSUER= 18 | ``` 19 | 20 | ## Start 21 | ```bash 22 | $ yarn workspace @okta/samples.react.react-router-dom-v6 start 23 | ``` 24 | OR 25 | ```bash 26 | $ cd ./samples/react-router-dom-v6 27 | $ yarn start 28 | ``` 29 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/bs-config.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | module.exports = { 4 | port: process.env.PORT || 8080, 5 | logLevel: 'silent', 6 | files: ['./dist/**/*.{html,htm,css,js}'], 7 | server: { 8 | baseDir: './dist', 9 | middleware: { 10 | 0: null 11 | } 12 | }, 13 | open: false 14 | }; 15 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/env/index.js: -------------------------------------------------------------------------------- 1 | // "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'" 2 | 3 | export default function () { 4 | let oktaEnv; 5 | try { 6 | oktaEnv = require('@okta/env'); 7 | } catch (err) { 8 | if (err.code === 'MODULE_NOT_FOUND') { 9 | // try local env module 10 | oktaEnv = require('./okta-env'); 11 | return oktaEnv; 12 | } 13 | 14 | throw err; 15 | } 16 | 17 | return oktaEnv; 18 | } 19 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | React Router v6 Sample 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "IMPORTANT: THIS FILE IS GENERATED, CHANGES SHOULD BE MADE WITHIN '@okta/generator'", 3 | "name": "@okta/samples.react.react-router-dom-v6", 4 | "private": true, 5 | "version": "0.3.0", 6 | "scripts": { 7 | "prestart": "STANDALONE_SAMPLE_BUILD=1 vite build", 8 | "start": "vite preview", 9 | "dev": "vite", 10 | "build": "vite build", 11 | "preview": "vite preview" 12 | }, 13 | "dependencies": { 14 | "react": "^17.0.2", 15 | "react-dom": "^17.0.2", 16 | "react-router-dom": "6.2.1", 17 | "@okta/okta-auth-js": "*", 18 | "@okta/okta-react": "*" 19 | }, 20 | "devDependencies": { 21 | "@vitejs/plugin-react": "^1.3.2", 22 | "vite": "^2.8.0", 23 | "dotenv": "^16.0.0" 24 | } 25 | } -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/App.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | 15 | import { useNavigate } from 'react-router-dom'; 16 | import { Security } from '@okta/okta-react'; 17 | import { OktaAuth, toRelativeUrl } from '@okta/okta-auth-js'; 18 | import config from './config'; 19 | 20 | import Footer from './components/Footer'; 21 | import Nav from './components/Nav'; 22 | import Routes from './components/Routes'; 23 | 24 | const oktaAuth = new OktaAuth(config.oidc); 25 | 26 | function App() { 27 | const navigate = useNavigate(); 28 | const restoreOriginalUri = (_oktaAuth: any, originalUri: string) => { 29 | navigate(toRelativeUrl(originalUri || '/', window.location.origin)); 30 | }; 31 | 32 | return ( 33 | 34 |
35 |
36 |
38 |
39 | 40 |
41 |
42 |
43 |
44 | ); 45 | } 46 | 47 | export default App; 48 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/components/Footer.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { useOktaAuth } from '@okta/okta-react'; 15 | 16 | 17 | function Footer() { 18 | const { authState, oktaAuth } = useOktaAuth(); 19 | 20 | const handleLogin = () => oktaAuth.signInWithRedirect(); 21 | const handleLogout = () => oktaAuth.signOut(); 22 | 23 | return ( 24 |
25 |
26 | { 27 | !authState || !authState.isAuthenticated ? 28 | ( 29 | <> 30 |

Please log in

31 | 32 | 33 | ) : 34 | ( 35 | <> 36 |

You're logged in!

37 | 38 | 39 | ) 40 | } 41 |
42 | ); 43 | } 44 | 45 | export default Footer; 46 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/components/Loading.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | 15 | const Loading: React.FC = () => { 16 | return ( 17 |

Loading...

18 | ); 19 | }; 20 | 21 | export default Loading; 22 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/components/Nav.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Link } from 'react-router-dom'; 15 | 16 | const Nav = () => { 17 | return ( 18 | 22 | ); 23 | }; 24 | 25 | export default Nav; 26 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/components/Routes.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import { Routes, Route } from 'react-router-dom'; 15 | import { LoginCallback } from '@okta/okta-react'; 16 | import { RequiredAuth } from './SecureRoute'; 17 | 18 | import Home from '../pages/Home'; 19 | import Protected from '../pages/Protected'; 20 | import Loading from './Loading'; 21 | 22 | const AppRoutes = () => { 23 | return ( 24 | 25 | } /> 26 | } />} /> 27 | }> 28 | } /> 29 | 30 | 31 | ); 32 | }; 33 | 34 | export default AppRoutes; 35 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/components/SecureRoute.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React, { useEffect } from 'react'; 14 | import { useOktaAuth } from '@okta/okta-react'; 15 | import { toRelativeUrl } from '@okta/okta-auth-js'; 16 | import { Outlet } from 'react-router-dom'; 17 | import Loading from './Loading'; 18 | 19 | export const RequiredAuth: React.FC = () => { 20 | const { oktaAuth, authState } = useOktaAuth(); 21 | 22 | useEffect(() => { 23 | if (!authState) { 24 | return; 25 | } 26 | 27 | if (!authState?.isAuthenticated) { 28 | const originalUri = toRelativeUrl(window.location.href, window.location.origin); 29 | oktaAuth.setOriginalUri(originalUri); 30 | oktaAuth.signInWithRedirect(); 31 | } 32 | }, [oktaAuth, !!authState, authState?.isAuthenticated]); 33 | 34 | if (!authState || !authState?.isAuthenticated) { 35 | return (); 36 | } 37 | 38 | return (); 39 | } 40 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/config.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | const CLIENT_ID = process.env.CLIENT_ID || '{clientId}'; 14 | const ISSUER = process.env.ISSUER || 'https://{yourOktaDomain}.com/oauth2/default'; 15 | const OKTA_TESTING_DISABLEHTTPSCHECK = process.env.OKTA_TESTING_DISABLEHTTPSCHECK || false; 16 | const BASENAME = process.env.PUBLIC_URL || ''; 17 | const REDIRECT_URI = `${window.location.origin}${BASENAME}/login/callback`; 18 | 19 | export default { 20 | oidc: { 21 | clientId: CLIENT_ID, 22 | issuer: ISSUER, 23 | redirectUri: REDIRECT_URI, 24 | scopes: ['openid', 'profile', 'email'], 25 | pkce: true, 26 | disableHttpsCheck: OKTA_TESTING_DISABLEHTTPSCHECK, 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | background-color: #282c34; 9 | min-height: 100vh; 10 | display: flex; 11 | flex-direction: column; 12 | align-items: center; 13 | justify-content: center; 14 | font-size: calc(10px + 2vmin); 15 | color: white; 16 | } 17 | 18 | code { 19 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 20 | monospace; 21 | } 22 | 23 | .App { 24 | text-align: center; 25 | } 26 | 27 | .App-logo { 28 | height: 40vmin; 29 | pointer-events: none; 30 | } 31 | 32 | @media (prefers-reduced-motion: no-preference) { 33 | .App-logo { 34 | animation: App-logo-spin infinite 20s linear; 35 | } 36 | } 37 | 38 | .App-link, a { 39 | color: #61dafb; 40 | padding: 0 5px; 41 | } 42 | 43 | @keyframes App-logo-spin { 44 | from { 45 | transform: rotate(0deg); 46 | } 47 | to { 48 | transform: rotate(360deg); 49 | } 50 | } 51 | 52 | form label { 53 | margin: 0 5px; 54 | } -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/index.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import ReactDOM from 'react-dom'; 15 | import './index.css'; 16 | import App from './App'; 17 | import { BrowserRouter } from "react-router-dom"; 18 | 19 | 20 | ReactDOM.render( 21 | 22 | 23 | 24 | 25 | , 26 | document.getElementById('root') 27 | ); 28 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/pages/Home.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import logo from '../assets/logo.svg'; 15 | 16 | const Home = () => { 17 | return ( 18 | <> 19 |

Home

20 | logo 21 | 22 | ); 23 | }; 24 | 25 | export default Home; -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/pages/Protected.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React from 'react'; 14 | import logo from '../assets/logo.svg'; 15 | 16 | const Protected = () => { 17 | return ( 18 | <> 19 |

Protected

20 | logo 21 | 22 | ); 23 | }; 24 | 25 | export default Protected; -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": false, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["src"], 20 | "references": [{ "path": "./tsconfig.node.json" }] 21 | } 22 | -------------------------------------------------------------------------------- /samples/routing/react-router-dom-v6/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "esnext", 5 | "moduleResolution": "node" 6 | }, 7 | "include": ["vite.config.ts"] 8 | } 9 | -------------------------------------------------------------------------------- /scripts/downstream/create-downstream-for-authjs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # download okta-auth-js artifact version if empty and assign to upstream_artifact_version 4 | if [[ -z "${upstream_artifact_version}" ]]; then 5 | pushd ${OKTA_HOME}/okta-auth-js > /dev/null 6 | download_job_data global artifact_version upstream_artifact_version okta-auth-js ${upstream_artifact_sha} 7 | popd > /dev/null 8 | echo "okta-auth-js version that will be tested: ${upstream_artifact_version}" 9 | fi 10 | 11 | pushd ${OKTA_HOME}/okta-react/scripts > /dev/null 12 | sdk_version_number="$(echo ${upstream_artifact_version} | cut -d'@' -f3)" 13 | echo "Update okta-auth-js version in scripts/setup.sh to ${sdk_version_number}" 14 | sed -i "s/\(AUTHJS_VERSION\=\).*/\1\"${sdk_version_number}\"/g" setup.sh 15 | popd > /dev/null -------------------------------------------------------------------------------- /scripts/e2e-v6.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) 4 | source $DIR/utils/local.sh 5 | source ${OKTA_HOME}/${REPO}/scripts/setup.sh 6 | 7 | if [ ! -z "$AUTHJS_VERSION" ]; then 8 | echo "Skipping e2e tests against auth-js v6.x" 9 | exit ${SUCCESS} 10 | fi 11 | 12 | setup_service java 1.8.222 13 | setup_service google-chrome-stable 106.0.5249.61-1 14 | 15 | export CI=true 16 | export TEST_SUITE_TYPE="junit" 17 | export TEST_RESULT_FILE_DIR="${REPO}/test-reports/e2e" 18 | 19 | export ISSUER=https://samples-javascript.okta.com/oauth2/default 20 | export CLIENT_ID=0oapmwm72082GXal14x6 21 | export SPA_CLIENT_ID=0oapmwm72082GXal14x6 22 | export USERNAME=george@acme.com 23 | get_terminus_secret "/" PASSWORD PASSWORD 24 | export ORG_OIE_ENABLED= 25 | export USE_INTERACTION_CODE= 26 | 27 | # modifies the package.json of all workspaces to the latest 6.x version 28 | ./scripts/utils/sync-ws-auth-js.sh $(yarn info @okta/okta-auth-js@^6 --json | jq '.data.versions | last' | tr -d \") 29 | yarn --ignore-scripts 30 | 31 | if ! yarn test:e2e; then 32 | echo "e2e tests failed! Exiting..." 33 | exit ${TEST_FAILURE} 34 | fi 35 | 36 | echo ${TEST_SUITE_TYPE} > ${TEST_SUITE_TYPE_FILE} 37 | echo ${TEST_RESULT_FILE_DIR} > ${TEST_RESULT_FILE_DIR_FILE} 38 | exit ${PUBLISH_TYPE_AND_RESULT_DIR} 39 | -------------------------------------------------------------------------------- /scripts/e2e.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) 4 | source $DIR/utils/local.sh 5 | source ${OKTA_HOME}/${REPO}/scripts/setup.sh 6 | 7 | setup_service java 1.8.222 8 | setup_service google-chrome-stable 106.0.5249.61-1 9 | 10 | export CI=true 11 | export TEST_SUITE_TYPE="junit" 12 | export TEST_RESULT_FILE_DIR="${REPO}/test-reports/e2e" 13 | 14 | export ISSUER=https://samples-javascript.okta.com/oauth2/default 15 | export CLIENT_ID=0oapmwm72082GXal14x6 16 | export SPA_CLIENT_ID=0oapmwm72082GXal14x6 17 | export USERNAME=george@acme.com 18 | get_terminus_secret "/" PASSWORD PASSWORD 19 | export ORG_OIE_ENABLED= 20 | export USE_INTERACTION_CODE= 21 | 22 | if ! yarn test:e2e; then 23 | echo "e2e tests failed! Exiting..." 24 | exit ${TEST_FAILURE} 25 | fi 26 | 27 | echo ${TEST_SUITE_TYPE} > ${TEST_SUITE_TYPE_FILE} 28 | echo ${TEST_RESULT_FILE_DIR} > ${TEST_RESULT_FILE_DIR_FILE} 29 | exit ${PUBLISH_TYPE_AND_RESULT_DIR} 30 | -------------------------------------------------------------------------------- /scripts/lint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | source ${OKTA_HOME}/${REPO}/scripts/setup.sh 4 | 5 | export TEST_SUITE_TYPE="checkstyle" 6 | export TEST_RESULT_FILE_DIR="${REPO}/test-reports" 7 | 8 | if ! yarn lint:report; then 9 | echo "lint failed! Exiting..." 10 | exit ${TEST_FAILURE} 11 | fi 12 | 13 | echo ${TEST_SUITE_TYPE} > ${TEST_SUITE_TYPE_FILE} 14 | echo ${TEST_RESULT_FILE_DIR} > ${TEST_RESULT_FILE_DIR_FILE} 15 | exit ${PUBLISH_TYPE_AND_RESULT_DIR_BUT_SUCCEED_IF_NO_RESULTS} 16 | -------------------------------------------------------------------------------- /scripts/publish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | source ${OKTA_HOME}/${REPO}/scripts/setup.sh 4 | 5 | REGISTRY="${ARTIFACTORY_URL}/api/npm/npm-topic" 6 | 7 | export TEST_SUITE_TYPE="build" 8 | 9 | # Install required dependencies 10 | export PATH="${PATH}:$(yarn global bin)" 11 | yarn global add @okta/ci-append-sha 12 | yarn global add @okta/ci-pkginfo 13 | 14 | if [ -n "${action_branch}" ]; 15 | then 16 | echo "Publishing from bacon task using branch ${action_branch}" 17 | TARGET_BRANCH=${action_branch} 18 | else 19 | echo "Publishing from bacon testSuite using branch ${BRANCH}" 20 | TARGET_BRANCH=${BRANCH} 21 | fi 22 | 23 | pushd ./dist 24 | 25 | if ! ci-append-sha; then 26 | echo "ci-append-sha failed! Exiting..." 27 | exit ${FAILED_SETUP} 28 | fi 29 | 30 | npm config set @okta:registry ${REGISTRY} 31 | if ! npm publish --registry ${REGISTRY}; then 32 | echo "npm publish failed! Exiting..." 33 | exit ${PUBLISH_ARTIFACTORY_FAILURE} 34 | fi 35 | 36 | FINAL_PUBLISHED_VERSION="$(ci-pkginfo -t pkgsemver)" 37 | log_custom_message "Published Version" "${FINAL_PUBLISHED_VERSION}" 38 | 39 | popd 40 | 41 | exit ${SUCCESS} 42 | -------------------------------------------------------------------------------- /scripts/semgrep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eo pipefail 4 | 5 | cd ${OKTA_HOME}/${REPO} 6 | 7 | if ! sast_scan; 8 | then 9 | exit ${FAILURE} 10 | fi 11 | 12 | exit ${SUCCESS} -------------------------------------------------------------------------------- /scripts/snyk.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # When packages change their dependency tree, we want to run snyk monitor. This 4 | # sends the updated dependency tree to snyk for monitoring. We want to do this 5 | # when a commit has been made to master, not on PRs because the dependency tree 6 | # is likely still in flux while review is happening. 7 | # 8 | # For simplicity, this script just runs snyk monitor against all packages on 9 | # master commits, it doesn't try to figure out which packages were updated. 10 | 11 | if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then 12 | yarn global add snyk 13 | snyk auth $SNYK_API_TOKEN 14 | echo "snyk monitor --org=$SNYK_ORG_ID" 15 | fi 16 | -------------------------------------------------------------------------------- /scripts/travis.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | # if this build was triggered via a cron job, run tests on sauce labs 3 | if [ "${TRAVIS_EVENT_TYPE}" = "cron" ] ; then 4 | yarn pretest 5 | yarn test:e2e 6 | else 7 | # run the lint, unit tests 8 | yarn lint 9 | yarn test:unit 10 | fi 11 | -------------------------------------------------------------------------------- /scripts/unit-v6.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | # runs unit tests against latest 6.x version 4 | 5 | source ${OKTA_HOME}/${REPO}/scripts/setup.sh 6 | 7 | export TEST_SUITE_TYPE="junit" 8 | export TEST_RESULT_FILE_DIR="${REPO}/test-reports/unit" 9 | 10 | if [ ! -z "$AUTHJS_VERSION" ]; then 11 | echo "Skipping unit tests against auth-js v6.x" 12 | exit ${SUCCESS} 13 | fi 14 | 15 | if ! yarn add -DW --ignore-scripts @okta/okta-auth-js@^6; then 16 | echo "auth-js v6.x could not be installed" 17 | exit ${FAILED_SETUP} 18 | fi 19 | 20 | # Run jest with "ci" flag 21 | if ! yarn test:unit --ci; then 22 | echo "unit failed! Exiting..." 23 | exit ${TEST_FAILURE} 24 | fi 25 | 26 | echo ${TEST_SUITE_TYPE} > ${TEST_SUITE_TYPE_FILE} 27 | echo ${TEST_RESULT_FILE_DIR} > ${TEST_RESULT_FILE_DIR_FILE} 28 | exit ${PUBLISH_TYPE_AND_RESULT_DIR} 29 | -------------------------------------------------------------------------------- /scripts/unit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | source ${OKTA_HOME}/${REPO}/scripts/setup.sh 4 | 5 | export TEST_SUITE_TYPE="junit" 6 | export TEST_RESULT_FILE_DIR="${REPO}/test-reports/unit" 7 | 8 | # Run jest with "ci" flag 9 | if ! yarn test:unit --ci; then 10 | echo "unit failed! Exiting..." 11 | exit ${TEST_FAILURE} 12 | fi 13 | 14 | echo ${TEST_SUITE_TYPE} > ${TEST_SUITE_TYPE_FILE} 15 | echo ${TEST_RESULT_FILE_DIR} > ${TEST_RESULT_FILE_DIR_FILE} 16 | exit ${PUBLISH_TYPE_AND_RESULT_DIR} 17 | -------------------------------------------------------------------------------- /scripts/utils/local.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # if not running on bacon 4 | if [ -z "${TEST_SUITE_ID}" ]; then 5 | export OKTA_HOME=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../.." &> /dev/null && pwd) 6 | export REPO="." 7 | export TEST_SUITE_TYPE_FILE=/dev/null 8 | export TEST_RESULT_FILE_DIR_FILE=/dev/null 9 | 10 | ### (known) Bacon exit codes 11 | # success 12 | export SUCCESS=0 13 | export PUBLISH_TYPE_AND_RESULT_DIR=0 14 | export PUBLISH_TYPE_AND_RESULT_DIR_BUT_SUCCEED_IF_NO_RESULTS=0 15 | # failure 16 | export FAILURE=1 17 | export FAILED_SETUP=1 18 | export TEST_FAILURE=1 19 | export PUBLISH_TYPE_AND_RESULT_DIR_BUT_ALWAYS_FAIL=1 20 | export PUBLISH_ARTIFACTORY_FAILURE=1 21 | 22 | # bacon commands 23 | setup_service () { 24 | echo 'noop' 25 | } 26 | 27 | get_secret () { 28 | # ensures the env var is set 29 | key="$2" 30 | if [ -z "${!key}" ]; then 31 | echo "$key is not defined. Exiting..." 32 | exit 1 33 | fi 34 | } 35 | 36 | get_terminus_secret () { 37 | # ensures the env var is set 38 | key="$3" 39 | if [ -z "${!key}" ]; then 40 | echo "$key is not defined. Exiting..." 41 | exit 1 42 | fi 43 | } 44 | 45 | get_vault_secret_key () { 46 | echo "'get_vault_secret_key' command has been deprecated!" 47 | exit 1 48 | } 49 | 50 | set -x # when running locally, might as well see all the commands being ran 51 | fi -------------------------------------------------------------------------------- /scripts/utils/siw-platform-scripts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # if running on bacon 4 | if [ -n "${TEST_SUITE_ID}" ]; then 5 | export SIW_PLATFORM_ENV="bacon" 6 | else 7 | export SIW_PLATFORM_ENV="local" 8 | fi 9 | 10 | orig_ssl=$(yarn config get strict-ssl) 11 | orig_registry=$(yarn config get @okta:registry) 12 | REGISTRY="${ARTIFACTORY_URL}/api/npm/npm-topic" 13 | 14 | update_yarn_config () { 15 | if [ "$SIW_PLATFORM_ENV" == "local" ] ; then 16 | yarn config set @okta:registry ${REGISTRY} 17 | yarn config set strict-ssl false 18 | trap restore_yarn_config EXIT 19 | fi 20 | } 21 | 22 | restore_yarn_config () { 23 | if [ "$SIW_PLATFORM_ENV" == "local" ] ; then 24 | if [ "$orig_registry" == "undefined" ] ; then 25 | yarn config delete @okta:registry 26 | else 27 | yarn config set @okta:registry $orig_registry 28 | fi 29 | yarn config set strict-ssl $orig_ssl 30 | fi 31 | } 32 | 33 | install_siw_platform_scripts () { 34 | update_yarn_config 35 | if ! yarn global add @okta/siw-platform-scripts ; then 36 | echo "siw-platform-scripts could not be installed" 37 | exit ${FAILED_SETUP} 38 | fi 39 | restore_yarn_config 40 | } 41 | 42 | install_artifact () { 43 | # $1 = package name 44 | # $2 = version 45 | update_yarn_config 46 | if ! siw-platform install-artifact -e ${SIW_PLATFORM_ENV} -n $1 -v $2 ; then 47 | echo "$1 $2 could not be installed via siw-platform" 48 | exit ${FAILED_SETUP} 49 | fi 50 | restore_yarn_config 51 | } 52 | -------------------------------------------------------------------------------- /scripts/utils/sync-ws-auth-js.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # A command that modifies the package.json of all workspaces that depdend on @okta/okta-auth-js to use a consistent version 4 | 5 | workspaces=$(yarn -s workspaces info | jq 'map(..|objects|select(.location).location)[1:] | @sh' | tr -d \'\") 6 | 7 | # project directory 8 | pdir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../.." &> /dev/null && pwd) 9 | 10 | for loc in $workspaces 11 | do 12 | echo $loc 13 | json=$(cat $pdir/$loc/package.json | jq --arg version $@ 'if .dependencies | has("@okta/okta-auth-js") then .dependencies["@okta/okta-auth-js"] = $version else . end') && \ 14 | echo -E "${json}" > "$pdir/$loc/package.json" 15 | done 16 | -------------------------------------------------------------------------------- /src/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: "@typescript-eslint/parser", 3 | parserOptions: { 4 | ecmaVersion: 2020, 5 | sourceType: 'module' 6 | }, 7 | extends: [ 8 | 'plugin:@typescript-eslint/eslint-recommended', 9 | 'plugin:@typescript-eslint/recommended', 10 | ], 11 | plugins: [ 12 | // https://github.com/import-js/eslint-plugin-import#typescript 13 | 'import', 14 | ], 15 | rules: { 16 | // https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-extraneous-dependencies.md 17 | 'import/no-extraneous-dependencies': ['error', { 18 | 'devDependencies': false 19 | }] 20 | }, 21 | settings: { 22 | // https://github.com/import-js/eslint-plugin-import#typescript 23 | 'import/parsers': { 24 | '@typescript-eslint/parser': ['.ts', '.tsx'] 25 | } 26 | }, 27 | } 28 | -------------------------------------------------------------------------------- /src/OktaContext.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | import * as React from 'react'; 13 | import { AuthState, OktaAuth } from '@okta/okta-auth-js'; 14 | 15 | export type OnAuthRequiredFunction = (oktaAuth: OktaAuth) => Promise | void; 16 | export type OnAuthResumeFunction = () => void; 17 | 18 | export type RestoreOriginalUriFunction = (oktaAuth: OktaAuth, originalUri: string) => Promise | void; 19 | 20 | export interface IOktaContext { 21 | oktaAuth: OktaAuth; 22 | authState: AuthState | null; 23 | _onAuthRequired?: OnAuthRequiredFunction; 24 | } 25 | 26 | const OktaContext = React.createContext(null); 27 | 28 | export const useOktaAuth = (): IOktaContext => React.useContext(OktaContext) as IOktaContext; 29 | 30 | export default OktaContext; 31 | -------------------------------------------------------------------------------- /src/OktaError.tsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import * as React from 'react'; 14 | 15 | const OktaError: React.FC<{ error: Error }> = ({ error }) => { 16 | if(error.name && error.message) { 17 | return

{error.name}: {error.message}

; 18 | } 19 | return

Error: {error.toString()}

; 20 | }; 21 | 22 | export default OktaError; 23 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import Security from './Security'; 14 | import withOktaAuth from './withOktaAuth'; 15 | import OktaContext, { useOktaAuth } from './OktaContext'; 16 | import LoginCallback from './LoginCallback'; 17 | import SecureRoute from './SecureRoute'; 18 | 19 | export { 20 | Security, 21 | withOktaAuth, 22 | useOktaAuth, 23 | OktaContext, 24 | LoginCallback, 25 | SecureRoute, 26 | }; 27 | -------------------------------------------------------------------------------- /src/withOktaAuth.tsx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import * as React from 'react'; 14 | import { useOktaAuth, IOktaContext } from './OktaContext'; 15 | 16 | const withOktaAuth =

( 17 | ComponentToWrap: React.ComponentType

18 | ): React.FC> => { 19 | const WrappedComponent = (props: Omit) => { 20 | const oktaAuthProps = useOktaAuth(); 21 | return ; 22 | }; 23 | WrappedComponent.displayName = 'withOktaAuth_' + (ComponentToWrap.displayName || ComponentToWrap.name); 24 | return WrappedComponent; 25 | }; 26 | 27 | export default withOktaAuth; 28 | -------------------------------------------------------------------------------- /test/apps/test-harness-app/.env.development: -------------------------------------------------------------------------------- 1 | # Forces Vite to run a development build: https://vitejs.dev/guide/env-and-mode.html#modes 2 | NODE_ENV=development -------------------------------------------------------------------------------- /test/apps/test-harness-app/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /test/apps/test-harness-app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |

11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/apps/test-harness-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@okta/test.app.test-harness-app", 3 | "private": true, 4 | "version": "0.0.0", 5 | "scripts": { 6 | "prestart": "vite build", 7 | "start": "vite preview --port 8080", 8 | "start:dev": "vite build --mode development && vite preview --port 8080", 9 | "dev": "vite", 10 | "build": "tsc && vite build", 11 | "preview": "vite preview" 12 | }, 13 | "dependencies": { 14 | "react": "^18.2.0", 15 | "react-dom": "^18.2.0", 16 | "react-router-dom": "5.2.0", 17 | "@okta/okta-auth-js": "*", 18 | "@okta/okta-react": "*" 19 | }, 20 | "devDependencies": { 21 | "@types/react": "^18.2.15", 22 | "@types/react-dom": "^18.2.7", 23 | "@types/react-router-dom": "^5.3.3", 24 | "@vitejs/plugin-react": "^1.3.2", 25 | "typescript": "^4.5.4", 26 | "vite": "^2.8.0" 27 | } 28 | } -------------------------------------------------------------------------------- /test/apps/test-harness-app/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 80px; 8 | } 9 | 10 | .App-header { 11 | background-color: #222; 12 | height: 150px; 13 | padding: 20px; 14 | color: white; 15 | } 16 | 17 | .App-intro { 18 | font-size: large; 19 | } 20 | 21 | @keyframes App-logo-spin { 22 | from { transform: rotate(0deg); } 23 | to { transform: rotate(360deg); } 24 | } 25 | -------------------------------------------------------------------------------- /test/apps/test-harness-app/src/CustomLogin.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import * as React from 'react'; 14 | import { useOktaAuth } from '@okta/okta-react'; 15 | 16 | const CustomLogin: React.FC = () => { 17 | const { oktaAuth } = useOktaAuth(); 18 | 19 | React.useEffect(() => { 20 | oktaAuth.signInWithRedirect(); 21 | }, [oktaAuth]); 22 | 23 | return null; 24 | }; 25 | 26 | export default CustomLogin; 27 | -------------------------------------------------------------------------------- /test/apps/test-harness-app/src/Protected.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | // implement with "withOktaAuth" HOC 14 | import * as React from 'react'; 15 | import { OktaAuth } from '@okta/okta-auth-js'; 16 | import { withOktaAuth } from '@okta/okta-react'; 17 | 18 | const Protected: React.FC<{ oktaAuth: OktaAuth }> = ({ oktaAuth }) => { 19 | const [userInfo, setUserInfo] = React.useState(''); 20 | 21 | React.useEffect(() => { 22 | const fetchUser = async () => { 23 | const claims = await oktaAuth.getUser(); 24 | const userinfo = JSON.stringify(claims, null, 4); 25 | setUserInfo(userinfo); 26 | }; 27 | 28 | fetchUser(); 29 | }, [oktaAuth]); 30 | 31 | const logout = async () => oktaAuth.signOut(); 32 | 33 | return ( 34 |
35 |
Protected!
36 | {userInfo &&
 {userInfo} 
} 37 | 38 |
39 | ); 40 | }; 41 | 42 | export default withOktaAuth(Protected); 43 | -------------------------------------------------------------------------------- /test/apps/test-harness-app/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: sans-serif; 5 | } 6 | -------------------------------------------------------------------------------- /test/apps/test-harness-app/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | /// 14 | -------------------------------------------------------------------------------- /test/apps/test-harness-app/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | /// 14 | -------------------------------------------------------------------------------- /test/apps/test-harness-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": false, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["src"], 20 | "references": [{ "path": "./tsconfig.node.json" }] 21 | } 22 | -------------------------------------------------------------------------------- /test/apps/test-harness-app/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "esnext", 5 | "moduleResolution": "node" 6 | }, 7 | "include": ["vite.config.ts"] 8 | } 9 | -------------------------------------------------------------------------------- /test/apps/v6-app/.env.development: -------------------------------------------------------------------------------- 1 | # Forces Vite to run a development build: https://vitejs.dev/guide/env-and-mode.html#modes 2 | NODE_ENV=development -------------------------------------------------------------------------------- /test/apps/v6-app/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /test/apps/v6-app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /test/apps/v6-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@okta/test.app.v6-app", 3 | "private": true, 4 | "version": "0.0.0", 5 | "scripts": { 6 | "prestart": "vite build", 7 | "start": "vite preview --port 8080", 8 | "start:dev": "vite build --mode development && vite preview --port 8080", 9 | "dev": "vite", 10 | "build": "tsc && vite build", 11 | "preview": "vite preview" 12 | }, 13 | "dependencies": { 14 | "react": "^18.2.0", 15 | "react-dom": "^18.2.0", 16 | "react-router-dom": "6.3.0", 17 | "@okta/okta-auth-js": "*", 18 | "@okta/okta-react": "*" 19 | }, 20 | "devDependencies": { 21 | "@types/react": "^18.2.15", 22 | "@types/react-dom": "^18.2.7", 23 | "@types/react-router-dom": "^5.3.3", 24 | "@vitejs/plugin-react": "^1.3.2", 25 | "typescript": "^4.5.4", 26 | "vite": "^2.8.0" 27 | } 28 | } -------------------------------------------------------------------------------- /test/apps/v6-app/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 80px; 8 | } 9 | 10 | .App-header { 11 | background-color: #222; 12 | height: 150px; 13 | padding: 20px; 14 | color: white; 15 | } 16 | 17 | .App-intro { 18 | font-size: large; 19 | } 20 | 21 | @keyframes App-logo-spin { 22 | from { transform: rotate(0deg); } 23 | to { transform: rotate(360deg); } 24 | } 25 | -------------------------------------------------------------------------------- /test/apps/v6-app/src/CustomLogin.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import * as React from 'react'; 14 | import { useOktaAuth } from '@okta/okta-react'; 15 | 16 | const CustomLogin: React.FC = () => { 17 | const { oktaAuth } = useOktaAuth(); 18 | 19 | React.useEffect(() => { 20 | oktaAuth.signInWithRedirect(); 21 | }, [oktaAuth]); 22 | 23 | return null; 24 | }; 25 | 26 | export default CustomLogin; 27 | -------------------------------------------------------------------------------- /test/apps/v6-app/src/Protected.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | // implement with "withOktaAuth" HOC 14 | import * as React from 'react'; 15 | import { OktaAuth } from '@okta/okta-auth-js'; 16 | import { withOktaAuth } from '@okta/okta-react'; 17 | 18 | const Protected: React.FC<{ oktaAuth: OktaAuth }> = ({ oktaAuth }) => { 19 | const [userInfo, setUserInfo] = React.useState(''); 20 | 21 | React.useEffect(() => { 22 | const fetchUser = async () => { 23 | const claims = await oktaAuth.getUser(); 24 | const userinfo = JSON.stringify(claims, null, 4); 25 | setUserInfo(userinfo); 26 | }; 27 | 28 | fetchUser(); 29 | }, [oktaAuth]); 30 | 31 | const logout = async () => oktaAuth.signOut(); 32 | 33 | return ( 34 |
35 |
Protected!
36 | {userInfo &&
 {userInfo} 
} 37 | 38 |
39 | ); 40 | }; 41 | 42 | export default withOktaAuth(Protected); 43 | -------------------------------------------------------------------------------- /test/apps/v6-app/src/SecureRoute.tsx: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import React, { useEffect } from 'react'; 14 | import { useOktaAuth } from '@okta/okta-react'; 15 | import { toRelativeUrl } from '@okta/okta-auth-js'; 16 | import { Outlet } from 'react-router-dom'; 17 | 18 | 19 | export const SecureRoute: React.FC = () => { 20 | const { oktaAuth, authState } = useOktaAuth(); 21 | 22 | useEffect(() => { 23 | if (!authState) { 24 | return; 25 | } 26 | 27 | if (!authState?.isAuthenticated) { 28 | const originalUri = toRelativeUrl(window.location.href, window.location.origin); 29 | oktaAuth.setOriginalUri(originalUri); 30 | oktaAuth.signInWithRedirect(); 31 | } 32 | }, [oktaAuth, !!authState, authState?.isAuthenticated]); 33 | 34 | if (!authState || !authState?.isAuthenticated) { 35 | return (

Loading...

); 36 | } 37 | 38 | return (); 39 | } 40 | -------------------------------------------------------------------------------- /test/apps/v6-app/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: sans-serif; 5 | } 6 | -------------------------------------------------------------------------------- /test/apps/v6-app/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | /// 14 | -------------------------------------------------------------------------------- /test/apps/v6-app/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | /// 14 | -------------------------------------------------------------------------------- /test/apps/v6-app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": false, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx" 18 | }, 19 | "include": ["src"], 20 | "references": [{ "path": "./tsconfig.node.json" }] 21 | } 22 | -------------------------------------------------------------------------------- /test/apps/v6-app/tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "esnext", 5 | "moduleResolution": "node" 6 | }, 7 | "include": ["vite.config.ts"] 8 | } 9 | -------------------------------------------------------------------------------- /test/e2e/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parserOptions: { 3 | ecmaVersion: 2020, 4 | sourceType: 'module' 5 | }, 6 | extends: [ 7 | 'plugin:jasmine/recommended' 8 | ], 9 | plugins: [ 10 | 'jasmine', 11 | ], 12 | env: { 13 | jasmine: true, 14 | node: true, 15 | es6: true 16 | }, 17 | rules: { 18 | 'jasmine/new-line-before-expect': 0, 19 | }, 20 | globals: { 21 | '$': true, 22 | 'browser': true, 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /test/e2e/babel.config.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | module.exports = { 14 | "presets": [ 15 | [ 16 | "@babel/preset-env", 17 | { 18 | "targets": { 19 | "node": "14" 20 | } 21 | } 22 | ] 23 | ] 24 | } -------------------------------------------------------------------------------- /test/e2e/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@okta/test.e2e", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "test": "node runner.js", 7 | "wdio": "wdio run wdio.conf.js", 8 | "test:harness": "SAMPLE_NAME=harness yarn test" 9 | }, 10 | "devDependencies": { 11 | "@babel/cli": "^7.19.3", 12 | "@babel/core": "^7.19.3", 13 | "@babel/preset-env": "^7.19.3", 14 | "@babel/register": "^7.18.9", 15 | "@wdio/cli": "^7.25.1", 16 | "@wdio/jasmine-framework": "^7.25.1", 17 | "@wdio/junit-reporter": "^7.25.1", 18 | "@wdio/local-runner": "^7.25.1", 19 | "@wdio/selenium-standalone-service": "^7.25.1", 20 | "@wdio/spec-reporter": "^7.25.1", 21 | "cross-spawn-with-kill": "^1.0.0", 22 | "eslint-plugin-jasmine": "^4.1.1", 23 | "wait-on": "^6.0.1", 24 | "url": "^0.11.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/e2e/page-objects/authenticators-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-2018, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | class AuthenticatorsPage { 16 | 17 | get authenticatorLabel () { return $('.authenticator-label'); } 18 | get selectAuthenticatorButton () { return $('[class="authenticator-button"] [data-se="button"]'); } 19 | 20 | waitForPageLoad() { 21 | return this.selectAuthenticatorButton.waitForDisplayed(); 22 | } 23 | 24 | async clickAuthenticatorByLabel(label) { 25 | await this.authenticatorLabel.waitForDisplayed(); 26 | 27 | let index = 0; 28 | for await (let element of this.authenticatorLabel) { 29 | const text = await element.getText(); 30 | if (text.includes(label) > 0) { 31 | this.selectAuthenticatorButton[index].click(); 32 | } 33 | index++; 34 | } 35 | } 36 | } 37 | 38 | export default new AuthenticatorsPage(); 39 | -------------------------------------------------------------------------------- /test/e2e/page-objects/direct-auth-login-form.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | 16 | class DirectAuthLoginInPage { 17 | 18 | get usernameInput () { return $('#username'); } 19 | get passwordInput () { return $('#password'); } 20 | get submitButton () { return $('button[type=submit]'); } 21 | 22 | waitForPageLoad() { 23 | return this.usernameInput.waitForDisplayed(); 24 | } 25 | 26 | async login(username, password) { 27 | await this.usernameInput.setValue(username); 28 | await this.passwordInput.setValue(password); 29 | await this.submitButton.click(); 30 | } 31 | 32 | } 33 | 34 | export default new DirectAuthLoginInPage(); 35 | -------------------------------------------------------------------------------- /test/e2e/page-objects/messages-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-2018, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | 16 | 17 | class MessagesPage { 18 | 19 | get message1 () { return $('#message-1'); } 20 | 21 | waitForPageLoad() { 22 | return this.message1.waitForDisplayed(); 23 | } 24 | 25 | getMessage() { 26 | return this.message1.getText(); 27 | } 28 | } 29 | 30 | export default new MessagesPage(); 31 | -------------------------------------------------------------------------------- /test/e2e/page-objects/mfa-challenge-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-2018, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | 16 | class MFAChallengePage { 17 | 18 | get passcodeSelector () { return $('[name="credentials.passcode"]'); } 19 | get submitButton () { return $('input[data-type="save"]'); } 20 | 21 | waitForPageLoad() { 22 | return this.passcodeSelector.waitForDisplayed(); 23 | } 24 | 25 | async clickSubmitButton() { 26 | await this.submitButton.waitForDisplayed(); 27 | await this.submitButton.click(); 28 | } 29 | 30 | async enterPasscode(passcode) { 31 | await this.passcodeSelector.setValue(passcode); 32 | } 33 | 34 | // TODO: is this used? 35 | // getEmailPasscode() { 36 | // util.wait(this.passcodeSelector); 37 | // } 38 | } 39 | 40 | export default new MFAChallengePage(); -------------------------------------------------------------------------------- /test/e2e/page-objects/okta-signin-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | 16 | class OktaSignInPage { 17 | 18 | get usernameInput () { return $(`[data-se="o-form-input-username"] input`); } 19 | get passwordInput () { return $(`[data-se="o-form-input-password"] input`); } 20 | get submitButton () { return $('[data-type="save"]'); } 21 | 22 | waitForPageLoad() { 23 | return this.usernameInput.waitForDisplayed(); 24 | } 25 | 26 | async login(username, password) { 27 | await this.usernameInput.setValue(username); 28 | await this.passwordInput.setValue(password); 29 | await this.submitButton.click(); 30 | } 31 | 32 | } 33 | 34 | export default new OktaSignInPage(); 35 | -------------------------------------------------------------------------------- /test/e2e/page-objects/router-sample-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | /* eslint-disable */ 14 | 15 | /** 16 | * main page object containing all methods, selectors and functionality 17 | * that is shared across all page objects 18 | */ 19 | class RouterSampleAppPage { 20 | 21 | // Router App selectors 22 | get header () { return $('main h1.page-header'); } 23 | get homeNavLink () { return $('#home-nav-link'); } 24 | get protectedNavLink () { return $('#protected-nav-link'); } 25 | get loadingIcon () { return $('#loading-icon'); } 26 | get footerBtn () { return $('footer > button[type="button"]'); } 27 | 28 | async logout () { 29 | await expect(this.footerBtn).toHaveText('Logout'); 30 | await this.footerBtn.click(); 31 | await browser.waitUntil(async () => await this.footerBtn.getText() === 'Login', {timeoutMsg: 'Could not find logout button'}); 32 | } 33 | 34 | /** 35 | * Opens a sub page of the page 36 | * @param path path of the sub page (e.g. /path/to/page.html) 37 | */ 38 | open (path='/') { 39 | return browser.url(`http://localhost:8080${path}`); 40 | } 41 | } 42 | 43 | export default new RouterSampleAppPage(); 44 | -------------------------------------------------------------------------------- /test/e2e/page-objects/shared/login-home-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-2018, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | class LoginHomePage { 16 | 17 | get loginButton () { return $('#login-button'); } 18 | 19 | waitForPageLoad() { 20 | return this.loginButton.waitForDisplayed(); 21 | } 22 | 23 | clickLoginButton() { 24 | return this.loginButton.click(); 25 | } 26 | } 27 | 28 | export default new LoginHomePage(); 29 | -------------------------------------------------------------------------------- /test/e2e/page-objects/shared/profile-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-2018, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | 16 | class ProfilePage { 17 | 18 | get emailClaim () { return $('#claim-email'); } 19 | 20 | waitForPageLoad() { 21 | return this.emailClaim.waitForDisplayed(); 22 | } 23 | 24 | logout() { 25 | return this.logoutLink.click(); 26 | } 27 | 28 | getEmailClaim() { 29 | return this.emailClaim.getText(); 30 | } 31 | } 32 | 33 | export default new ProfilePage(); 34 | -------------------------------------------------------------------------------- /test/e2e/page-objects/shared/protected-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | 16 | class ProtectedPage { 17 | 18 | get protected () { return $('#protected'); } 19 | 20 | waitForPageLoad() { 21 | return this.protected.waitForDisplayed(); 22 | } 23 | } 24 | 25 | export default new ProtectedPage(); 26 | -------------------------------------------------------------------------------- /test/e2e/page-objects/test-harness-app/app-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-2018, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | 16 | class AppPage { 17 | 18 | // Home Page 19 | get loginButton () { return $('#login-button'); } 20 | get logoutButton () { return $('#logout-button'); } 21 | get protectedButton () { return $('#protected-button'); } 22 | get loginFlow () { return $('#login-flow'); } 23 | 24 | waitForPageLoad() { 25 | return browser.waitUntil(async () => { 26 | try { 27 | await Promise.race([ 28 | this.loginButton.waitForDisplayed({timeout: 20000}), 29 | this.logoutButton.waitForDisplayed({timeout: 20000}) 30 | ]); 31 | return true; 32 | } 33 | catch (err) { 34 | return false; 35 | } 36 | }) 37 | } 38 | 39 | waitForLogout () { 40 | return this.loginButton.waitForDisplayed(); 41 | } 42 | 43 | open (path='/') { 44 | return browser.url(path); 45 | } 46 | } 47 | 48 | export default new AppPage(); 49 | -------------------------------------------------------------------------------- /test/e2e/page-objects/test-harness-app/index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | export { default as AppPage } from './app-page'; 14 | export { default as ProtectedPage } from './protected-page'; 15 | export { default as SessionTokenSignInPage } from './sessionToken-signin-page'; 16 | export { default as LoginCallbackPage } from './login-callback-page'; 17 | -------------------------------------------------------------------------------- /test/e2e/page-objects/test-harness-app/login-callback-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-2018, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | 16 | class LoginCallbackPage { 17 | 18 | get loadingElement () { return $('#login-callback-loading'); } 19 | get errorElement () { return $('#login-callback-error'); } 20 | 21 | waitForPageLoad() { 22 | return this.loadingElement.waitForDisplayed(); 23 | } 24 | 25 | } 26 | 27 | export default new LoginCallbackPage(); 28 | -------------------------------------------------------------------------------- /test/e2e/page-objects/test-harness-app/protected-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-2018, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | 16 | class ProtectedPage { 17 | 18 | get loginButton () { return $('#login-button'); } 19 | get logoutButton () { return $('#logout-button'); } 20 | get userInfo () { return $('#userinfo-container'); } 21 | 22 | waitForPageLoad(path) { 23 | return browser.waitUntil(async () => { 24 | const url = await browser.getUrl(); 25 | return url.indexOf('/protected' + path) !== -1; 26 | }, { timeout: 20000 }); 27 | } 28 | 29 | open (path='/') { 30 | return browser.url('/protected' + path); 31 | } 32 | } 33 | 34 | export default new ProtectedPage(); 35 | -------------------------------------------------------------------------------- /test/e2e/page-objects/test-harness-app/sessionToken-signin-page.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2015-2018, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | 'use strict'; 14 | 15 | 16 | class SessionTokenSignInPage { 17 | 18 | get usernameInput () { return $('#username'); } 19 | get passwordInput () { return $('#password'); } 20 | get submitButton () { return $('#submit'); } 21 | 22 | waitForPageLoad() { 23 | return this.submitButton.waitForDisplayed(); 24 | } 25 | 26 | async login(username, password) { 27 | await this.submitButton.waitForClickable(); 28 | await this.usernameInput.setValue(username); 29 | await this.passwordInput.setValue(password); 30 | await this.submitButton.click(); 31 | } 32 | 33 | open () { 34 | return browser.url('/sessionToken-login'); 35 | } 36 | } 37 | 38 | export default new SessionTokenSignInPage(); 39 | -------------------------------------------------------------------------------- /test/jest/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | env: { 4 | jest: true 5 | }, 6 | extends: [ 7 | 'plugin:@typescript-eslint/recommended', 8 | 'plugin:jest/recommended' 9 | ], 10 | rules: { 11 | '@typescript-eslint/no-explicit-any': 0 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/jest/setup.ts: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ 12 | 13 | import Enzyme from 'enzyme'; 14 | import Adapter from 'enzyme-adapter-react-16'; 15 | 16 | Enzyme.configure({ adapter: new Adapter() }); 17 | 18 | // eslint-disable-next-line @typescript-eslint/no-empty-function 19 | global.console.warn = function() {}; 20 | -------------------------------------------------------------------------------- /test/jest/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "skipLibCheck": true, 4 | "jsx": "react", 5 | "esModuleInterop": true, 6 | "resolveJsonModule": true, 7 | "strict": true 8 | } 9 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "declarationDir": "dist/bundles/types", 5 | "target": "ES2019", 6 | "sourceMap": true, 7 | "jsx": "react", 8 | "moduleResolution": "node", 9 | "strictFunctionTypes": true, 10 | "resolveJsonModule": true, 11 | "strict": true 12 | }, 13 | "include": ["src/**/*"], 14 | } 15 | -------------------------------------------------------------------------------- /util/license-template.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | * Copyright (c) 2017-Present, Okta, Inc. and/or its affiliates. All rights reserved. 3 | * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") 4 | * 5 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 6 | * Unless required by applicable law or agreed to in writing, software 7 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 8 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | * 10 | * See the License for the specific language governing permissions and limitations under the License. 11 | */ -------------------------------------------------------------------------------- /util/maintain-banners.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const globby = require('globby'); 3 | const path = require('path'); 4 | 5 | const bannerSourcePath = path.join(__dirname, 'license-template.txt'); 6 | const filePatterns = [ 7 | 'src/**/*.{js,jsx,ts,tsx}', 8 | 'test/**/*.{js,jsx,ts,tsx}', 9 | 'generator/**/*.{js,jsx,ts,tsx}', 10 | 'generated/**/*.{js,jsx,ts,tsx}', 11 | 'dist/bundles/*.{js,jsx,ts,tsx}' 12 | ]; 13 | const files = globby.sync([path.join(__dirname, '..',`{${filePatterns.join(',')}}`), '!**/node_modules/**']); 14 | const bannerSource = fs.readFileSync(bannerSourcePath).toString(); 15 | const copyrightRegex = /(Copyright \(c\) )([0-9]+)-?([0-9]+)?/; 16 | 17 | files.forEach(file => { 18 | const contents = fs.readFileSync(file).toString(); 19 | const match = contents.match(copyrightRegex); 20 | if (!match) { 21 | return fs.writeFileSync(file, bannerSource + '\n\n' + contents); 22 | } 23 | }); 24 | --------------------------------------------------------------------------------