🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

react-oauth2-code-pkce

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-oauth2-code-pkce - npm Package Compare versions

Comparing version

to
1.23.0

@@ -18,9 +18,19 @@ "use strict";

});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -27,0 +37,0 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

@@ -1,3 +0,3 @@

import type { TInternalConfig, TPrimitiveRecord, TTokenResponse } from './types';
export declare function redirectToLogin(config: TInternalConfig, customState?: string, additionalParameters?: TPrimitiveRecord, method?: 'popup' | 'redirect'): Promise<void>;
import type { TInternalConfig, TLoginMethod, TPrimitiveRecord, TTokenResponse } from './types';
export declare function redirectToLogin(config: TInternalConfig, customState?: string, additionalParameters?: TPrimitiveRecord, method?: TLoginMethod): Promise<void>;
export declare const fetchTokens: (config: TInternalConfig) => Promise<TTokenResponse>;

@@ -4,0 +4,0 @@ export declare const fetchWithRefreshToken: (props: {

@@ -18,2 +18,3 @@ "use strict";

const pkceUtils_1 = require("./pkceUtils");
const popupUtils_1 = require("./popupUtils");
const codeVerifierStorageKey = 'PKCE_code_verifier';

@@ -24,2 +25,3 @@ const stateStorageKey = 'ROCP_auth_state';

const storage = config.storage === 'session' ? sessionStorage : localStorage;
const navigationMethod = method === 'replace' ? 'replace' : 'assign';
// Create and store a random string in storage, used as the 'code_verifier'

@@ -46,3 +48,4 @@ const codeVerifier = (0, pkceUtils_1.generateRandomString)(96);

if (method === 'popup') {
const handle = window.open(loginUrl, 'loginPopup', 'popup width=600 height=600');
const { width, height, left, top } = (0, popupUtils_1.calculatePopupPosition)(600, 600);
const handle = window.open(loginUrl, 'loginPopup', `width=${width},height=${height},top=${top},left=${left}`);
if (handle)

@@ -52,3 +55,3 @@ return;

}
window.location.assign(loginUrl);
window.location[navigationMethod](loginUrl);
});

@@ -55,0 +58,0 @@ });

import type { ReactNode } from 'react';
type WithRequired<T, K extends keyof T> = T & {
[P in K]-?: T[P];
};
interface TTokenRqBase {

@@ -29,2 +32,9 @@ grant_type: string;

};
export type TLoginMethod = 'redirect' | 'replace' | 'popup';
export type TPopupPosition = {
left: number;
top: number;
width: number;
height: number;
};
export interface IAuthProvider {

@@ -34,8 +44,9 @@ authConfig: TAuthConfig;

}
type TLogInFunction = (state?: string, additionalParameters?: TPrimitiveRecord, method?: TLoginMethod) => void;
export interface IAuthContext {
token: string;
logIn: (state?: string, additionalParameters?: TPrimitiveRecord, method?: 'redirect' | 'popup') => void;
logIn: TLogInFunction;
logOut: (state?: string, logoutHint?: string, additionalParameters?: TPrimitiveRecord) => void;
/** @deprecated Use `logIn` instead */
login: (state?: string, additionalParameters?: TPrimitiveRecord) => void;
login: TLogInFunction;
error: string | null;

@@ -61,3 +72,3 @@ tokenData?: TTokenData;

postLogin?: () => void;
loginMethod?: 'redirect' | 'popup';
loginMethod?: TLoginMethod;
onRefreshTokenExpire?: (event: TRefreshTokenExpiredEvent) => void;

@@ -81,35 +92,7 @@ decodeToken?: boolean;

export type TRefreshTokenExpiredEvent = {
logIn: (state?: string, additionalParameters?: TPrimitiveRecord, method?: 'redirect' | 'popup') => void;
logIn: TLogInFunction;
/** @deprecated Use `logIn` instead. Will be removed in a future version. */
login: (state?: string, additionalParameters?: TPrimitiveRecord, method?: 'redirect' | 'popup') => void;
login: TLogInFunction;
};
export type TInternalConfig = {
clientId: string;
authorizationEndpoint: string;
tokenEndpoint: string;
redirectUri: string;
scope?: string;
state?: string;
logoutEndpoint?: string;
logoutRedirect?: string;
preLogin?: () => void;
postLogin?: () => void;
loginMethod: 'redirect' | 'popup';
onRefreshTokenExpire?: (event: TRefreshTokenExpiredEvent) => void;
decodeToken: boolean;
autoLogin: boolean;
clearURL: boolean;
/** @deprecated Use `extraAuthParameters` instead. Will be removed in a future version. */
extraAuthParams?: TPrimitiveRecord;
extraAuthParameters?: TPrimitiveRecord;
extraTokenParameters?: TPrimitiveRecord;
extraLogoutParameters?: TPrimitiveRecord;
tokenExpiresIn?: number;
refreshTokenExpiresIn?: number;
refreshTokenExpiryStrategy: 'renewable' | 'absolute';
storage: 'session' | 'local';
storageKeyPrefix: string;
refreshWithScope: boolean;
tokenRequestCredentials: RequestCredentials;
};
export type TInternalConfig = WithRequired<TAuthConfig, 'loginMethod' | 'decodeToken' | 'autoLogin' | 'clearURL' | 'refreshTokenExpiryStrategy' | 'storage' | 'storageKeyPrefix' | 'refreshWithScope' | 'tokenRequestCredentials'>;
export {};
{
"name": "react-oauth2-code-pkce",
"version": "1.22.2",
"version": "1.23.0",
"description": "Provider agnostic react package for OAuth2 Authorization Code flow with PKCE",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -85,3 +85,3 @@ # react-oauth2-code-pkce

// Note that most browsers block popups by default. The library will print a warning and fallback to redirect if the popup is blocked
logIn: (state?: string, additionalParameters?: { [key: string]: string | boolean | number }, method: 'redirect' | 'popup' = 'redirect') => void
logIn: (state?: string, additionalParameters?: { [key: string]: string | boolean | number }, method: TLoginMethod = 'redirect') => void
// Function to trigger logout from authentication provider. You may provide optional 'state', and 'logout_hint' values.

@@ -139,5 +139,5 @@ // See https://openid.net/specs/openid-connect-rpinitiated-1_0.html#RPLogout for details.

postLogin?: () => void // default: () => null
// Which method to use for login. Can be either 'redirect' or 'popup'
// Which method to use for login. Can be 'redirect', 'replace', or 'popup'
// Note that most browsers block popups by default. The library will print a warning and fallback to redirect if the popup is blocked
loginMethod: 'redirect' | 'popup' // default: 'redirect'
loginMethod: 'redirect' | 'replace' | 'popup' // default: 'redirect'
// Optional callback function for the 'refreshTokenExpired' event.

@@ -183,3 +183,3 @@ // You likely want to display a message saying the user need to log in again. A page refresh is enough.

// not needed in any other case. Use with caution.
tokenRequestCredentials?: 'same-origin'|'include'|'omit' // default: 'same-origin'
tokenRequestCredentials?: 'same-origin' | 'include' | 'omit' // default: 'same-origin'
}

@@ -186,0 +186,0 @@