Skip to content

Commit

Permalink
fix: #45 switch to oidc-client-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
pamapa committed Oct 1, 2021
1 parent 8098990 commit 97b266d
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 89 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
![Pipeline](https://github.com/pamapa/oidc-client-react/workflows/Release/badge.svg)


Lightweight auth library using the [oidc-client](https://github.com/IdentityModel/oidc-client-js) library for React single page applications (SPA).
Lightweight auth library using the [oidc-client-ts](https://github.com/pamapa/oidc-client-ts) library for React single page applications (SPA).
Support for [hooks](https://reactjs.org/docs/hooks-intro.html) and [higher-order components (HOC)](https://reactjs.org/docs/higher-order-components.html).


Expand All @@ -18,10 +18,10 @@ Support for [hooks](https://reactjs.org/docs/hooks-intro.html) and [higher-order


## Documentation
This library implements an auth context provider by making use of the `oidc-client` library. Its configuration is
This library implements an auth context provider by making use of the `oidc-client-ts` library. Its configuration is
tight coupled to that library.

- [oidc-client](https://github.com/IdentityModel/oidc-client-js/wiki)
- [oidc-client-ts](https://github.com/pamapa/oidc-client-ts)

The User and UserManager is hold in this context, which is accessible from the React application. Additionally it intercepts
the auth redirects by looking at the query/fragment parameters and acts accordingly. You still need to setup a redirect uri,
Expand Down Expand Up @@ -170,7 +170,7 @@ As **not** a child of `AuthProvider` (e.g. redux slice) when using local storage
containing an access token:
```jsx
// src/slice.js
import { User } from "oidc-client"
import { User } from "oidc-client-ts"

function getUser() {
const oidcStorage = localStorage.getItem(`oidc.user:<your authority>:<your client id>`)
Expand Down
95 changes: 44 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
},
"peerDependencies": {
"react": ">=16",
"oidc-client": "^1.11.5"
"oidc-client-ts": "^2.0.0-beta.1"
},
"dependencies": {
"oidc-client": "^1.11.5"
"oidc-client-ts": "^2.0.0-beta.1"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.5.0",
Expand Down
18 changes: 10 additions & 8 deletions src/AuthContext.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React from "react";
import { UserManagerSettings, User, SessionStatus } from "oidc-client";
import { UserManagerSettings, User, SessionStatus } from "oidc-client-ts";
import { SigninPopupArgs, SigninSilentArgs, SigninRedirectArgs } from "oidc-client-ts";
import { SignoutRedirectArgs, SignoutPopupArgs, QuerySessionStatusArgs } from "oidc-client-ts";

import { AuthState } from "./AuthState";

export interface AuthContextProps extends AuthState {
/**
* UserManager functions. See [UserManager](https://github.com/IdentityModel/oidc-client-js/wiki#usermanager) for more details.
* UserManager functions. See [UserManager](https://github.com/pamapa/oidc-client-ts) for more details.
*/
readonly settings: UserManagerSettings;
clearStaleState(): Promise<void>;
removeUser(): Promise<void>;
signinPopup(args?: any): Promise<User>;
signinSilent(args?: any): Promise<User>;
signinRedirect(args?: any): Promise<void>;
signoutRedirect(args?: any): Promise<void>;
signoutPopup(args?: any): Promise<void>;
querySessionStatus(args?: any): Promise<SessionStatus>;
signinPopup(args?: SigninPopupArgs): Promise<User>;
signinSilent(args?: SigninSilentArgs): Promise<User | null>;
signinRedirect(args?: SigninRedirectArgs): Promise<void>;
signoutRedirect(args?: SignoutRedirectArgs): Promise<void>;
signoutPopup(args?: SignoutPopupArgs): Promise<void>;
querySessionStatus(args?: QuerySessionStatusArgs): Promise<SessionStatus | null>;
revokeAccessToken(): Promise<void>;
startSilentRenew(): void;
stopSilentRenew(): void;
Expand Down
9 changes: 5 additions & 4 deletions src/AuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { UserManager, UserManagerSettings, User } from "oidc-client";
import { UserManager, UserManagerSettings, User } from "oidc-client-ts";
import { SignoutRedirectArgs, SignoutPopupArgs } from "oidc-client-ts";

import { AuthContext } from "./AuthContext";
import { initialAuthState } from "./AuthState";
Expand Down Expand Up @@ -106,7 +107,7 @@ export const AuthProvider = (props: AuthProviderProps): JSX.Element => {
const [state, dispatch] = React.useReducer(reducer, initialAuthState);
const userManagerContext = React.useMemo(
() => ({
settings: userManager?.settings ?? {},
settings: userManager?.settings ?? { ...userManagerProps },
...(Object.fromEntries(
userManagerContextKeys.map((key) => [
key,
Expand Down Expand Up @@ -173,14 +174,14 @@ export const AuthProvider = (props: AuthProviderProps): JSX.Element => {

const signoutRedirect = React.useMemo(
() => userManager
? (args?: any) => userManager.signoutRedirect(args).then(onSignoutRedirect)
? (args?: SignoutRedirectArgs) => userManager.signoutRedirect(args).then(onSignoutRedirect)
: unsupportedEnvironment("signoutRedirect"),
[userManager, onSignoutRedirect]
);

const signoutPopup = React.useMemo(
() => userManager
? (args?: any) => userManager.signoutPopup(args).then(onSignoutPopup)
? (args?: SignoutPopupArgs) => userManager.signoutPopup(args).then(onSignoutPopup)
: unsupportedEnvironment("signoutPopup"),
[userManager, onSignoutPopup]
);
Expand Down
2 changes: 1 addition & 1 deletion src/AuthState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { User } from "oidc-client";
import { User } from "oidc-client-ts";

/**
* The auth state which, when combined with the auth methods, make up the return object of the `useAuth` hook.
Expand Down
2 changes: 1 addition & 1 deletion src/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { User } from "oidc-client";
import { User } from "oidc-client-ts";

import { AuthState } from "./AuthState";

Expand Down
Loading

0 comments on commit 97b266d

Please sign in to comment.