react-oauth2-code-pkce
Advanced tools
Comparing version 1.18.0 to 1.18.1
@@ -40,2 +40,3 @@ "use strict"; | ||
login: () => null, | ||
logIn: () => null, | ||
logOut: () => null, | ||
@@ -73,3 +74,3 @@ error: null, | ||
} | ||
function login(state, additionalParameters) { | ||
function logIn(state, additionalParameters) { | ||
clearStorage(); | ||
@@ -80,3 +81,4 @@ setLoginInProgress(true); | ||
if (state && typeof state !== 'string') { | ||
console.warn(`Passed login state must be of type 'string'. Received '${state}'. Ignoring value...`); | ||
const jsonState = JSON.stringify(state); | ||
console.warn(`Passed login state must be of type 'string'. Received '${jsonState}'. Ignoring value. In a future version, an error will be thrown here.`); | ||
typeSafePassedState = undefined; | ||
@@ -124,3 +126,3 @@ } | ||
if (initial) { | ||
login(); | ||
logIn(); | ||
return; | ||
@@ -130,7 +132,8 @@ } | ||
if (!config.onRefreshTokenExpire) { | ||
login(); | ||
logIn(); | ||
return; | ||
} | ||
config.onRefreshTokenExpire({ | ||
login, | ||
login: logIn, | ||
logIn, | ||
}); | ||
@@ -164,9 +167,9 @@ } | ||
} | ||
// Unknown error. Set error, and login if first page load | ||
// Unknown error. Set error, and log in if first page load | ||
console.error(error); | ||
setError(error.message); | ||
if (initial) | ||
login(); | ||
logIn(); | ||
} | ||
// Unknown error. Set error, and login if first page load | ||
// Unknown error. Set error, and log in if first page load | ||
else if (error instanceof Error) { | ||
@@ -176,3 +179,3 @@ console.error(error); | ||
if (initial) | ||
login(); | ||
logIn(); | ||
} | ||
@@ -246,3 +249,3 @@ }) | ||
if (!token && config.autoLogin) | ||
return login(); | ||
return logIn(); | ||
// Page refresh after login has succeeded | ||
@@ -270,3 +273,4 @@ try { | ||
idTokenData, | ||
login, | ||
login: logIn, | ||
logIn, | ||
logOut, | ||
@@ -273,0 +277,0 @@ error, |
@@ -35,3 +35,5 @@ import { ReactNode } from 'react'; | ||
token: string; | ||
logIn: (state?: string, additionalParameters?: TPrimitiveRecord) => void; | ||
logOut: (state?: string, logoutHint?: string) => void; | ||
/** @deprecated Use `logIn` instead */ | ||
login: (state?: string, additionalParameters?: TPrimitiveRecord) => void; | ||
@@ -62,2 +64,3 @@ error: string | null; | ||
clearURL?: boolean; | ||
/** @deprecated Use `extraAuthParameters` instead. Will be removed in a future version. */ | ||
extraAuthParams?: TPrimitiveRecord; | ||
@@ -74,2 +77,4 @@ extraAuthParameters?: TPrimitiveRecord; | ||
export type TRefreshTokenExpiredEvent = { | ||
logIn: () => void; | ||
/** @deprecated Use `logIn` instead. Will be removed in a future version. */ | ||
login: () => void; | ||
@@ -92,2 +97,3 @@ }; | ||
clearURL: boolean; | ||
/** @deprecated Use `extraAuthParameters` instead. Will be removed in a future version. */ | ||
extraAuthParams?: TPrimitiveRecord; | ||
@@ -94,0 +100,0 @@ extraAuthParameters?: TPrimitiveRecord; |
{ | ||
"name": "react-oauth2-code-pkce", | ||
"version": "1.18.0", | ||
"version": "1.18.1", | ||
"description": "Provider agnostic react package for OAuth2 Authorization Code flow with PKCE", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -39,3 +39,3 @@ # react-oauth2-code-pkce | ||
scope: 'someScope openid', | ||
onRefreshTokenExpire: (event: TRefreshTokenExpiredEvent) => window.confirm('Session expired. Refresh page to continue using the site?') && event.login(), | ||
onRefreshTokenExpire: (event: TRefreshTokenExpiredEvent) => window.confirm('Session expired. Refresh page to continue using the site?') && event.logIn(), | ||
} | ||
@@ -85,3 +85,3 @@ | ||
// If you want to use 'state', you might want to set 'clearURL' configuration parameter to 'false'. | ||
login: (state?: string, additionalParameters?: { [key: string]: string | boolean | number }) => void | ||
logIn: (state?: string, additionalParameters?: { [key: string]: string | boolean | number }) => void | ||
// Function to trigger logout from authentication provider. You may provide optional 'state', and 'logout_hint' values. | ||
@@ -117,3 +117,3 @@ // See https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RPLogout for details. | ||
type TAuthConfig = { | ||
// Id of your app at the authentication provider | ||
// ID of your app at the authentication provider | ||
clientId: string // Required | ||
@@ -124,7 +124,7 @@ // URL for the authentication endpoint at the authentication provider | ||
tokenEndpoint: string // Required | ||
// Which URL the auth provider should redirect the user after successfull authentication/login | ||
// Which URL the auth provider should redirect the user to after successful authentication/login | ||
redirectUri: string // Required | ||
// Which scopes to request for the auth token | ||
scope?: string // default: '' | ||
// Optional state value. Will often make more sense to provide the state in a call to the 'login()' function | ||
// Optional state value. Will often make more sense to provide the state in a call to the 'logIn()' function | ||
state?: string // default: null | ||
@@ -142,3 +142,3 @@ // Which URL to call for logging out of the auth provider | ||
// Optional callback function for the 'refreshTokenExpired' event. | ||
// You likely want to display a message saying the user need to login again. A page refresh is enough. | ||
// You likely want to display a message saying the user need to log in again. A page refresh is enough. | ||
onRefreshTokenExpire?: (event: TRefreshTokenExpiredEvent) => void // default: undefined | ||
@@ -149,3 +149,3 @@ // Whether or not to decode the access token (should be set to 'false' if the access token is not a JWT (e.g. from Github)) | ||
// By default, the package will automatically redirect the user to the login server if not already logged in. | ||
// If set to false, you need to call the "login()" function to login (e.g. with a "Login" button) | ||
// If set to false, you need to call the "logIn()" function to log in (e.g. with a "Log in" button) | ||
autoLogin?: boolean // default: true | ||
@@ -155,3 +155,3 @@ // Store login state in 'localStorage' or 'sessionStorage' | ||
// NOTE: Many authentication servers will keep the client logged in by cookies. You should therefore use | ||
// the 'logout()'-function to properly logout the client. Or configure your server not to issue cookies. | ||
// the logOut() function to properly log out the client. Or configure your server not to issue cookies. | ||
storage?: 'local' | 'session' // default: 'local' | ||
@@ -203,3 +203,3 @@ // Sets the prefix used when storing login state | ||
Some known causes for this is that instead of logging in at the auth provider, the user "Registers" or "Reset password" or | ||
something similar instead. Any such functions should be handled outside of this library, with separate buttons/links than the Login-button. | ||
something similar instead. Any such functions should be handled outside of this library, with separate buttons/links than the "Log in" button. | ||
@@ -216,4 +216,4 @@ ### After redirect back from auth provider with `?code`, no token request is made | ||
This will happen if you haven't provided a callback-function for the `onRefreshTokenExpire` config parameter, and the refresh token expires. | ||
You probably want to implement some kind of "alert/message/banner", saying that the session has expired and that the user needs to login again. | ||
Either by refreshing the page, or clicking a "Login-button". | ||
You probably want to implement some kind of "alert/message/banner", saying that the session has expired and that the user needs to log in again. | ||
Either by refreshing the page, or clicking a "Log in" button. | ||
@@ -220,0 +220,0 @@ ## Develop |
50203
786