├── .bundlewatch.config.json ├── .editorconfig ├── .eslintignore ├── .eslintrc.cjs ├── .github ├── renovate.json └── workflows │ ├── codeql-analysis.yml │ ├── on-pull-request.yml │ ├── on-push.yml │ └── on-release.yml ├── .gitignore ├── .prettierignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── assets └── logo.jpg ├── docs ├── README.md ├── functions │ ├── AuthProvider.md │ ├── useAuth.md │ └── withAuth.md ├── interfaces │ ├── AuthContextProps.md │ ├── AuthProviderProps.md │ ├── AuthProviderSignOutProps.md │ └── Location.md └── variables │ └── AuthContext.md ├── guides ├── HOOKS.md ├── QUICKSTART.md ├── WITHAUTH.md └── migrate-v1-v2.md ├── package.json ├── pnpm-lock.yaml ├── src ├── __tests__ │ └── auth-context.test.tsx ├── auth-context-interface.ts ├── auth-context.tsx ├── index.ts ├── use-auth.ts └── with-auth.tsx ├── tsconfig.json ├── tsconfig.release.json └── typedoc.json /.bundlewatch.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | { 4 | "path": "./build/src/*.js" 5 | } 6 | ], 7 | "ci": { 8 | "trackBranches": ["main"] 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = false 8 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | /**/*.js 2 | build/ -------------------------------------------------------------------------------- /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | /** 2 | * @type {import('eslint').Linter.Config} 3 | **/ 4 | 5 | module.exports = { 6 | extends: [ 7 | '@bjerk/eslint-config/base', 8 | '@bjerk/eslint-config/typescript', 9 | // '@bjerk/eslint-config/import', 10 | // '@bjerk/eslint-config/prettier', 11 | ], 12 | overrides: [ 13 | { 14 | files: ['*.test.ts', '*.test.tsx'], 15 | rules: { 16 | // TODO: Improve tests and remove these rules 17 | '@typescript-eslint/no-unsafe-assignment': 'warn', 18 | '@typescript-eslint/no-unsafe-member-access': 'warn', 19 | '@typescript-eslint/no-explicit-any': 'warn', 20 | '@typescript-eslint/no-unsafe-argument': 'warn', 21 | '@typescript-eslint/no-floating-promises': 'warn', 22 | 'no-restricted-globals': 'warn', 23 | '@typescript-eslint/no-unsafe-call': 'warn', 24 | }, 25 | }, 26 | ], 27 | parserOptions: { 28 | project: true, 29 | tsconfigRootDir: __dirname, 30 | }, 31 | }; 32 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["github>bjerkio/workflows"], 4 | 5 | "packageRules": [ 6 | { 7 | "matchDatasources": ["npm"], 8 | "matchPackageNames": [ 9 | "react", 10 | "react-dom", 11 | "@types/react", 12 | "@types/react-dom" 13 | ], 14 | "matchUpdateTypes": ["major"], 15 | "groupName": "React major dependency updates", 16 | "groupSlug": "react-major-deps" 17 | }, 18 | { 19 | "matchPackageNames": ["oidc-client-ts"], 20 | "matchUpdateTypes": ["minor", "patch", "major"], 21 | "groupName": "oidc-client-ts dependency update", 22 | "groupSlug": "oidc-client-ts-dep", 23 | "semanticCommitScope": "deps" 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | name: 'CodeQL' 7 | 8 | on: 9 | push: 10 | branches: [master] 11 | pull_request: 12 | # The branches below must be a subset of the branches above 13 | branches: [master] 14 | schedule: 15 | - cron: '0 12 * * 0' 16 | 17 | jobs: 18 | analyze: 19 | name: Analyze 20 | runs-on: ubuntu-latest 21 | 22 | strategy: 23 | fail-fast: false 24 | matrix: 25 | # Override automatic language detection by changing the below list 26 | # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] 27 | language: ['javascript'] 28 | # Learn more... 29 | # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection 30 | 31 | steps: 32 | - name: Checkout repository 33 | uses: actions/checkout@v4 34 | with: 35 | # We must fetch at least the immediate parents so that if this is 36 | # a pull request then we can checkout the head. 37 | fetch-depth: 2 38 | 39 | # If this run was triggered by a pull request event, then checkout 40 | # the head of the pull request instead of the merge commit. 41 | - run: git checkout HEAD^2 42 | if: ${{ github.event_name == 'pull_request' }} 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v3 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v3 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v3 72 | -------------------------------------------------------------------------------- /.github/workflows/on-pull-request.yml: -------------------------------------------------------------------------------- 1 | name: On PR 2 | on: [pull_request] 3 | 4 | jobs: 5 | build: 6 | runs-on: ubuntu-latest 7 | 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | node-version: [lts/-2, lts/-1, lts/*, current] 12 | 13 | steps: 14 | - uses: actions/checkout@v4 15 | 16 | - name: Setup pnpm 📦️ 17 | uses: pnpm/action-setup@v2 18 | 19 | - name: Use Node.js ${{ matrix.node-version }} 20 | uses: actions/setup-node@v4 21 | with: 22 | node-version: ${{ matrix.node-version }} 23 | cache: pnpm 24 | 25 | - run: node --version 26 | 27 | - run: pnpm install --frozen-lockfile 28 | 29 | # - run: pnpm run lint # Temporarily removed on 2024-12-09 30 | 31 | - run: pnpm run test 32 | 33 | - run: pnpm run build 34 | 35 | - run: pnpm run format:check 36 | 37 | - uses: codecov/codecov-action@v4 38 | -------------------------------------------------------------------------------- /.github/workflows/on-push.yml: -------------------------------------------------------------------------------- 1 | name: On Push 2 | on: 3 | push: 4 | branches: 5 | - main 6 | - master 7 | 8 | jobs: 9 | build-and-test: 10 | runs-on: ubuntu-latest 11 | 12 | strategy: 13 | fail-fast: false 14 | matrix: 15 | node-version: [lts/-2, lts/-1, lts/*, current] 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - name: Setup pnpm 📦️ 21 | uses: pnpm/action-setup@v2 22 | 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v4 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | cache: pnpm 28 | 29 | - run: node --version 30 | 31 | - run: pnpm install --frozen-lockfile 32 | 33 | - run: pnpm run test 34 | 35 | - run: pnpm run build 36 | 37 | - uses: codecov/codecov-action@v4 38 | 39 | generate-docs: 40 | runs-on: ubuntu-latest 41 | steps: 42 | - uses: actions/checkout@v4 43 | 44 | - name: Setup pnpm 📦️ 45 | uses: pnpm/action-setup@v2 46 | 47 | - name: Use Node.js LTS 48 | uses: actions/setup-node@v4 49 | with: 50 | node-version: lts/* 51 | cache: pnpm 52 | 53 | - run: pnpm install --frozen-lockfile 54 | 55 | - name: Run typegen 56 | run: pnpm run generate-docs 57 | 58 | - name: Create Pull Request 59 | uses: peter-evans/create-pull-request@v7 60 | with: 61 | branch: update-documentation 62 | delete-branch: true 63 | commit-message: 'chore(docs): run typegen' 64 | title: 'chore(docs): run typegen' 65 | body: 66 | 'This is automatically created since the documentation is out of 67 | date.' 68 | -------------------------------------------------------------------------------- /.github/workflows/on-release.yml: -------------------------------------------------------------------------------- 1 | name: Release to NPM 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | release: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout 🛎️ 12 | uses: actions/checkout@v4 13 | 14 | - uses: pnpm/action-setup@v2 15 | 16 | - name: Use Node LTS ✨ 17 | uses: actions/setup-node@v4 18 | with: 19 | node-version: lts/* 20 | registry-url: https://registry.npmjs.org 21 | cache: pnpm 22 | 23 | - name: Install dependencies 📦️ 24 | run: pnpm install --frozen-lockfile 25 | 26 | - name: Build 🔨 27 | run: pnpm build 28 | 29 | - uses: simenandre/publish-with-pnpm@v2 30 | with: 31 | npm-auth-token: ${{ secrets.NPM_TOKEN }} 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | *.pid.lock 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Intellij 16 | .idea 17 | *.iml 18 | 19 | # Coverage directory used by tools like istanbul 20 | coverage 21 | 22 | # nyc test coverage 23 | .nyc_output 24 | 25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 26 | .grunt 27 | 28 | # Bower dependency directory (https://bower.io/) 29 | bower_components 30 | 31 | # node-waf configuration 32 | .lock-wscript 33 | 34 | # Compiled binary addons (https://nodejs.org/api/addons.html) 35 | build/Release 36 | 37 | # Dependency directories 38 | node_modules/ 39 | jspm_packages/ 40 | 41 | # TypeScript v1 declaration files 42 | typings/ 43 | 44 | # Optional npm cache directory 45 | .npm 46 | 47 | # Optional eslint cache 48 | .eslintcache 49 | 50 | # Optional REPL history 51 | .node_repl_history 52 | 53 | # Output of 'npm pack' 54 | *.tgz 55 | 56 | # dotenv environment variables file 57 | .env 58 | 59 | # next.js build output 60 | .next 61 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 62 | 63 | # dependencies 64 | /node_modules 65 | /.pnp 66 | .pnp.js 67 | 68 | # testing 69 | /coverage 70 | 71 | # production 72 | /build 73 | 74 | # misc 75 | .DS_Store 76 | .env.local 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | 81 | npm-debug.log* 82 | package-lock.json 83 | pnpm-debug.log* -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | CHANGELOG.md 2 | docs/* 3 | dist/* 4 | build/* 5 | 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | lerna-debug.log* 11 | 12 | # Diagnostic reports (https://nodejs.org/api/report.html) 13 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 14 | 15 | # Runtime data 16 | pids 17 | *.pid 18 | *.seed 19 | *.pid.lock 20 | 21 | # Directory for instrumented libs generated by jscoverage/JSCover 22 | lib-cov 23 | 24 | # Coverage directory used by tools like istanbul 25 | coverage 26 | *.lcov 27 | 28 | # nyc test coverage 29 | .nyc_output 30 | 31 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 32 | .grunt 33 | 34 | # Bower dependency directory (https://bower.io/) 35 | bower_components 36 | 37 | # node-waf configuration 38 | .lock-wscript 39 | 40 | # Compiled binary addons (https://nodejs.org/api/addons.html) 41 | build/Release 42 | 43 | # Dependency directories 44 | node_modules/ 45 | jspm_packages/ 46 | 47 | # TypeScript v1 declaration files 48 | typings/ 49 | 50 | # TypeScript cache 51 | *.tsbuildinfo 52 | 53 | # Optional npm cache directory 54 | .npm 55 | 56 | # Optional eslint cache 57 | .eslintcache 58 | 59 | # Microbundle cache 60 | .rpt2_cache/ 61 | .rts2_cache_cjs/ 62 | .rts2_cache_es/ 63 | .rts2_cache_umd/ 64 | 65 | # Optional REPL history 66 | .node_repl_history 67 | 68 | # Output of 'npm pack' 69 | *.tgz 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | # GitHub Actions 107 | .github/renovate.json 108 | pnpm-lock.yaml 109 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. See 4 | [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [3.2.2](https://github.com/bjerkio/oidc-react/compare/v3.2.1...v3.2.2) (2023-06-20) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * multiplied code exchange requests in strict mode ([#1012](https://github.com/bjerkio/oidc-react/issues/1012)) ([2118bb2](https://github.com/bjerkio/oidc-react/commit/2118bb24fae875669a3bc87fcec298092485838d)) 12 | 13 | ## [3.2.1](https://github.com/bjerkio/oidc-react/compare/v3.2.0...v3.2.1) (2023-06-12) 14 | 15 | 16 | ### Bug Fixes 17 | 18 | * **deps:** update dependency oidc-client-ts to v2.2.4 ([#1006](https://github.com/bjerkio/oidc-react/issues/1006)) ([423be19](https://github.com/bjerkio/oidc-react/commit/423be19c9a09ea43e53931d7eeaab6972651eb32)) 19 | 20 | ## [3.2.0](https://github.com/bjerkio/oidc-react/compare/v3.1.0...v3.2.0) (2023-05-02) 21 | 22 | 23 | ### Features 24 | 25 | * add inline source maps ([efdf184](https://github.com/bjerkio/oidc-react/commit/efdf184bd585a3b7d2c8ad59cac03e83c27133c4)) 26 | 27 | ## [3.1.0](https://github.com/bjerkio/oidc-react/compare/v3.0.4...v3.1.0) (2023-04-21) 28 | 29 | 30 | ### Features 31 | 32 | * add `metadata` parameter to AuthContext ([1e6703b](https://github.com/bjerkio/oidc-react/commit/1e6703b11a8eda0ced7e76cd9e8a27b5abb902f9)) 33 | 34 | ## [3.0.4](https://github.com/bjerkio/oidc-react/compare/oidc-react-v3.0.4...oidc-react-v3.0.4) (2023-04-10) 35 | 36 | 37 | ### Bug Fixes 38 | 39 | * isLoading has correct status when autoSignIn is disabled and user is signed out ([#982](https://github.com/bjerkio/oidc-react/issues/982)) ([db28cdd](https://github.com/bjerkio/oidc-react/commit/db28cdd6a6368d8d07f01f1827d77afd18d70bf1)) 40 | 41 | 42 | ### Miscellaneous Chores 43 | 44 | * **main:** release 3.0.4 ([01051e9](https://github.com/bjerkio/oidc-react/commit/01051e9d8117cba5ca0ddb631a20a5af179214ec)) 45 | 46 | ## [3.0.3](https://github.com/bjerkio/oidc-react/compare/v3.0.2...v3.0.3) (2023-03-16) 47 | 48 | 49 | ### Bug Fixes 50 | 51 | * handle both null user and user.expired when autoSignIn is disabled ([#977](https://github.com/bjerkio/oidc-react/issues/977)) ([1a95930](https://github.com/bjerkio/oidc-react/commit/1a9593060f902ae89880fb6bfd076bb24fbac8ab)) 52 | 53 | ## [3.0.2](https://github.com/bjerkio/oidc-react/compare/v3.0.1...v3.0.2) (2023-03-12) 54 | 55 | 56 | ### Bug Fixes 57 | 58 | * handle token refresh failure ([#968](https://github.com/bjerkio/oidc-react/issues/968)) ([751732b](https://github.com/bjerkio/oidc-react/commit/751732b636b1911ff07bb86e34fff80ff5f39933)) 59 | 60 | ## [3.0.1](https://github.com/bjerkio/oidc-react/compare/v3.0.0...v3.0.1) (2023-03-08) 61 | 62 | 63 | ### Bug Fixes 64 | 65 | * avoid reinitiating partial authentication flow when user is already authenticated ([#962](https://github.com/bjerkio/oidc-react/issues/962)) ([7c88d80](https://github.com/bjerkio/oidc-react/commit/7c88d800d2dd64f8b032787076709fc98cf8486d)) 66 | 67 | ## [3.0.0](https://github.com/bjerkio/oidc-react/compare/v2.1.0...v3.0.0) (2023-03-01) 68 | 69 | 70 | ### ⚠ BREAKING CHANGES 71 | 72 | * `signIn` and `signOutRedirect` now has it's own types. 73 | 74 | ### Features 75 | 76 | * add sourcemap and comments ([#947](https://github.com/bjerkio/oidc-react/issues/947)) ([a605296](https://github.com/bjerkio/oidc-react/commit/a605296a7ebffe9952850593b22670475f4701f9)) 77 | * pin and update all dependencies ([#948](https://github.com/bjerkio/oidc-react/issues/948)) ([caf90a7](https://github.com/bjerkio/oidc-react/commit/caf90a789c1864b01648578c874ca85b818cdf0a)) 78 | * update + pin a key dependencies in use ([#945](https://github.com/bjerkio/oidc-react/issues/945)) ([9e69e80](https://github.com/bjerkio/oidc-react/commit/9e69e80a5fc1e2596ed2b176f95d3ae8b3ac655b)) 79 | 80 | 81 | ### Bug Fixes 82 | 83 | * remove bundlesize dependency ([#936](https://github.com/bjerkio/oidc-react/issues/936)) ([e9f8d8a](https://github.com/bjerkio/oidc-react/commit/e9f8d8a596eb695c875956bd00c3c379fb4e4898)) 84 | * validation environment ([#945](https://github.com/bjerkio/oidc-react/issues/945)) ([9e69e80](https://github.com/bjerkio/oidc-react/commit/9e69e80a5fc1e2596ed2b176f95d3ae8b3ac655b)) 85 | 86 | 87 | ### Code Refactoring 88 | 89 | * add types ([#945](https://github.com/bjerkio/oidc-react/issues/945)) ([9e69e80](https://github.com/bjerkio/oidc-react/commit/9e69e80a5fc1e2596ed2b176f95d3ae8b3ac655b)) 90 | 91 | ## [2.1.0](https://github.com/bjerkio/oidc-react/compare/v2.0.3...v2.1.0) (2022-10-23) 92 | 93 | 94 | ### Features 95 | 96 | * add extraQueryParams to AuthProvider ([#890](https://github.com/bjerkio/oidc-react/issues/890)) ([89dc4ea](https://github.com/bjerkio/oidc-react/commit/89dc4ea0a1aaecabe73c164a7f519b03e94c28d4)) 97 | 98 | ## [2.0.3](https://github.com/bjerkio/oidc-react/compare/v2.0.2...v2.0.3) (2022-08-04) 99 | 100 | 101 | ### Bug Fixes 102 | 103 | * use memoized context value ([#880](https://github.com/bjerkio/oidc-react/issues/880)) ([3342a8d](https://github.com/bjerkio/oidc-react/commit/3342a8d29a7b42d4428bd01a409ca079619e9549)) 104 | 105 | ## [2.0.2](https://github.com/bjerkio/oidc-react/compare/v2.0.1...v2.0.2) (2022-08-03) 106 | 107 | 108 | ### Bug Fixes 109 | 110 | * alway userData=null - isLoading=true ([#877](https://github.com/bjerkio/oidc-react/issues/877)) ([d2d78ce](https://github.com/bjerkio/oidc-react/commit/d2d78ce29fced9598bf9928fd4561fb83c9d9834)) 111 | 112 | ## [2.0.1](https://github.com/bjerkio/oidc-react/compare/v2.0.0...v2.0.1) (2022-08-02) 113 | 114 | 115 | ### Bug Fixes 116 | 117 | * Add React 17 to peer dependencies ([#874](https://github.com/bjerkio/oidc-react/issues/874)) ([54fd6e0](https://github.com/bjerkio/oidc-react/commit/54fd6e0ea21b773e26e9e5fb0a42610de54097e5)) 118 | 119 | ## [2.0.0](https://github.com/bjerkio/oidc-react/compare/v1.5.1...v2.0.0) (2022-07-25) 120 | 121 | 122 | ### ⚠ BREAKING CHANGES 123 | 124 | * replace oidc-client-js with oidc-client-ts (#860) 125 | * migrate to react 18 (#827) 126 | 127 | ### Features 128 | 129 | * create ES5 output for IE11 compatibility. ([#696](https://github.com/bjerkio/oidc-react/issues/696)) ([4d9712c](https://github.com/bjerkio/oidc-react/commit/4d9712c1882384cc89311c16a56bc6b091a53b0c)) 130 | * migrate to react 18 ([#827](https://github.com/bjerkio/oidc-react/issues/827)) ([28e998a](https://github.com/bjerkio/oidc-react/commit/28e998a1c56c8fd32ef15143ae4d31993f8d22d5)) 131 | 132 | 133 | ### Bug Fixes 134 | 135 | * initUserManager in AuthContext called every render call ([#764](https://github.com/bjerkio/oidc-react/issues/764)) ([2cef6c7](https://github.com/bjerkio/oidc-react/commit/2cef6c748be19f278ba49900025f92dbd392885e)) 136 | * move release-please to after checkout ([9b70ccf](https://github.com/bjerkio/oidc-react/commit/9b70ccf581e8844d63717a17797790a0c0419443)) 137 | 138 | 139 | ### Code Refactoring 140 | 141 | * replace oidc-client-js with oidc-client-ts ([#860](https://github.com/bjerkio/oidc-react/issues/860)) ([a07bb70](https://github.com/bjerkio/oidc-react/commit/a07bb705d4cd6d4074a055f46b83b2b4053fed1b)) 142 | 143 | ## [1.6.0](https://github.com/bjerkio/oidc-react/compare/v1.5.1...v1.6.0) (2022-07-15) 144 | 145 | ### Features 146 | 147 | * Change dependency from no longer maintained [oidc-client-js](https://github.com/IdentityModel/oidc-client-js) to its official successor [oidc-client-ts](https://github.com/authts/oidc-client-ts) 148 | 149 | 150 | ## [1.5.1](https://github.com/bjerkio/oidc-react/compare/v1.5.0...v1.5.1) (2021-04-11) 151 | 152 | 153 | ### Bug Fixes 154 | 155 | * AuthContext cannot be null ([#576](https://github.com/bjerkio/oidc-react/issues/576)) ([61bd0fa](https://github.com/bjerkio/oidc-react/commit/61bd0fa65dbd682437aee3aae13258b8f4668f69)) 156 | 157 | # [1.5.0](https://github.com/bjerkio/oidc-react/compare/v1.4.0...v1.5.0) (2021-04-10) 158 | 159 | 160 | ### Features 161 | 162 | * `isLoading` state ([#577](https://github.com/bjerkio/oidc-react/issues/577)) ([b24e9ff](https://github.com/bjerkio/oidc-react/commit/b24e9ff5434b7ddf59000890637fbca36cf8e8ec)) 163 | 164 | # [1.4.0](https://github.com/bjerkio/oidc-react/compare/v1.3.0...v1.4.0) (2021-03-15) 165 | 166 | 167 | ### Features 168 | 169 | * Add silentRedirectUri option. ([#528](https://github.com/bjerkio/oidc-react/issues/528)) ([a349d4d](https://github.com/bjerkio/oidc-react/commit/a349d4dc770ed22af9c68b9c5c178550382e7006)) 170 | 171 | # [1.3.0](https://github.com/bjerkio/oidc-react/compare/v1.2.1...v1.3.0) (2021-03-11) 172 | 173 | 174 | ### Features 175 | 176 | * upgrade to oidc-client 1.11.5 ([#527](https://github.com/bjerkio/oidc-react/issues/527)) ([3943c94](https://github.com/bjerkio/oidc-react/commit/3943c942237cfc6bbe8346ef1543a9a0fcf202f9)) 177 | 178 | ## [1.2.1](https://github.com/bjerkio/oidc-react/compare/v1.2.0...v1.2.1) (2021-03-09) 179 | 180 | 181 | ### Bug Fixes 182 | 183 | * state update on an unmounted component ([#522](https://github.com/bjerkio/oidc-react/issues/522)) ([0e873f4](https://github.com/bjerkio/oidc-react/commit/0e873f4e6ac7d14cc39f4cb5196b2a79b866da93)) 184 | 185 | # [1.2.0](https://github.com/bjerkio/oidc-react/compare/v1.1.6...v1.2.0) (2021-03-08) 186 | 187 | 188 | ### Features 189 | 190 | * Add signInPopup method ([#479](https://github.com/bjerkio/oidc-react/issues/479)) ([a50c196](https://github.com/bjerkio/oidc-react/commit/a50c196bba92cc95698eb10d7e5b68eb7b0959b1)) 191 | 192 | ## [1.1.6](https://github.com/bjerkio/oidc-react/compare/v1.1.5...v1.1.6) (2021-02-03) 193 | 194 | 195 | ### Bug Fixes 196 | 197 | * Remove `getUser` in callback handler ([#461](https://github.com/bjerkio/oidc-react/issues/461)) ([7abb83d](https://github.com/bjerkio/oidc-react/commit/7abb83d97135aed1370c3a86582a1a689fa676f5)), closes [#447](https://github.com/bjerkio/oidc-react/issues/447) 198 | 199 | ## [1.1.5](https://github.com/bjerkio/oidc-react/compare/v1.1.4...v1.1.5) (2020-12-22) 200 | 201 | 202 | ### Bug Fixes 203 | 204 | * Load new state from session/local storage when available after a silent renew ([#363](https://github.com/bjerkio/oidc-react/issues/363)) ([319d0e3](https://github.com/bjerkio/oidc-react/commit/319d0e34d3f890a4838f436af6b4cb3859a0ad85)) 205 | 206 | ## [1.1.4](https://github.com/bjerkio/oidc-react/compare/v1.1.3...v1.1.4) (2020-12-19) 207 | 208 | 209 | ### Bug Fixes 210 | 211 | * Including 'Log' in export ([#383](https://github.com/bjerkio/oidc-react/issues/383)) ([1f10c07](https://github.com/bjerkio/oidc-react/commit/1f10c075f90dcf0e2abb3d48ea768c38164f2f74)) 212 | 213 | ## [1.1.3](https://github.com/bjerkio/oidc-react/compare/v1.1.2...v1.1.3) (2020-10-24) 214 | 215 | 216 | ### Bug Fixes 217 | 218 | * Remove react-router 🤷 ([527bcd3](https://github.com/bjerkio/oidc-react/commit/527bcd3a9d07fd3097924d022b13d31afb7d2dcf)) 219 | 220 | ## [1.1.2](https://github.com/bjerkio/oidc-react/compare/v1.1.1...v1.1.2) (2020-10-24) 221 | 222 | 223 | ### Bug Fixes 224 | 225 | * Move react, react-dom to peerDependencies ([b4fd437](https://github.com/bjerkio/oidc-react/commit/b4fd437dfb81248766cb5be59b2bd684e95dcf7e)), closes [#301](https://github.com/bjerkio/oidc-react/issues/301) 226 | 227 | ## [1.1.1](https://github.com/bjerkio/oidc-react/compare/v1.1.0...v1.1.1) (2020-10-09) 228 | 229 | 230 | ### Bug Fixes 231 | 232 | * change callback method to allow other sign in method ([c497f49](https://github.com/bjerkio/oidc-react/commit/c497f49ddbca100ff5f52419ce07ac64c00d2656)) 233 | 234 | # [1.1.0](https://github.com/bjerkio/oidc-react/compare/v1.0.1...v1.1.0) (2020-09-26) 235 | 236 | 237 | ### Features 238 | 239 | * add auto silent renew option ([6bb2df5](https://github.com/bjerkio/oidc-react/commit/6bb2df5e1c7c8b9f12fc220bcd51c1eac4890fe4)) 240 | 241 | ## [1.0.1](https://github.com/bjerkio/oidc-react/compare/v1.0.0...v1.0.1) (2020-08-21) 242 | 243 | 244 | ### Bug Fixes 245 | 246 | * this._signinStart is not a function ([20b1e57](https://github.com/bjerkio/oidc-react/commit/20b1e57b1b8a15276a04498081560ccce03e0c73)), closes [#173](https://github.com/bjerkio/oidc-react/issues/173) 247 | 248 | # 1.0.0 (2020-08-20) 249 | 250 | 251 | ### Bug Fixes 252 | 253 | * Autosignin on expired user ([d5dce04](https://github.com/bjerkio/oidc-react/commit/d5dce04f51bdfcff49ab622f60875aedfe17fdb5)) 254 | * Fix withAuth export ([4e0e2e1](https://github.com/bjerkio/oidc-react/commit/4e0e2e11675eda83fc543779d53f51f2ff96284e)) 255 | * Package size and target ([b9c8205](https://github.com/bjerkio/oidc-react/commit/b9c820524cd34f030d823af867df3d51ad2d2bd7)) 256 | * Useless conditional ([6cf9dda](https://github.com/bjerkio/oidc-react/commit/6cf9ddad48728b50c4f17ce7ade18f67ee1faccf)) 257 | * Variable 'user' cannot be of type null ([0d8a0c3](https://github.com/bjerkio/oidc-react/commit/0d8a0c3110aec43b4e8c22b6385df8fcbd64147d)) 258 | 259 | 260 | ### Code Refactoring 261 | 262 | * Improve createContext setup ([6b715f5](https://github.com/bjerkio/oidc-react/commit/6b715f5ad8f78fdb1306cfc399b5f26a2bdc5a14)) 263 | 264 | 265 | ### Features 266 | 267 | * add client_secret ([151a494](https://github.com/bjerkio/oidc-react/commit/151a494a0faf48483086ce75435ab033335c54ca)) 268 | * Add improved API layout ([1e3d66a](https://github.com/bjerkio/oidc-react/commit/1e3d66a1d336d6f0e6e6310e33b4061e9c50e46a)), closes [#36](https://github.com/bjerkio/oidc-react/issues/36) 269 | * Add onBeforeSignIn hook ([e2f609e](https://github.com/bjerkio/oidc-react/commit/e2f609ef205cc05f4040a6281460ccd2a2441e35)) 270 | * add option to use signoutRedirect ([9ca3ada](https://github.com/bjerkio/oidc-react/commit/9ca3ada0e2ef1fdba81397ec2044928cc5844a87)) 271 | * add option to use signoutRedirect ([d2c4278](https://github.com/bjerkio/oidc-react/commit/d2c42782edd676ae68ccedf45dde18d696f32447)) 272 | * Add responseType and scope properties ([e00454a](https://github.com/bjerkio/oidc-react/commit/e00454a50606d287063a3134cfe3740e2ee360f8)) 273 | * Add withAuth higher order component ([9f2cea8](https://github.com/bjerkio/oidc-react/commit/9f2cea8c74476a7e74490cd8ae18e82a832d18e0)) 274 | * First implementation ([071d311](https://github.com/bjerkio/oidc-react/commit/071d311b7bd4810648c7a18150e2d98e23328258)) 275 | * re-export User and UserManager ([a2fdf39](https://github.com/bjerkio/oidc-react/commit/a2fdf39c88dadfe28e8f605ddfc5825c294a017b)) 276 | 277 | 278 | ### BREAKING CHANGES 279 | 280 | * Typescript users might not expect the Context to be 'null'. Now you have to check 281 | it. 282 | 283 | # [1.0.0-alpha.7](https://github.com/bjerkio/oidc-react/compare/v1.0.0-alpha.6...v1.0.0-alpha.7) (2020-05-15) 284 | 285 | 286 | ### Bug Fixes 287 | 288 | * Useless conditional ([6cf9dda](https://github.com/bjerkio/oidc-react/commit/6cf9ddad48728b50c4f17ce7ade18f67ee1faccf)) 289 | * Variable 'user' cannot be of type null ([0d8a0c3](https://github.com/bjerkio/oidc-react/commit/0d8a0c3110aec43b4e8c22b6385df8fcbd64147d)) 290 | 291 | 292 | ### Code Refactoring 293 | 294 | * Improve createContext setup ([6b715f5](https://github.com/bjerkio/oidc-react/commit/6b715f5ad8f78fdb1306cfc399b5f26a2bdc5a14)) 295 | 296 | 297 | ### Features 298 | 299 | * Add improved API layout ([1e3d66a](https://github.com/bjerkio/oidc-react/commit/1e3d66a1d336d6f0e6e6310e33b4061e9c50e46a)), closes [#36](https://github.com/bjerkio/oidc-react/issues/36) 300 | * add option to use signoutRedirect ([d2c4278](https://github.com/bjerkio/oidc-react/commit/d2c42782edd676ae68ccedf45dde18d696f32447)) 301 | 302 | 303 | ### BREAKING CHANGES 304 | 305 | * Typescript users might not expect the Context to be 'null'. Now you have to check 306 | it. 307 | 308 | # [1.0.0-alpha.6](https://github.com/bjerkio/oidc-react/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2020-05-15) 309 | 310 | 311 | ### Features 312 | 313 | * add option to use signoutRedirect ([9ca3ada](https://github.com/bjerkio/oidc-react/commit/9ca3ada0e2ef1fdba81397ec2044928cc5844a87)) 314 | 315 | # [1.0.0-alpha.5](https://github.com/bjerkio/oidc-react/compare/v1.0.0-alpha.4...v1.0.0-alpha.5) (2020-04-21) 316 | 317 | 318 | ### Bug Fixes 319 | 320 | * Autosignin on expired user ([d5dce04](https://github.com/bjerkio/oidc-react/commit/d5dce04f51bdfcff49ab622f60875aedfe17fdb5)) 321 | * Fix withAuth export ([4e0e2e1](https://github.com/bjerkio/oidc-react/commit/4e0e2e11675eda83fc543779d53f51f2ff96284e)) 322 | 323 | # [1.0.0-alpha.4](https://github.com/bjerkio/oidc-react/compare/v1.0.0-alpha.3...v1.0.0-alpha.4) (2020-04-16) 324 | 325 | 326 | ### Features 327 | 328 | * Add onBeforeSignIn hook ([e2f609e](https://github.com/bjerkio/oidc-react/commit/e2f609ef205cc05f4040a6281460ccd2a2441e35)) 329 | * Add withAuth higher order component ([9f2cea8](https://github.com/bjerkio/oidc-react/commit/9f2cea8c74476a7e74490cd8ae18e82a832d18e0)) 330 | 331 | # [1.0.0-alpha.3](https://github.com/bjerkio/oidc-react/compare/v1.0.0-alpha.2...v1.0.0-alpha.3) (2020-04-09) 332 | 333 | 334 | ### Bug Fixes 335 | 336 | * Package size and target ([b9c8205](https://github.com/bjerkio/oidc-react/commit/b9c820524cd34f030d823af867df3d51ad2d2bd7)) 337 | 338 | # [1.0.0-alpha.2](https://github.com/bjerkio/oidc-react/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2020-04-09) 339 | 340 | 341 | ### Features 342 | 343 | * Add responseType and scope properties ([e00454a](https://github.com/bjerkio/oidc-react/commit/e00454a50606d287063a3134cfe3740e2ee360f8)) 344 | 345 | # 1.0.0-alpha.1 (2020-04-09) 346 | 347 | 348 | ### Features 349 | 350 | * First implementation ([071d311](https://github.com/bjerkio/oidc-react/commit/071d311b7bd4810648c7a18150e2d98e23328258)) 351 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to oidc-react 2 | 3 | :+1::tada: Thanks for taking the time to contribute! :tada::+1: 4 | 5 | The following is a set of guidelines for contributing. These are just 6 | guidelines, not rules, so use your best judgment and feel free to propose 7 | changes to this document in a pull request. 8 | 9 | ## Issues and Pull Requests 10 | 11 | - If you're not sure about adding something, 12 | [open an issue](https://github.com/bjerkio/oidc-react/issues/new) to discuss 13 | it. 14 | - Feel free to open a Pull Request early so that a discussion can be had as 15 | changes are developed. 16 | 17 | ## Commit Messages and Pull Request Titles 18 | 19 | We use the 20 | [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) 21 | specification to standardize our commit history. To enforce this convention on 22 | commit messages and/or pull request titles, we use the 23 | [Semantic Pull Requests](https://github.com/probot/semantic-pull-requests) bot. 24 | 25 | The commit message summary (or pull request title) is constructed by prepending 26 | the type of change being made (e.g., feat, fix, refactor), followed by an 27 | imperative, present tense sentence (without a period). Example: 28 | `fix: make header bold`. 29 | 30 | If you are still working on your pull request, prepend `WIP:` to indicate that 31 | it's work in progress. 32 | 33 | ### Pull Request Title 34 | 35 | Same as commit messages, prepend the type of change being made (refactor, fix, 36 | chore, feat, etc.) Example: `docs: add linux setup instructions` 37 | 38 | ## Documentation 39 | 40 | Most of the documentation are automatically generated. We utilize `typedoc` that 41 | uses tags inline with classes in order to generate. The nice thing about this is 42 | that documentation will be visible when using Typescript in editors as well. 43 | 44 | However, we love to have examples and guides as well. 45 | 46 | ## Need Help? 47 | 48 | If any of this information confusing, incorrect, or incomplete, feel free to 49 | [open an issue](https://github.com/bjerkio/oidc-react/issues/new) for help. 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Bjerk AS 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included 11 | in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 14 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 15 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 17 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 18 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 19 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OIDC React 2 | 3 | [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) 4 | [![code style: airbnb](https://img.shields.io/badge/eslint-airbnb-ff5a5f.svg?style=flat-square)](https://github.com/prettier/prettier) 5 | [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/) 6 | [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release) 7 | [![codecov](https://codecov.io/gh/bjerkio/oidc-react/branch/master/graph/badge.svg)](https://codecov.io/gh/bjerkio/oidc-react) 8 | 9 | ![oidc-react logo](assets/logo.jpg) 10 | 11 | ## About 12 | 13 | React component (AuthProvider) to provide OpenID Connect and OAuth2 protocol 14 | support. Has [hooks](guides/HOOKS.md) 🎉 15 | 16 | Based on [oidc-client-ts](https://github.com/authts/oidc-client-ts). 17 | 18 | ## Quickstart 19 | 20 | Install packages by running: 21 | 22 | ```shell 23 | $ npm install oidc-react 24 | ``` 25 | 26 | ## Usage 27 | 28 | ```tsx 29 | import { AuthProvider } from 'oidc-react'; 30 | 31 | const oidcConfig = { 32 | onSignIn: () => { 33 | // Redirect? 34 | }, 35 | authority: 'https://oidc.io/oauth', 36 | clientId: 'this-is-a-client-id', 37 | redirectUri: 'https://my-app.com/', 38 | }; 39 | 40 | const Routes = () => ( 41 | 42 | 43 | 44 | 45 | 46 | ... 47 | 48 | 49 | ); 50 | ``` 51 | 52 | # Documentation 53 | 54 | Apart from this README, you can find details and examples of using the SDK in 55 | the following places: 56 | 57 | - [SDK Documentation](docs/README.md) 58 | - [Guides](guides/) 59 | - [Example repository](https://github.com/simenandre/example-oidc-react) 60 | - [oidc-client-ts Documentation](https://authts.github.io/oidc-client-ts/) 61 | 62 | ## Contribute & Disclaimer 63 | 64 | We love to get help 🙏 Read more about how to get started in 65 | [CONTRIBUTING](CONTRIBUTING.md) 🌳 66 | -------------------------------------------------------------------------------- /assets/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bjerkio/oidc-react/991ba4b1888b3b91d67c4505fe04f6d9d9e1b2c4/assets/logo.jpg -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | **oidc-react** • **Docs** 2 | 3 | *** 4 | 5 | # oidc-react 6 | 7 | ## Interfaces 8 | 9 | - [AuthContextProps](interfaces/AuthContextProps.md) 10 | - [AuthProviderProps](interfaces/AuthProviderProps.md) 11 | - [AuthProviderSignOutProps](interfaces/AuthProviderSignOutProps.md) 12 | - [Location](interfaces/Location.md) 13 | 14 | ## Variables 15 | 16 | - [AuthContext](variables/AuthContext.md) 17 | 18 | ## Functions 19 | 20 | - [AuthProvider](functions/AuthProvider.md) 21 | - [useAuth](functions/useAuth.md) 22 | - [withAuth](functions/withAuth.md) 23 | -------------------------------------------------------------------------------- /docs/functions/AuthProvider.md: -------------------------------------------------------------------------------- 1 | [**oidc-react**](../README.md) • **Docs** 2 | 3 | *** 4 | 5 | [oidc-react](../README.md) / AuthProvider 6 | 7 | # Function: AuthProvider() 8 | 9 | > **AuthProvider**(`props`, `deprecatedLegacyContext`?): `ReactNode` 10 | 11 | ## Parameters 12 | 13 | • **props**: `PropsWithChildren`\<[`AuthProviderProps`](../interfaces/AuthProviderProps.md)\> 14 | 15 | AuthProviderProps 16 | 17 | • **deprecatedLegacyContext?**: `any` 18 | 19 | **Deprecated** 20 | 21 | **See** 22 | 23 | [React Docs](https://legacy.reactjs.org/docs/legacy-context.html#referencing-context-in-lifecycle-methods) 24 | 25 | ## Returns 26 | 27 | `ReactNode` 28 | 29 | ## Defined in 30 | 31 | [src/auth-context.tsx:96](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context.tsx#L96) 32 | -------------------------------------------------------------------------------- /docs/functions/useAuth.md: -------------------------------------------------------------------------------- 1 | [**oidc-react**](../README.md) • **Docs** 2 | 3 | *** 4 | 5 | [oidc-react](../README.md) / useAuth 6 | 7 | # Function: useAuth() 8 | 9 | > **useAuth**(): [`AuthContextProps`](../interfaces/AuthContextProps.md) 10 | 11 | ## Returns 12 | 13 | [`AuthContextProps`](../interfaces/AuthContextProps.md) 14 | 15 | ## Defined in 16 | 17 | [src/use-auth.ts:6](https://github.com/bjerkio/oidc-react/blob/main/src/use-auth.ts#L6) 18 | -------------------------------------------------------------------------------- /docs/functions/withAuth.md: -------------------------------------------------------------------------------- 1 | [**oidc-react**](../README.md) • **Docs** 2 | 3 | *** 4 | 5 | [oidc-react](../README.md) / withAuth 6 | 7 | # Function: withAuth() 8 | 9 | > **withAuth**\<`P`\>(`Component`): `React.ComponentType`\<`Omit`\<`P`, keyof [`AuthContextProps`](../interfaces/AuthContextProps.md)\>\> 10 | 11 | A public higher-order component to access the imperative API 12 | 13 | ## Type Parameters 14 | 15 | • **P** *extends* [`AuthContextProps`](../interfaces/AuthContextProps.md) 16 | 17 | ## Parameters 18 | 19 | • **Component**: `ComponentType`\<`P`\> 20 | 21 | ## Returns 22 | 23 | `React.ComponentType`\<`Omit`\<`P`, keyof [`AuthContextProps`](../interfaces/AuthContextProps.md)\>\> 24 | 25 | ## Defined in 26 | 27 | [src/with-auth.tsx:8](https://github.com/bjerkio/oidc-react/blob/main/src/with-auth.tsx#L8) 28 | -------------------------------------------------------------------------------- /docs/interfaces/AuthContextProps.md: -------------------------------------------------------------------------------- 1 | [**oidc-react**](../README.md) • **Docs** 2 | 3 | *** 4 | 5 | [oidc-react](../README.md) / AuthContextProps 6 | 7 | # Interface: AuthContextProps 8 | 9 | ## Properties 10 | 11 | ### isLoading 12 | 13 | > **isLoading**: `boolean` 14 | 15 | Auth state: True until the library has been initialized. 16 | 17 | #### Defined in 18 | 19 | [src/auth-context-interface.ts:181](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L181) 20 | 21 | *** 22 | 23 | ### signIn() 24 | 25 | > **signIn**: (`args`?) => `Promise`\<`void`\> 26 | 27 | Alias for userManager.signInRedirect 28 | 29 | #### Parameters 30 | 31 | • **args?**: `SigninRedirectArgs` 32 | 33 | #### Returns 34 | 35 | `Promise`\<`void`\> 36 | 37 | #### Defined in 38 | 39 | [src/auth-context-interface.ts:157](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L157) 40 | 41 | *** 42 | 43 | ### signInPopup() 44 | 45 | > **signInPopup**: () => `Promise`\<`void`\> 46 | 47 | Alias for userManager.signinPopup 48 | 49 | #### Returns 50 | 51 | `Promise`\<`void`\> 52 | 53 | #### Defined in 54 | 55 | [src/auth-context-interface.ts:161](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L161) 56 | 57 | *** 58 | 59 | ### signOut() 60 | 61 | > **signOut**: () => `Promise`\<`void`\> 62 | 63 | Alias for removeUser 64 | 65 | #### Returns 66 | 67 | `Promise`\<`void`\> 68 | 69 | #### Defined in 70 | 71 | [src/auth-context-interface.ts:165](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L165) 72 | 73 | *** 74 | 75 | ### signOutRedirect() 76 | 77 | > **signOutRedirect**: (`args`?) => `Promise`\<`void`\> 78 | 79 | #### Parameters 80 | 81 | • **args?**: `SignoutRedirectArgs` 82 | 83 | #### Returns 84 | 85 | `Promise`\<`void`\> 86 | 87 | #### Defined in 88 | 89 | [src/auth-context-interface.ts:169](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L169) 90 | 91 | *** 92 | 93 | ### userData? 94 | 95 | > `optional` **userData**: `null` \| `User` 96 | 97 | See [User](https://authts.github.io/oidc-client-ts/classes/User.html) for more details. 98 | 99 | #### Defined in 100 | 101 | [src/auth-context-interface.ts:177](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L177) 102 | 103 | *** 104 | 105 | ### userManager 106 | 107 | > **userManager**: `UserManager` 108 | 109 | See [UserManager](https://authts.github.io/oidc-client-ts/classes/UserManager.html) for more details. 110 | 111 | #### Defined in 112 | 113 | [src/auth-context-interface.ts:173](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L173) 114 | -------------------------------------------------------------------------------- /docs/interfaces/AuthProviderProps.md: -------------------------------------------------------------------------------- 1 | [**oidc-react**](../README.md) • **Docs** 2 | 3 | *** 4 | 5 | [oidc-react](../README.md) / AuthProviderProps 6 | 7 | # Interface: AuthProviderProps 8 | 9 | ## Properties 10 | 11 | ### authority? 12 | 13 | > `optional` **authority**: `string` 14 | 15 | The URL of the OIDC/OAuth2 provider. 16 | 17 | #### Defined in 18 | 19 | [src/auth-context-interface.ts:41](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L41) 20 | 21 | *** 22 | 23 | ### automaticSilentRenew? 24 | 25 | > `optional` **automaticSilentRenew**: `boolean` 26 | 27 | Flag to indicate if there should be an automatic attempt to renew the access token prior to its expiration. 28 | 29 | Defaults to true. 30 | 31 | #### Defined in 32 | 33 | [src/auth-context-interface.ts:109](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L109) 34 | 35 | *** 36 | 37 | ### autoSignIn? 38 | 39 | > `optional` **autoSignIn**: `boolean` 40 | 41 | Flag to control automatic redirection to the OIDC/OAuth2 provider when not signed in. 42 | 43 | Defaults to true. 44 | 45 | #### Defined in 46 | 47 | [src/auth-context-interface.ts:89](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L89) 48 | 49 | *** 50 | 51 | ### autoSignInArgs? 52 | 53 | > `optional` **autoSignInArgs**: `SigninRedirectArgs` 54 | 55 | Optional sign in arguments to be used when `autoSignIn` is enabled. 56 | 57 | #### Defined in 58 | 59 | [src/auth-context-interface.ts:93](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L93) 60 | 61 | *** 62 | 63 | ### autoSignOut? 64 | 65 | > `optional` **autoSignOut**: `boolean` 66 | 67 | Flag to control automatic sign out redirection to the OIDC/OAuth2 provider when silent renewal fails. 68 | 69 | Defaults to true. 70 | 71 | #### Defined in 72 | 73 | [src/auth-context-interface.ts:99](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L99) 74 | 75 | *** 76 | 77 | ### autoSignOutArgs? 78 | 79 | > `optional` **autoSignOutArgs**: `SignoutRedirectArgs` 80 | 81 | Optional sign out arguments to be used when `autoSignOut` is enabled. 82 | 83 | #### Defined in 84 | 85 | [src/auth-context-interface.ts:103](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L103) 86 | 87 | *** 88 | 89 | ### clientId? 90 | 91 | > `optional` **clientId**: `string` 92 | 93 | Your client application's identifier as registered with the OIDC/OAuth2 provider. 94 | 95 | #### Defined in 96 | 97 | [src/auth-context-interface.ts:53](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L53) 98 | 99 | *** 100 | 101 | ### clientSecret? 102 | 103 | > `optional` **clientSecret**: `string` 104 | 105 | Client secret defined on the identity server. 106 | 107 | #### Defined in 108 | 109 | [src/auth-context-interface.ts:57](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L57) 110 | 111 | *** 112 | 113 | ### extraQueryParams? 114 | 115 | > `optional` **extraQueryParams**: `Record`\<`string`, `string`\> 116 | 117 | Extra query params passed to the authorization url. 118 | 119 | #### Defined in 120 | 121 | [src/auth-context-interface.ts:49](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L49) 122 | 123 | *** 124 | 125 | ### loadUserInfo? 126 | 127 | > `optional` **loadUserInfo**: `boolean` 128 | 129 | Flag to control if additional identity data is loaded from the user info endpoint in order to populate the user's profile. 130 | 131 | Defaults to true. 132 | 133 | #### Defined in 134 | 135 | [src/auth-context-interface.ts:115](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L115) 136 | 137 | *** 138 | 139 | ### location? 140 | 141 | > `optional` **location**: [`Location`](Location.md) 142 | 143 | Defaults to `windows.location`. 144 | 145 | #### Defined in 146 | 147 | [src/auth-context-interface.ts:83](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L83) 148 | 149 | *** 150 | 151 | ### metadata? 152 | 153 | > `optional` **metadata**: `Partial`\<`OidcMetadata`\> 154 | 155 | Manually set metadata if CORS is not configured on the OIDC/OAuth2 provider. 156 | 157 | #### Defined in 158 | 159 | [src/auth-context-interface.ts:45](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L45) 160 | 161 | *** 162 | 163 | ### onBeforeSignIn()? 164 | 165 | > `optional` **onBeforeSignIn**: () => `unknown` 166 | 167 | On before sign in hook. Can be use to store the current url for use after signing in. 168 | 169 | This only gets called if autoSignIn is true 170 | 171 | #### Returns 172 | 173 | `unknown` 174 | 175 | #### Defined in 176 | 177 | [src/auth-context-interface.ts:136](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L136) 178 | 179 | *** 180 | 181 | ### onSignIn()? 182 | 183 | > `optional` **onSignIn**: (`userData`) => `void` \| `Promise`\<`void`\> 184 | 185 | On sign in hook. Can be a async function. 186 | 187 | #### Parameters 188 | 189 | • **userData**: `null` \| `User` 190 | 191 | User 192 | 193 | #### Returns 194 | 195 | `void` \| `Promise`\<`void`\> 196 | 197 | #### Defined in 198 | 199 | [src/auth-context-interface.ts:141](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L141) 200 | 201 | *** 202 | 203 | ### onSignInError()? 204 | 205 | > `optional` **onSignInError**: (`error`) => `void` 206 | 207 | On sign in error. Can be a async function. 208 | 209 | #### Parameters 210 | 211 | • **error**: `Error` 212 | 213 | #### Returns 214 | 215 | `void` 216 | 217 | #### Defined in 218 | 219 | [src/auth-context-interface.ts:150](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L150) 220 | 221 | *** 222 | 223 | ### onSignOut()? 224 | 225 | > `optional` **onSignOut**: (`options`?) => `void` \| `Promise`\<`void`\> 226 | 227 | On sign out hook. Can be a async function. 228 | 229 | #### Parameters 230 | 231 | • **options?**: [`AuthProviderSignOutProps`](AuthProviderSignOutProps.md) 232 | 233 | #### Returns 234 | 235 | `void` \| `Promise`\<`void`\> 236 | 237 | #### Defined in 238 | 239 | [src/auth-context-interface.ts:145](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L145) 240 | 241 | *** 242 | 243 | ### popupRedirectUri? 244 | 245 | > `optional` **popupRedirectUri**: `string` 246 | 247 | The URL for the page containing the call to signinPopupCallback to handle the callback from the OIDC/OAuth2 248 | 249 | #### Defined in 250 | 251 | [src/auth-context-interface.ts:126](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L126) 252 | 253 | *** 254 | 255 | ### popupWindowFeatures? 256 | 257 | > `optional` **popupWindowFeatures**: `PopupWindowFeatures` 258 | 259 | The features parameter to window.open for the popup signin window 260 | 261 | defaults to 'location=no,toolbar=no,width=500,height=500,left=100,top=100' 262 | 263 | #### Defined in 264 | 265 | [src/auth-context-interface.ts:121](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L121) 266 | 267 | *** 268 | 269 | ### popupWindowTarget? 270 | 271 | > `optional` **popupWindowTarget**: `string` 272 | 273 | The target parameter to window.open for the popup signin window. * 274 | defaults to '_blank' 275 | 276 | #### Defined in 277 | 278 | [src/auth-context-interface.ts:131](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L131) 279 | 280 | *** 281 | 282 | ### postLogoutRedirectUri? 283 | 284 | > `optional` **postLogoutRedirectUri**: `string` 285 | 286 | The post-logout redirect URI of your client application which your OIDC/OAuth2 provider can redirect to after completing logout. 287 | 288 | #### Defined in 289 | 290 | [src/auth-context-interface.ts:69](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L69) 291 | 292 | *** 293 | 294 | ### redirectUri? 295 | 296 | > `optional` **redirectUri**: `string` 297 | 298 | The redirect URI of your client application to receive a response from the OIDC/OAuth2 provider. 299 | 300 | #### Defined in 301 | 302 | [src/auth-context-interface.ts:61](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L61) 303 | 304 | *** 305 | 306 | ### responseType? 307 | 308 | > `optional` **responseType**: `string` 309 | 310 | Tells the authorization server which grant to execute. 311 | 312 | Read more: https://tools.ietf.org/html/rfc6749#section-3.1.1 313 | 314 | #### Defined in 315 | 316 | [src/auth-context-interface.ts:75](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L75) 317 | 318 | *** 319 | 320 | ### scope? 321 | 322 | > `optional` **scope**: `string` 323 | 324 | A space-delimited list of permissions that the application requires. 325 | 326 | #### Defined in 327 | 328 | [src/auth-context-interface.ts:79](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L79) 329 | 330 | *** 331 | 332 | ### silentRedirectUri? 333 | 334 | > `optional` **silentRedirectUri**: `string` 335 | 336 | The redirect URI of your client application to receive a response from the OIDC/OAuth2 provider when completing a background sign-in refresh. 337 | 338 | #### Defined in 339 | 340 | [src/auth-context-interface.ts:65](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L65) 341 | 342 | *** 343 | 344 | ### userManager? 345 | 346 | > `optional` **userManager**: `UserManager` 347 | 348 | See [UserManager](https://github.com/authts/oidc-client-ts) for more details. 349 | 350 | #### Defined in 351 | 352 | [src/auth-context-interface.ts:37](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L37) 353 | -------------------------------------------------------------------------------- /docs/interfaces/AuthProviderSignOutProps.md: -------------------------------------------------------------------------------- 1 | [**oidc-react**](../README.md) • **Docs** 2 | 3 | *** 4 | 5 | [oidc-react](../README.md) / AuthProviderSignOutProps 6 | 7 | # Interface: AuthProviderSignOutProps 8 | 9 | ## Properties 10 | 11 | ### signoutRedirect? 12 | 13 | > `optional` **signoutRedirect**: `unknown` 14 | 15 | Trigger a redirect of the current window to the end session endpoint 16 | 17 | You can also provide an object. This object will be sent with the 18 | function. 19 | 20 | #### Example 21 | 22 | ```javascript 23 | const config = { 24 | signOutRedirect: { 25 | state: 'abrakadabra', 26 | }, 27 | }; 28 | ``` 29 | 30 | #### Defined in 31 | 32 | [src/auth-context-interface.ts:30](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L30) 33 | -------------------------------------------------------------------------------- /docs/interfaces/Location.md: -------------------------------------------------------------------------------- 1 | [**oidc-react**](../README.md) • **Docs** 2 | 3 | *** 4 | 5 | [oidc-react](../README.md) / Location 6 | 7 | # Interface: Location 8 | 9 | ## Properties 10 | 11 | ### hash 12 | 13 | > **hash**: `string` 14 | 15 | #### Defined in 16 | 17 | [src/auth-context-interface.ts:11](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L11) 18 | 19 | *** 20 | 21 | ### search 22 | 23 | > **search**: `string` 24 | 25 | #### Defined in 26 | 27 | [src/auth-context-interface.ts:10](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context-interface.ts#L10) 28 | -------------------------------------------------------------------------------- /docs/variables/AuthContext.md: -------------------------------------------------------------------------------- 1 | [**oidc-react**](../README.md) • **Docs** 2 | 3 | *** 4 | 5 | [oidc-react](../README.md) / AuthContext 6 | 7 | # Variable: AuthContext 8 | 9 | > `const` **AuthContext**: `Context`\<`undefined` \| [`AuthContextProps`](../interfaces/AuthContextProps.md)\> 10 | 11 | ## Defined in 12 | 13 | [src/auth-context.tsx:24](https://github.com/bjerkio/oidc-react/blob/main/src/auth-context.tsx#L24) 14 | -------------------------------------------------------------------------------- /guides/HOOKS.md: -------------------------------------------------------------------------------- 1 | # Hooks 2 | 3 | OIDC React comes with hooks! Hooks are a great way, much better then using our 4 | [Consumer](https://reactjs.org/docs/context.html#contextconsumer). 5 | 6 | ## `useAuth` 7 | 8 | useAuth returns the same as our 9 | [authContext](../docs/interfaces/authcontextprops.md). Let's look at an example 10 | of use. 11 | 12 | ```tsx 13 | import { useAuth } from 'oidc-react'; 14 | 15 | export default () => { 16 | const auth = useAuth(); 17 | 18 | return

Hello {auth.profile.name}!

; 19 | }; 20 | ``` 21 | 22 | The example above uses `id_token` object (`profile`) and displays the name of 23 | the user. 24 | 25 | It should be as easy as that! 26 | -------------------------------------------------------------------------------- /guides/QUICKSTART.md: -------------------------------------------------------------------------------- 1 | # Quickstart 2 | 3 | First step is to install the package. 4 | 5 | ```shell 6 | $ npm install oidc-react 7 | ``` 8 | 9 | ## Setting up `AuthProvider` 10 | 11 | AuthProvider is a [Context](https://reactjs.org/docs/context.html) and holds 12 | most of the functionality of this package. In order to make it work with your 13 | very own OIDC server, you'll have to either setup your own 14 | [`UserManager`](https://authts.github.io/oidc-client-ts/classes/UserManager.html) 15 | or use the shortcut. In this guide, we'll use our shortcuts. 16 | 17 | Let's look at an example component. 18 | 19 | ```tsx 20 | import { AuthProvider } from 'oidc-react'; 21 | 22 | export default () => ( 23 | 28 | 29 | Hello world 30 | 31 | 32 | ); 33 | ``` 34 | 35 | _You can find the 36 | [properties under the API documentation](../docs/interfaces/authproviderprops.md)._ 37 | 38 | In the example above we've setup that we'll connect with a OIDC service located 39 | at `http://oidc.io/oauth` with the client id `my-client-id`. **By default, our 40 | client automatically redirects us to login**. This means that when wrapping 41 | anything with `AuthProvider` we'll be redirected once the app loads. After the 42 | user has successfully authenticated, our user will be redirected to 43 | `http://myapp.com`. 44 | 45 | However, if we want the user to be sent to our dashboard when authenticated, we 46 | can add in a hook. 47 | 48 | Let's look at another example for that! 49 | 50 | ```tsx 51 | import { AuthProvider } from 'oidc-react'; 52 | 53 | export default App = () => ( 54 | { 59 | // the `user` prop is actually the data the app received from `/userinfo` endpoint. 60 | history.go('/dashboard', user); 61 | }} 62 | > 63 | 64 | Hello world 65 | 66 | 67 | ); 68 | ``` 69 | 70 | In this example our user is now redirected once again, this time to `/dashboard` 71 | of our app. 72 | -------------------------------------------------------------------------------- /guides/WITHAUTH.md: -------------------------------------------------------------------------------- 1 | # Hooks 2 | 3 | OIDC React comes with a HOC withAuth! withAuth is a great way, much better then 4 | using our [Consumer](https://reactjs.org/docs/context.html#contextconsumer). 5 | 6 | ## `withAuth` 7 | 8 | withAuth returns a component wrapped in 9 | [authContext](../docs/interfaces/authcontextprops.md). Let's look at an example 10 | of use. 11 | 12 | ```tsx 13 | import { withAuth } from 'oidc-react'; 14 | 15 | class Hello extends React.PureComponent<{}, {}> { 16 | render() { 17 | return

Hello {this.props.authData.profile.name}!

; 18 | } 19 | } 20 | 21 | export default withAuth(Hello); 22 | ``` 23 | 24 | The example above uses `id_token` object (`profile`) and displays the name of 25 | the user. 26 | 27 | It should be as easy as that! 28 | -------------------------------------------------------------------------------- /guides/migrate-v1-v2.md: -------------------------------------------------------------------------------- 1 | # Migrate from v1 to v2 2 | 3 | Back in june 2021 `oidc-client-js` was deprecated, which lead us to start 4 | looking for a suitable replacement. Keeping tabs on what could suit our needs 5 | and the maintainability of the library had us wait until now. 6 | 7 | The largest change is migrating from `oidc-client-js` to `oidc-client-ts`. For 8 | consumers of this package, this means mostly that if you are importing 9 | `oidc-client` somewhere in your code. You have to replace it with 10 | `oidc-client-ts`. 11 | 12 | You can find more documentation on `oidc-client-ts` here: 13 | https://github.com/authts/oidc-client-ts 14 | 15 | They have written a migration guide, you can find that here: 16 | https://github.com/authts/oidc-client-ts/blob/main/docs/migration.md 17 | 18 | Other than that, we have also started supporting React 18. 🚀 19 | 20 | We haven't tested this extensively, so be sure to share your input and 21 | experiences with us! 22 | 23 | Thank you for using `oidc-react`. 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "oidc-react", 3 | "version": "3.4.1", 4 | "private": false, 5 | "description": "OpenID Connect Authentication for React. Supports Hooks 🚀", 6 | "repository": "github:bjerkio/oidc-react", 7 | "license": "MIT", 8 | "author": "Bjerk AS", 9 | "main": "build/src/index.js", 10 | "packageManager": "pnpm@8.15.9", 11 | "files": [ 12 | "/build" 13 | ], 14 | "prettier": "@simenandre/prettier", 15 | "scripts": { 16 | "start": "node build/index.js", 17 | "build": "tsc -p tsconfig.release.json", 18 | "test": "vitest", 19 | "format": "prettier --write .", 20 | "format:check": "prettier --check .", 21 | "lint": "eslint .", 22 | "generate-docs": "typedoc" 23 | }, 24 | "dependencies": { 25 | "oidc-client-ts": "^2.4.0" 26 | }, 27 | "devDependencies": { 28 | "@bjerk/eslint-config": "^6.0.2", 29 | "@simenandre/prettier": "^5.0.0", 30 | "@testing-library/react": "^16.0.0", 31 | "@types/node": "^20.0.0", 32 | "@types/react": "^18.2.12", 33 | "eslint": "^9.0.0", 34 | "jsdom": "^22.1.0", 35 | "prettier": "^3.0.3", 36 | "react": "^18.2.0", 37 | "react-dom": "^18.2.0", 38 | "ts-node-dev": "^2.0.0", 39 | "typedoc": "^0.26.10", 40 | "typedoc-plugin-markdown": "^4.2.9", 41 | "typescript": "^5.2.2", 42 | "vitest": "^2.0.0" 43 | }, 44 | "peerDependencies": { 45 | "react": "^16.8.0 || ^17.0.0 || ^18.0.0", 46 | "react-dom": "^16.8.0 || || ^17.0.0 || ^18.0.0" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/__tests__/auth-context.test.tsx: -------------------------------------------------------------------------------- 1 | // @vitest-environment jsdom 2 | import React from 'react'; 3 | import { SilentRenewErrorCallback, UserManager } from 'oidc-client-ts'; 4 | import { AuthProvider, AuthContext } from '../auth-context'; 5 | import { render, act, waitFor, RenderResult } from '@testing-library/react'; 6 | import { describe, it, expect, vi } from 'vitest'; 7 | 8 | const events = { 9 | addUserLoaded: () => undefined, 10 | removeUserLoaded: () => undefined, 11 | addSilentRenewError: () => undefined, 12 | removeSilentRenewError: () => undefined, 13 | }; 14 | 15 | vi.mock('oidc-client-ts', () => { 16 | return { 17 | UserManager: vi.fn().mockImplementation(() => { 18 | return { 19 | getUser: vi.fn(), 20 | signinRedirect: vi.fn(), 21 | events, 22 | }; 23 | }), 24 | }; 25 | }); 26 | 27 | describe('AuthContext', () => { 28 | it('should check for user and redirect', async () => { 29 | const u = { 30 | getUser: vi.fn(), 31 | signinRedirect: vi.fn(), 32 | events, 33 | } as any; 34 | const onBeforeSignIn = vi.fn(); 35 | await act(async () => { 36 | render(); 37 | }); 38 | expect(u.getUser).toHaveBeenCalled(); 39 | expect(onBeforeSignIn).toHaveBeenCalled(); 40 | expect(u.signinRedirect).toHaveBeenCalled(); 41 | }); 42 | 43 | it('should redirect when asked', async () => { 44 | const u = { 45 | getUser: vi.fn(), 46 | signinRedirect: vi.fn(), 47 | events, 48 | } as any; 49 | await act(async () => { 50 | render( 51 | 52 | 53 | {value => { 54 | value?.signIn(); 55 | return

Bjerk

; 56 | }} 57 |
58 |
, 59 | ); 60 | }); 61 | expect(u.getUser).toHaveBeenCalled(); 62 | expect(u.signinRedirect).toHaveBeenCalled(); 63 | }); 64 | 65 | it('should open Popup when asked', async () => { 66 | const u = { 67 | getUser: vi.fn(), 68 | signinPopupCallback: vi.fn(), 69 | signinPopup: vi.fn(), 70 | events, 71 | } as any; 72 | await act(async () => { 73 | render( 74 | 75 | 76 | {value => { 77 | value?.signInPopup(); 78 | return

Bjerk

; 79 | }} 80 |
81 |
, 82 | ); 83 | }); 84 | expect(u.signinPopupCallback).toHaveBeenCalled(); 85 | expect(u.signinPopup).toHaveBeenCalled(); 86 | }); 87 | 88 | it('should not redirect when asked', async () => { 89 | const u = { 90 | getUser: vi.fn(), 91 | events, 92 | } as any; 93 | await act(async () => { 94 | render(); 95 | }); 96 | expect(u.getUser).toHaveBeenCalled(); 97 | }); 98 | 99 | it('should generate a UserManager', async () => { 100 | await act(async () => { 101 | render( 102 | , 107 | ); 108 | }); 109 | expect(UserManager).toHaveBeenCalled(); 110 | }); 111 | 112 | it('should use post-logout redirect URI when given', async () => { 113 | await act(async () => { 114 | render( 115 | , 121 | ); 122 | }); 123 | expect(UserManager).toHaveBeenLastCalledWith( 124 | expect.objectContaining({ 125 | post_logout_redirect_uri: 'https://localhost', 126 | }), 127 | ); 128 | }); 129 | 130 | it('should fall back to redirectUri when post-logout redirect URI is not given', async () => { 131 | await act(async () => { 132 | render( 133 | , 138 | ); 139 | }); 140 | expect(UserManager).toHaveBeenLastCalledWith( 141 | expect.objectContaining({ post_logout_redirect_uri: 'http://127.0.0.1' }), 142 | ); 143 | }); 144 | 145 | it('should use silent redirect URI when given', async () => { 146 | await act(async () => { 147 | render( 148 | , 154 | ); 155 | }); 156 | expect(UserManager).toHaveBeenLastCalledWith( 157 | expect.objectContaining({ silent_redirect_uri: 'https://localhost' }), 158 | ); 159 | }); 160 | 161 | it('should fall back to redirectUri when silent redirect URI is not given', async () => { 162 | await act(async () => { 163 | render( 164 | , 169 | ); 170 | }); 171 | expect(UserManager).toHaveBeenLastCalledWith( 172 | expect.objectContaining({ silent_redirect_uri: 'http://127.0.0.1' }), 173 | ); 174 | }); 175 | 176 | it('should get userData', async () => { 177 | const userManager = { 178 | getUser: async () => ({ 179 | access_token: 'token', 180 | }), 181 | signinCallback: vi.fn(), 182 | events, 183 | } as any; 184 | let result: any; 185 | await act(async () => { 186 | result = render( 187 | 188 | 189 | {value => 190 | value?.userData && ( 191 | Received: {value.userData.access_token} 192 | ) 193 | } 194 | 195 | , 196 | ); 197 | }); 198 | expect(result.getByText(/^Received:/).textContent).toBe('Received: token'); 199 | }); 200 | 201 | it('should refresh userData when new data is available', async () => { 202 | const userManager = { 203 | getUser: async () => ({ 204 | access_token: 'token', 205 | }), 206 | signinCallback: vi.fn(), 207 | signoutRedirect: vi.fn(), 208 | events, 209 | } as any; 210 | const { getByText } = render( 211 | 212 | 213 | {value => 214 | value?.userData && ( 215 | Received: {value.userData.access_token} 216 | ) 217 | } 218 | 219 | , 220 | ); 221 | await waitFor(() => { 222 | expect(getByText(/^Received:/).textContent).toBe('Received: token'); 223 | }); 224 | }); 225 | 226 | it('should login the user with query params', async () => { 227 | const userManager = { 228 | getUser: vi.fn(), 229 | signinCallback: vi.fn(() => true), 230 | events, 231 | } as any; 232 | 233 | const location = { 234 | search: '?code=login-test-code', 235 | hash: '', 236 | }; 237 | 238 | const onSignIn = vi.fn(); 239 | render( 240 | , 245 | ); 246 | await waitFor(() => expect(onSignIn).toHaveBeenCalled()); 247 | await waitFor(() => expect(userManager.signinCallback).toHaveBeenCalled()); 248 | }); 249 | 250 | it('should login the user with hash params', async () => { 251 | const userManager = { 252 | getUser: vi.fn(), 253 | signinCallback: vi.fn(() => true), 254 | events, 255 | } as any; 256 | 257 | const location = { 258 | search: '', 259 | hash: '#code=login-test-code', 260 | }; 261 | 262 | const onSignIn = vi.fn(); 263 | render( 264 | , 269 | ); 270 | await waitFor(() => expect(onSignIn).toHaveBeenCalled()); 271 | await waitFor(() => expect(userManager.signinCallback).toHaveBeenCalled()); 272 | }); 273 | 274 | it('should logout the user', async () => { 275 | const userManager = { 276 | getUser: async () => ({ 277 | access_token: 'token', 278 | }), 279 | removeUser: vi.fn(), 280 | events, 281 | } as any; 282 | const onSignOut = vi.fn(); 283 | render( 284 | 289 | 290 | {value => { 291 | value?.signOut(); 292 | return

Bjerk

; 293 | }} 294 |
295 |
, 296 | ); 297 | await waitFor(() => expect(onSignOut).toHaveBeenCalled()); 298 | await waitFor(() => expect(userManager.removeUser).toHaveBeenCalled()); 299 | }); 300 | 301 | it('should end session and logout the user when signoutRedirect is true', async () => { 302 | const userManager = { 303 | getUser: async () => ({ 304 | access_token: 'token', 305 | }), 306 | signoutRedirect: vi.fn(), 307 | events, 308 | } as any; 309 | const onSignOut = vi.fn(); 310 | render( 311 | 316 | 317 | {value => { 318 | value?.signOutRedirect(); 319 | return

Bjerk

; 320 | }} 321 |
322 |
, 323 | ); 324 | await waitFor(() => expect(onSignOut).toHaveBeenCalled()); 325 | await waitFor(() => expect(userManager.signoutRedirect).toHaveBeenCalled()); 326 | }); 327 | 328 | it('should end session and logout the user when signoutRedirect is an object', async () => { 329 | const userManager = { 330 | getUser: async () => ({ 331 | access_token: 'token', 332 | }), 333 | signoutRedirect: vi.fn(), 334 | events, 335 | } as any; 336 | const onSignOut = vi.fn(); 337 | render( 338 | 339 | 340 | {value => { 341 | value?.signOutRedirect({ 342 | state: 'thebranches', 343 | }); 344 | return

Bjerk

; 345 | }} 346 |
347 |
, 348 | ); 349 | await waitFor(() => expect(onSignOut).toHaveBeenCalled()); 350 | await waitFor(() => 351 | expect(userManager.signoutRedirect).toHaveBeenCalledWith({ 352 | state: 'thebranches', 353 | }), 354 | ); 355 | }); 356 | 357 | it('should sign out redirect on silent renew failure', async () => { 358 | // given: a signed in UserManager that stashes silentRenewError callbacks 359 | const callbacks: SilentRenewErrorCallback[] = []; 360 | const u = { 361 | getUser: async () => ({ 362 | access_token: 'token', 363 | }), 364 | signinCallback: vi.fn(), 365 | signoutRedirect: vi.fn(), 366 | events: { 367 | ...events, 368 | addSilentRenewError: vi.fn(callback => callbacks.push(callback)), 369 | removeSilentRenewError: vi.fn(callback => 370 | callbacks.splice(callbacks.indexOf(callback), 1), 371 | ), 372 | }, 373 | } as any; 374 | 375 | // when: the AuthProvider is mounted 376 | let result: RenderResult; 377 | await act(async () => { 378 | result = render(); 379 | }); 380 | 381 | // then: the silentRenewError callback should be registered 382 | expect(u.events.addSilentRenewError).toHaveBeenCalledTimes(1); 383 | expect(callbacks).toHaveLength(1); 384 | 385 | // when: the registered silentRenewError callback is called 386 | await act(async () => callbacks[0](new Error('test'))); 387 | 388 | // then: the callback should trigger a signout redirect 389 | expect(u.signoutRedirect).toHaveBeenCalledTimes(1); 390 | 391 | // when: the AuthProvider is unmounted 392 | act(() => { 393 | result.unmount(); 394 | }); 395 | 396 | // then: the callback should be unregistered 397 | expect(u.events.removeSilentRenewError).toHaveBeenCalledTimes(1); 398 | expect(callbacks).toHaveLength(0); 399 | }); 400 | }); 401 | -------------------------------------------------------------------------------- /src/auth-context-interface.ts: -------------------------------------------------------------------------------- 1 | import { 2 | UserManager, 3 | User, 4 | PopupWindowFeatures, 5 | SigninRedirectArgs, 6 | SignoutRedirectArgs, 7 | OidcMetadata, 8 | } from 'oidc-client-ts'; 9 | export interface Location { 10 | search: string; 11 | hash: string; 12 | } 13 | 14 | export interface AuthProviderSignOutProps { 15 | /** 16 | * Trigger a redirect of the current window to the end session endpoint 17 | * 18 | * You can also provide an object. This object will be sent with the 19 | * function. 20 | * 21 | * @example 22 | * ```javascript 23 | * const config = { 24 | * signOutRedirect: { 25 | * state: 'abrakadabra', 26 | * }, 27 | * }; 28 | * ``` 29 | */ 30 | signoutRedirect?: unknown; 31 | } 32 | 33 | export interface AuthProviderProps { 34 | /** 35 | * See [UserManager](https://github.com/authts/oidc-client-ts) for more details. 36 | */ 37 | userManager?: UserManager; 38 | /** 39 | * The URL of the OIDC/OAuth2 provider. 40 | */ 41 | authority?: string; 42 | /** 43 | * Manually set metadata if CORS is not configured on the OIDC/OAuth2 provider. 44 | */ 45 | metadata?: Partial; 46 | /** 47 | * Extra query params passed to the authorization url. 48 | */ 49 | extraQueryParams?: Record; 50 | /** 51 | * Your client application's identifier as registered with the OIDC/OAuth2 provider. 52 | */ 53 | clientId?: string; 54 | /** 55 | * Client secret defined on the identity server. 56 | */ 57 | clientSecret?: string; 58 | /** 59 | * The redirect URI of your client application to receive a response from the OIDC/OAuth2 provider. 60 | */ 61 | redirectUri?: string; 62 | /** 63 | * The redirect URI of your client application to receive a response from the OIDC/OAuth2 provider when completing a background sign-in refresh. 64 | */ 65 | silentRedirectUri?: string; 66 | /** 67 | * The post-logout redirect URI of your client application which your OIDC/OAuth2 provider can redirect to after completing logout. 68 | */ 69 | postLogoutRedirectUri?: string; 70 | /** 71 | * Tells the authorization server which grant to execute. 72 | * 73 | * Read more: https://tools.ietf.org/html/rfc6749#section-3.1.1 74 | */ 75 | responseType?: string; 76 | /** 77 | * A space-delimited list of permissions that the application requires. 78 | */ 79 | scope?: string; 80 | /** 81 | * Defaults to `windows.location`. 82 | */ 83 | location?: Location; 84 | /** 85 | * Flag to control automatic redirection to the OIDC/OAuth2 provider when not signed in. 86 | * 87 | * Defaults to true. 88 | */ 89 | autoSignIn?: boolean; 90 | /** 91 | * Optional sign in arguments to be used when `autoSignIn` is enabled. 92 | */ 93 | autoSignInArgs?: SigninRedirectArgs; 94 | /** 95 | * Flag to control automatic sign out redirection to the OIDC/OAuth2 provider when silent renewal fails. 96 | * 97 | * Defaults to true. 98 | */ 99 | autoSignOut?: boolean; 100 | /** 101 | * Optional sign out arguments to be used when `autoSignOut` is enabled. 102 | */ 103 | autoSignOutArgs?: SignoutRedirectArgs; 104 | /** 105 | * Flag to indicate if there should be an automatic attempt to renew the access token prior to its expiration. 106 | * 107 | * Defaults to true. 108 | */ 109 | automaticSilentRenew?: boolean; 110 | /** 111 | * Flag to control if additional identity data is loaded from the user info endpoint in order to populate the user's profile. 112 | * 113 | * Defaults to true. 114 | */ 115 | loadUserInfo?: boolean; 116 | /** 117 | * The features parameter to window.open for the popup signin window 118 | * 119 | * defaults to 'location=no,toolbar=no,width=500,height=500,left=100,top=100' 120 | */ 121 | popupWindowFeatures?: PopupWindowFeatures; 122 | /** 123 | * The URL for the page containing the call to signinPopupCallback to handle the callback from the OIDC/OAuth2 124 | * 125 | */ 126 | popupRedirectUri?: string; 127 | /** 128 | * The target parameter to window.open for the popup signin window. * 129 | * defaults to '_blank' 130 | */ 131 | popupWindowTarget?: string; 132 | /** 133 | * On before sign in hook. Can be use to store the current url for use after signing in. 134 | * 135 | * This only gets called if autoSignIn is true */ 136 | onBeforeSignIn?: () => unknown; 137 | /** 138 | * On sign in hook. Can be a async function. 139 | * @param userData User 140 | */ 141 | onSignIn?: (userData: User | null) => Promise | void; 142 | /** 143 | * On sign out hook. Can be a async function. 144 | */ 145 | onSignOut?: (options?: AuthProviderSignOutProps) => Promise | void; 146 | 147 | /** 148 | * On sign in error. Can be a async function. 149 | */ 150 | onSignInError?: (error: Error) => void; 151 | } 152 | 153 | export interface AuthContextProps { 154 | /** 155 | * Alias for userManager.signInRedirect 156 | */ 157 | signIn: (args?: SigninRedirectArgs) => Promise; 158 | /** 159 | * Alias for userManager.signinPopup 160 | */ 161 | signInPopup: () => Promise; 162 | /** 163 | * Alias for removeUser 164 | */ 165 | signOut: () => Promise; 166 | /** 167 | * 168 | */ 169 | signOutRedirect: (args?: SignoutRedirectArgs) => Promise; 170 | /** 171 | * See [UserManager](https://authts.github.io/oidc-client-ts/classes/UserManager.html) for more details. 172 | */ 173 | userManager: UserManager; 174 | /** 175 | * See [User](https://authts.github.io/oidc-client-ts/classes/User.html) for more details. 176 | */ 177 | userData?: User | null; 178 | /** 179 | * Auth state: True until the library has been initialized. 180 | */ 181 | isLoading: boolean; 182 | } 183 | -------------------------------------------------------------------------------- /src/auth-context.tsx: -------------------------------------------------------------------------------- 1 | import React, { 2 | FC, 3 | useState, 4 | useEffect, 5 | useRef, 6 | PropsWithChildren, 7 | useMemo, 8 | useCallback, 9 | } from 'react'; 10 | import { 11 | UserManager, 12 | User, 13 | SigninRedirectArgs, 14 | SignoutRedirectArgs, 15 | UserLoadedCallback, 16 | SilentRenewErrorCallback, 17 | } from 'oidc-client-ts'; 18 | import { 19 | Location, 20 | AuthProviderProps, 21 | AuthContextProps, 22 | } from './auth-context-interface'; 23 | 24 | export const AuthContext = React.createContext( 25 | undefined, 26 | ); 27 | 28 | /** 29 | * @private 30 | * @hidden 31 | * @param location 32 | */ 33 | export const hasCodeInUrl = (location: Location): boolean => { 34 | const searchParams = new URLSearchParams(location.search); 35 | const hashParams = new URLSearchParams(location.hash.replace('#', '?')); 36 | 37 | return ( 38 | searchParams.has('code') || 39 | searchParams.has('id_token') || 40 | searchParams.has('session_state') || 41 | hashParams.has('code') || 42 | hashParams.has('id_token') || 43 | hashParams.has('session_state') 44 | ); 45 | }; 46 | /** 47 | * @private 48 | * @hidden 49 | * @param props 50 | */ 51 | export const initUserManager = (props: AuthProviderProps): UserManager => { 52 | if (props.userManager) { 53 | return props.userManager; 54 | } 55 | 56 | const { 57 | authority, 58 | clientId, 59 | clientSecret, 60 | redirectUri, 61 | silentRedirectUri, 62 | postLogoutRedirectUri, 63 | responseType, 64 | scope, 65 | automaticSilentRenew, 66 | loadUserInfo, 67 | popupWindowFeatures, 68 | popupRedirectUri, 69 | popupWindowTarget, 70 | extraQueryParams, 71 | metadata, 72 | } = props; 73 | return new UserManager({ 74 | authority: authority ?? '', 75 | client_id: clientId ?? '', 76 | client_secret: clientSecret, 77 | redirect_uri: redirectUri ?? '', 78 | silent_redirect_uri: silentRedirectUri ?? redirectUri, 79 | post_logout_redirect_uri: postLogoutRedirectUri ?? redirectUri, 80 | response_type: responseType ?? 'code', 81 | scope: scope ?? 'openid', 82 | loadUserInfo: loadUserInfo ?? true, 83 | popupWindowFeatures: popupWindowFeatures, 84 | popup_redirect_uri: popupRedirectUri, 85 | popupWindowTarget: popupWindowTarget, 86 | automaticSilentRenew, 87 | extraQueryParams, 88 | metadata: metadata, 89 | }); 90 | }; 91 | 92 | /** 93 | * 94 | * @param props AuthProviderProps 95 | */ 96 | export const AuthProvider: FC> = ({ 97 | children, 98 | autoSignIn = true, 99 | autoSignInArgs, 100 | autoSignOut = true, 101 | autoSignOutArgs, 102 | onBeforeSignIn, 103 | onSignIn, 104 | onSignOut, 105 | location = window.location, 106 | onSignInError, 107 | ...props 108 | }) => { 109 | const [isLoading, setIsLoading] = useState(true); 110 | const [userData, setUserData] = useState(null); 111 | const [userManager] = useState(() => initUserManager(props)); 112 | const isMountedRef = useRef(false); 113 | 114 | const signOutHooks = useCallback(async (): Promise => { 115 | setUserData(null); 116 | if (onSignOut) { 117 | await onSignOut(); 118 | } 119 | }, [onSignOut]); 120 | const signInPopupHooks = useCallback(async (): Promise => { 121 | const userFromPopup = await userManager.signinPopup(); 122 | setUserData(userFromPopup); 123 | if (onSignIn) { 124 | await onSignIn(userFromPopup); 125 | } 126 | await userManager.signinPopupCallback(); 127 | }, [userManager, onSignIn]); 128 | 129 | /** 130 | * Handles user auth flow on initial render. 131 | */ 132 | useEffect(() => { 133 | let isMounted = true; 134 | isMountedRef.current = true; 135 | setIsLoading(true); 136 | void (async () => { 137 | if (!userManager) { 138 | return; 139 | } 140 | 141 | const user = await userManager.getUser(); 142 | 143 | // isMountedRef cannot be used here as its value is updated by next useEffect. 144 | // We intend to keep context of current useEffect. 145 | if (isMounted && (!user || user.expired)) { 146 | // If the user is returning back from the OIDC provider, get and set the user data. 147 | if (hasCodeInUrl(location)) { 148 | try { 149 | const user = await userManager.signinCallback(); 150 | if (user) { 151 | setUserData(user); 152 | if (onSignIn) { 153 | await onSignIn(user); 154 | } 155 | } 156 | } catch (error) { 157 | if (onSignInError) { 158 | onSignInError(error as Error); 159 | } else { 160 | throw error; 161 | } 162 | } 163 | } 164 | // If autoSignIn is enabled, redirect to the OIDC provider. 165 | else if (autoSignIn) { 166 | const state = onBeforeSignIn ? onBeforeSignIn() : undefined; 167 | await userManager.signinRedirect({ ...autoSignInArgs, state }); 168 | } 169 | } 170 | // Otherwise if the user is already signed in, set the user data. 171 | else if (isMountedRef.current) { 172 | setUserData(user); 173 | } 174 | setIsLoading(false); 175 | })(); 176 | return () => { 177 | isMounted = false; 178 | isMountedRef.current = false; 179 | }; 180 | }, [ 181 | location, 182 | userManager, 183 | autoSignIn, 184 | onBeforeSignIn, 185 | onSignIn, 186 | onSignInError, 187 | ]); 188 | 189 | /** 190 | * Registers UserManager event callbacks for handling changes to user state due to automaticSilentRenew, session expiry, etc. 191 | */ 192 | useEffect(() => { 193 | const updateUserData: UserLoadedCallback = (user: User): void => { 194 | if (isMountedRef.current) { 195 | setUserData(user); 196 | } 197 | }; 198 | const onSilentRenewError: SilentRenewErrorCallback = 199 | async (): Promise => { 200 | if (autoSignOut) { 201 | await signOutHooks(); 202 | await userManager.signoutRedirect(autoSignOutArgs); 203 | } 204 | }; 205 | userManager.events.addUserLoaded(updateUserData); 206 | userManager.events.addSilentRenewError(onSilentRenewError); 207 | return () => { 208 | userManager.events.removeUserLoaded(updateUserData); 209 | userManager.events.removeSilentRenewError(onSilentRenewError); 210 | }; 211 | }, [userManager]); 212 | 213 | const value = useMemo(() => { 214 | return { 215 | signIn: async (args?: SigninRedirectArgs): Promise => { 216 | await userManager.signinRedirect(args); 217 | }, 218 | signInPopup: async (): Promise => { 219 | await signInPopupHooks(); 220 | }, 221 | signOut: async (): Promise => { 222 | await userManager.removeUser(); 223 | await signOutHooks(); 224 | }, 225 | signOutRedirect: async (args?: SignoutRedirectArgs): Promise => { 226 | await userManager.signoutRedirect(args); 227 | await signOutHooks(); 228 | }, 229 | userManager, 230 | userData, 231 | isLoading, 232 | }; 233 | }, [userManager, isLoading, userData, signInPopupHooks, signOutHooks]); 234 | 235 | return {children}; 236 | }; 237 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './use-auth'; 2 | export * from './with-auth'; 3 | export * from './auth-context'; 4 | export * from './auth-context-interface'; 5 | 6 | export { User, UserManager, Log, WebStorageStateStore } from 'oidc-client-ts'; 7 | -------------------------------------------------------------------------------- /src/use-auth.ts: -------------------------------------------------------------------------------- 1 | /* eslint @typescript-eslint/explicit-function-return-type: 0 */ 2 | import { useContext } from 'react'; 3 | import { AuthContextProps } from './auth-context-interface'; 4 | import { AuthContext } from './auth-context'; 5 | 6 | export const useAuth = (): AuthContextProps => { 7 | const context = useContext(AuthContext); 8 | 9 | if (!context) { 10 | throw new Error( 11 | 'AuthProvider context is undefined, please verify you are calling useAuth() as child of a component.', 12 | ); 13 | } 14 | 15 | return context; 16 | }; 17 | -------------------------------------------------------------------------------- /src/with-auth.tsx: -------------------------------------------------------------------------------- 1 | import { AuthContextProps } from './auth-context-interface'; 2 | import { useAuth } from './use-auth'; 3 | import React from 'react'; 4 | 5 | /** 6 | * A public higher-order component to access the imperative API 7 | */ 8 | export function withAuth

( 9 | Component: React.ComponentType

, 10 | ): React.ComponentType> { 11 | const displayName = `withAuth(${Component.displayName ?? Component.name})`; 12 | const C: React.FC> = props => { 13 | const auth = useAuth(); 14 | 15 | return ; 16 | }; 17 | 18 | C.displayName = displayName; 19 | 20 | return C; 21 | } 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "build", 4 | "target": "ES5", 5 | "lib": ["es2015", "es2016", "dom", "dom.iterable"], 6 | "allowJs": false, 7 | "skipLibCheck": true, 8 | "esModuleInterop": true, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "declaration": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "module": "commonjs", 14 | "moduleResolution": "node", 15 | "resolveJsonModule": true, 16 | "jsx": "react", 17 | "rootDir": ".", 18 | "sourceMap": true, 19 | "inlineSources": true 20 | }, 21 | "include": [ 22 | "*.ts", 23 | "src/*.ts", 24 | "src/**/*.ts", 25 | "test/*.ts", 26 | "test/**/*.ts", 27 | "src/*.tsx", 28 | "src/**/*.tsx", 29 | "test/*.tsx", 30 | "test/**/*.tsx", 31 | "examples/*.ts", 32 | "examples/*.tsx", 33 | "examples/**/*.ts", 34 | "examples/**/*.tsx" 35 | ], 36 | "exclude": ["node_modules"] 37 | } 38 | -------------------------------------------------------------------------------- /tsconfig.release.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": ["src/**/*"], 4 | "exclude": ["**/__tests__/*", "**/__fixtures__/*"] 5 | } 6 | -------------------------------------------------------------------------------- /typedoc.json: -------------------------------------------------------------------------------- 1 | { 2 | "readme": "none", 3 | "plugin": "typedoc-plugin-markdown", 4 | "out": "docs/", 5 | "gitRevision": "main", 6 | "exclude": ["node_modules/**"], 7 | "entryPoints": ["src/index.ts"] 8 | } 9 | --------------------------------------------------------------------------------