Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: replace oidc-client-js with oidc-client-ts #860

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file. See
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.6.0](https://github.com/bjerkio/oidc-react/compare/v1.5.1...v1.6.0) (2022-07-15)

### Features

* 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)


## [1.5.1](https://github.com/bjerkio/oidc-react/compare/v1.5.0...v1.5.1) (2021-04-11)


Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

React component (AuthProvider) to provide OpenID Connect and OAuth2 protocol support. Has [hooks](guides/HOOKS.md) 🎉

Based on [oidc-client-js](https://github.com/IdentityModel/oidc-client-js).
Based on [oidc-client-ts](https://github.com/authts/oidc-client-ts).

## Quickstart

Expand Down Expand Up @@ -60,7 +60,7 @@ Apart from this README, you can find details and examples of using the SDK in th
- [SDK Documentation](docs/README.md)
- [Guides](guides/)
- [Example repository](https://github.com/cobraz/example-react-oidc)
- [oidc-client-js Documentation](https://github.com/IdentityModel/oidc-client-js/wiki)
- [oidc-client-ts Documentation](https://authts.github.io/oidc-client-ts/)

## Contribute & Disclaimer

Expand Down
4 changes: 2 additions & 2 deletions docs/interfaces/authcontextinterface.authcontextprops.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ ___

`Optional` **userData**: *null* \| [*User*](../classes/index.user.md)

See [User](https://github.com/IdentityModel/oidc-client-js/wiki#user) for more details.
See [User](https://authts.github.io/oidc-client-ts/classes/User.html) for more details.

Defined in: [src/AuthContextInterface.ts:143](https://github.com/pamapa/oidc-react/blob/5ae1406/src/AuthContextInterface.ts#L143)

Expand All @@ -124,6 +124,6 @@ ___

**userManager**: *null* \| [*UserManager*](../classes/index.usermanager.md)

See [UserManager](https://github.com/IdentityModel/oidc-client-js/wiki#usermanager) for more details.
See [UserManager](https://authts.github.io/oidc-client-ts/classes/UserManager.html) for more details.

Defined in: [src/AuthContextInterface.ts:139](https://github.com/pamapa/oidc-react/blob/5ae1406/src/AuthContextInterface.ts#L139)
2 changes: 1 addition & 1 deletion docs/interfaces/authcontextinterface.authproviderprops.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,6 @@ ___

`Optional` **userManager**: [*UserManager*](../classes/index.usermanager.md)

See [UserManager](https://github.com/IdentityModel/oidc-client-js/wiki#usermanager) for more details.
See [UserManager](https://authts.github.io/oidc-client-ts/classes/UserManager.html) for more details.

Defined in: [src/AuthContextInterface.ts:30](https://github.com/pamapa/oidc-react/blob/5ae1406/src/AuthContextInterface.ts#L30)
2 changes: 1 addition & 1 deletion guides/QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $ npm install oidc-react

## Setting up `AuthProvider`

AuthProvider is a [Context](https://reactjs.org/docs/context.html) and holds most of the functionality of this package. In order to make it work with your very own OIDC server, you'll have to either setup your own [`UserManager`](https://github.com/IdentityModel/oidc-client-js/wiki#usermanager) or use the shortcut. In this guide, we'll use our shortcuts.
AuthProvider is a [Context](https://reactjs.org/docs/context.html) and holds most of the functionality of this package. In order to make it work with your very own OIDC server, you'll have to either setup your own [`UserManager`](https://authts.github.io/oidc-client-ts/classes/UserManager.html) or use the shortcut. In this guide, we'll use our shortcuts.

Let's look at an example component.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
]
},
"dependencies": {
"oidc-client": "^1.11.5"
"oidc-client-ts": "^2.0.5"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.4.0",
Expand Down
14 changes: 7 additions & 7 deletions src/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useState, useEffect, useRef, PropsWithChildren } from 'react';
import { UserManager, User } from 'oidc-client';
import { UserManager, User } from 'oidc-client-ts';
import {
Location,
AuthProviderProps,
Expand Down Expand Up @@ -50,10 +50,10 @@ export const initUserManager = (props: AuthProviderProps): UserManager => {
popupWindowTarget,
} = props;
return new UserManager({
authority,
client_id: clientId,
authority: authority || '',
client_id: clientId || '',
client_secret: clientSecret,
redirect_uri: redirectUri,
redirect_uri: redirectUri || '',
Comment on lines +53 to +56
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these being defaulted to an empty string? It's been a while since I worked with this code base, so I'm a bit rusty 😅

silent_redirect_uri: silentRedirectUri || redirectUri,
post_logout_redirect_uri: postLogoutRedirectUri || redirectUri,
response_type: responseType || 'code',
Expand Down Expand Up @@ -107,7 +107,7 @@ export const AuthProvider: FC<PropsWithChildren<AuthProviderProps>> = ({
* Check if the user is returning back from OIDC.
*/
if (hasCodeInUrl(location)) {
const user = await userManager.signinCallback();
const user: any = await userManager.signinCallback();
setUserData(user);
setIsLoading(false);
onSignIn && onSignIn(user);
Expand Down Expand Up @@ -142,7 +142,7 @@ export const AuthProvider: FC<PropsWithChildren<AuthProviderProps>> = ({
return (
<AuthContext.Provider
value={{
signIn: async (args: unknown): Promise<void> => {
signIn: async (args: any): Promise<void> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we want to use any here? If the args are not know, they should probably stay unknown. It would however be nicer to have some types here, is that something oidc-client-ts now provides?

await userManager.signinRedirect(args);
},
signInPopup: async (): Promise<void> => {
Expand All @@ -152,7 +152,7 @@ export const AuthProvider: FC<PropsWithChildren<AuthProviderProps>> = ({
await userManager!.removeUser();
await signOutHooks();
},
signOutRedirect: async (args?: unknown): Promise<void> => {
signOutRedirect: async (args?: any): Promise<void> => {
await userManager!.signoutRedirect(args);
await signOutHooks();
},
Expand Down
10 changes: 5 additions & 5 deletions src/AuthContextInterface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UserManager, User } from 'oidc-client';
import {UserManager, User, PopupWindowFeatures} from 'oidc-client-ts';
export interface Location {
search: string;
hash: string;
Expand All @@ -25,7 +25,7 @@ export interface AuthProviderSignOutProps {

export interface AuthProviderProps {
/**
* See [UserManager](https://github.com/IdentityModel/oidc-client-js/wiki#usermanager) for more details.
* See [UserManager](https://github.com/authts/oidc-client-ts) for more details.
*/
userManager?: UserManager;
/**
Expand Down Expand Up @@ -87,7 +87,7 @@ export interface AuthProviderProps {
*
* defaults to 'location=no,toolbar=no,width=500,height=500,left=100,top=100'
*/
popupWindowFeatures?: string;
popupWindowFeatures?: PopupWindowFeatures;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a union now?

/**
* The URL for the page containing the call to signinPopupCallback to handle the callback from the OIDC/OAuth2
*
Expand Down Expand Up @@ -134,11 +134,11 @@ export interface AuthContextProps {
*/
signOutRedirect: (args?: unknown) => Promise<void>;
/**
* See [UserManager](https://github.com/IdentityModel/oidc-client-js/wiki#usermanager) for more details.
* See [UserManager](https://authts.github.io/oidc-client-ts/classes/UserManager.html) for more details.
*/
userManager: UserManager;
/**
* See [User](https://github.com/IdentityModel/oidc-client-js/wiki#user) for more details.
* See [User](https://authts.github.io/oidc-client-ts/classes/User.html) for more details.
*/
userData?: User | null;
/**
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/AuthContext.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint @typescript-eslint/no-explicit-any: 0 */
/* eslint @typescript-eslint/explicit-function-return-type: 0 */
import React from 'react';
import { UserManager } from 'oidc-client';
import { UserManager } from 'oidc-client-ts';
import { AuthProvider, AuthContext } from '../AuthContext';
import { render, act, waitFor } from '@testing-library/react';

Expand All @@ -10,7 +10,7 @@ const events = {
removeUserLoaded: () => undefined,
}

jest.mock('oidc-client', () => {
jest.mock('oidc-client-ts', () => {
return {
UserManager: jest.fn().mockImplementation(() => {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export * from './withAuth';
export * from './AuthContext';
export * from './AuthContextInterface';

export { User, UserManager, Log } from 'oidc-client';
export { User, UserManager, Log } from 'oidc-client-ts';
Loading