Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-oauth2-code-pkce

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

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 1.8.3 to 1.8.4

dist/errors.d.ts

53

dist/AuthContext.js

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

const decodeJWT_1 = require("./decodeJWT");
const errors_1 = require("./errors");
const FALLBACK_EXPIRE_TIME = 600; // 10minutes

@@ -74,2 +75,3 @@ exports.AuthContext = (0, react_1.createContext)({

function login() {
clearStorage();
setLoginInProgress(true);

@@ -100,4 +102,16 @@ (0, authentication_1.redirectToLogin)(config);

}
function handleExpiredRefreshToken(initial = false) {
// If it's the first page load, OR there is no sessionExpire callback, we trigger a new login
if (initial)
return login();
// TODO: Breaking change - remove automatic login during ongoing session
else if (!onRefreshTokenExpire)
return login();
else
return onRefreshTokenExpire({ login });
}
function refreshAccessToken(initial = false) {
// We have a token, but it has expired
if (token && (0, timeUtils_1.epochTimeIsPast)(tokenExpire)) {
// We have a refreshToken, and it is not expired
if (refreshToken && !(0, timeUtils_1.epochTimeIsPast)(refreshTokenExpire)) {

@@ -107,21 +121,31 @@ (0, authentication_1.fetchWithRefreshToken)({ config, refreshToken })

.catch((error) => {
console.error(error);
setError(error.message);
if (initial)
login(); // If the attempt to get a new token failed during page load, do a full login.
if ((0, authentication_1.errorMessageForExpiredRefreshToken)(error.message)) {
if (onRefreshTokenExpire)
onRefreshTokenExpire({ login });
if (error instanceof errors_1.FetchError) {
// If the fetch failed with status 400, assume expired refresh token
if (error.status === 400) {
return handleExpiredRefreshToken(initial);
}
// Unknown error. Set error, and login if first page load
else {
console.error(error);
setError(error.message);
if (initial)
login();
}
}
// Unknown error. Set error, and login if first page load
else if (error instanceof Error) {
console.error(error);
setError(error.message);
if (initial)
login();
}
});
}
// The refreshToken has expired
else {
if (initial)
return login();
if (onRefreshTokenExpire)
onRefreshTokenExpire({ login });
else
login(); // TODO Breaking change - remove automatic login during ongoing session
return handleExpiredRefreshToken();
}
}
// The token has not expired. Do nothing
return;
}

@@ -156,3 +180,4 @@ // Register the 'check for soon expiring access token' interval (Every minute)

.catch((error) => {
setError(error);
console.error(error);
setError(error.message);
});

@@ -159,0 +184,0 @@ }

import { TInternalConfig, TTokenResponse } from './Types';
export declare const EXPIRED_REFRESH_TOKEN_ERROR_CODES: string[];
export declare function redirectToLogin(config: TInternalConfig): Promise<void>;

@@ -10,2 +9,1 @@ export declare const fetchTokens: (config: TInternalConfig) => Promise<TTokenResponse>;

export declare function redirectToLogout(config: TInternalConfig, token: string): void;
export declare const errorMessageForExpiredRefreshToken: (errorMessage: string) => boolean;

@@ -12,8 +12,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.errorMessageForExpiredRefreshToken = exports.redirectToLogout = exports.fetchWithRefreshToken = exports.fetchTokens = exports.redirectToLogin = exports.EXPIRED_REFRESH_TOKEN_ERROR_CODES = void 0;
exports.redirectToLogout = exports.fetchWithRefreshToken = exports.fetchTokens = exports.redirectToLogin = void 0;
const pkceUtils_1 = require("./pkceUtils");
const httpUtils_1 = require("./httpUtils");
const codeVerifierStorageKey = 'PKCE_code_verifier';
// [ AzureAD,]
exports.EXPIRED_REFRESH_TOKEN_ERROR_CODES = ['AADSTS700084'];
function redirectToLogin(config) {

@@ -47,4 +45,3 @@ return __awaiter(this, void 0, void 0, function* () {

else {
console.error(body);
throw Error(body.error_description);
throw Error(body);
}

@@ -98,11 +95,1 @@ });

exports.redirectToLogout = redirectToLogout;
const errorMessageForExpiredRefreshToken = (errorMessage) => {
let expired = false;
exports.EXPIRED_REFRESH_TOKEN_ERROR_CODES.forEach((errorCode) => {
if (errorMessage.includes(errorCode)) {
expired = true;
}
});
return expired;
};
exports.errorMessageForExpiredRefreshToken = errorMessageForExpiredRefreshToken;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.postWithXForm = void 0;
const errors_1 = require("./errors");
function buildUrlEncodedRequest(request) {

@@ -12,14 +22,16 @@ let queryString = '';

function postWithXForm(url, request) {
return fetch(url, {
method: 'POST',
body: buildUrlEncodedRequest(request),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}).then((response) => {
if (!response.ok) {
console.error(response);
throw Error(response.statusText);
}
return response;
return __awaiter(this, void 0, void 0, function* () {
return fetch(url, {
method: 'POST',
body: buildUrlEncodedRequest(request),
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}).then((response) => __awaiter(this, void 0, void 0, function* () {
if (!response.ok) {
const responseBody = yield response.text();
throw new errors_1.FetchError(response.status, response.statusText, responseBody);
}
return response;
}));
});
}
exports.postWithXForm = postWithXForm;

@@ -67,6 +67,2 @@ import { ReactNode } from 'react';

};
export type TAzureADErrorResponse = {
error_description: string;
[k: string]: unknown;
};
export type TInternalConfig = {

@@ -73,0 +69,0 @@ clientId: string;

{
"name": "react-oauth2-code-pkce",
"version": "1.8.3",
"description": "Plug-and-play react package for OAuth2 Authorization Code flow with PKCE",
"version": "1.8.4",
"description": "Provider agnostic react package for OAuth2 Authorization Code flow with PKCE",
"main": "dist/index.js",

@@ -6,0 +6,0 @@ "types": "dist/index.d.ts",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc