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.3.0-alpha.1 to 1.3.0-alpha.2

28

dist/AuthContext.js

@@ -42,5 +42,5 @@ "use strict";

const [refreshToken, setRefreshToken] = (0, Hooks_1.default)('ROCP_refreshToken', undefined);
const [refreshTokenExpire, setRefreshTokenExpire] = (0, Hooks_1.default)('ROCP_refreshTokenExpire', (0, authentication_1.timeOfExpire)(FALLBACK_EXPIRE_TIME));
const [refreshTokenExpire, setRefreshTokenExpire] = (0, Hooks_1.default)('ROCP_refreshTokenExpire', (0, authentication_1.epochAtSecondsFromNow)(2 * FALLBACK_EXPIRE_TIME));
const [token, setToken] = (0, Hooks_1.default)('ROCP_token', '');
const [tokenExpire, setTokenExpire] = (0, Hooks_1.default)('ROCP_tokenExpire', (0, authentication_1.timeOfExpire)(FALLBACK_EXPIRE_TIME));
const [tokenExpire, setTokenExpire] = (0, Hooks_1.default)('ROCP_tokenExpire', (0, authentication_1.epochAtSecondsFromNow)(FALLBACK_EXPIRE_TIME));
const [idToken, setIdToken] = (0, Hooks_1.default)('ROCP_idToken', undefined);

@@ -64,4 +64,4 @@ const [loginInProgress, setLoginInProgress] = (0, Hooks_1.default)('ROCP_loginInProgress', false);

setToken('');
setTokenExpire((0, authentication_1.timeOfExpire)(FALLBACK_EXPIRE_TIME));
setRefreshTokenExpire((0, authentication_1.timeOfExpire)(FALLBACK_EXPIRE_TIME));
setTokenExpire((0, authentication_1.epochAtSecondsFromNow)(FALLBACK_EXPIRE_TIME));
setRefreshTokenExpire((0, authentication_1.epochAtSecondsFromNow)(FALLBACK_EXPIRE_TIME));
setIdToken(undefined);

@@ -72,7 +72,13 @@ setTokenData(undefined);

function handleTokenResponse(response) {
setRefreshToken(response?.refresh_token);
setToken(response.access_token);
setTokenExpire((0, authentication_1.timeOfExpire)(response.expires_in || FALLBACK_EXPIRE_TIME));
setRefreshTokenExpire((0, authentication_1.timeOfExpire)(response.refresh_token_expires_in || FALLBACK_EXPIRE_TIME));
setIdToken(response?.id_token);
setRefreshToken(response.refresh_token);
setTokenExpire((0, authentication_1.epochAtSecondsFromNow)(response.expires_in || FALLBACK_EXPIRE_TIME));
// If there is no refresh_token_expire, use access_token_expire + 10min.
// If no access_token_expire, assume double the fallback expire time
let refreshTokenExpire = response.refresh_token_expires_in || 2 * FALLBACK_EXPIRE_TIME;
if (!response.refresh_token_expires_in && response.expires_in) {
refreshTokenExpire = response.expires_in + FALLBACK_EXPIRE_TIME;
}
setRefreshTokenExpire((0, authentication_1.epochAtSecondsFromNow)(refreshTokenExpire));
setIdToken(response.id_token);
setLoginInProgress(false);

@@ -88,4 +94,4 @@ try {

function refreshAccessToken() {
if (token && (0, authentication_1.tokenExpired)(tokenExpire)) {
if (refreshToken && !(0, authentication_1.tokenExpired)(refreshTokenExpire)) {
if (token && (0, authentication_1.epochTimeIsPast)(tokenExpire)) {
if (refreshToken && !(0, authentication_1.epochTimeIsPast)(refreshTokenExpire)) {
(0, authentication_1.fetchWithRefreshToken)({ config, refreshToken })

@@ -103,3 +109,3 @@ .then((result) => handleTokenResponse(result))

// The refresh token has expired. Need to log in from scratch.
logOut();
setLoginInProgress(true);
(0, authentication_1.logIn)(config);

@@ -106,0 +112,0 @@ }

@@ -13,3 +13,3 @@ import { TInternalConfig, TTokenData, TTokenResponse } from './Types';

export declare const decodeJWT: (token: string) => TTokenData;
export declare const timeOfExpire: (validTimeDelta: number) => number;
export declare const epochAtSecondsFromNow: (secondsFromNow: number) => number;
/**

@@ -19,3 +19,3 @@ * Check if the Access Token has expired.

*/
export declare function tokenExpired(tokenExpire: number): boolean;
export declare function epochTimeIsPast(timestamp: number): boolean;
export declare const errorMessageForExpiredRefreshToken: (errorMessage: string) => boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.errorMessageForExpiredRefreshToken = exports.tokenExpired = exports.timeOfExpire = exports.decodeJWT = exports.fetchWithRefreshToken = exports.fetchTokens = exports.logIn = exports.EXPIRED_REFRESH_TOKEN_ERROR_CODES = void 0;
exports.errorMessageForExpiredRefreshToken = exports.epochTimeIsPast = exports.epochAtSecondsFromNow = exports.decodeJWT = exports.fetchWithRefreshToken = exports.fetchTokens = exports.logIn = exports.EXPIRED_REFRESH_TOKEN_ERROR_CODES = void 0;
const pkceUtils_1 = require("./pkceUtils");

@@ -113,4 +113,4 @@ const codeVerifierStorageKey = 'PKCE_code_verifier';

// Returns epoch time (in seconds) for when the token will expire
const timeOfExpire = (validTimeDelta) => Math.round(Date.now() / 1000 + validTimeDelta);
exports.timeOfExpire = timeOfExpire;
const epochAtSecondsFromNow = (secondsFromNow) => Math.round(Date.now() / 1000 + secondsFromNow);
exports.epochAtSecondsFromNow = epochAtSecondsFromNow;
/**

@@ -120,9 +120,8 @@ * Check if the Access Token has expired.

*/
function tokenExpired(tokenExpire) {
function epochTimeIsPast(timestamp) {
const now = Math.round(Date.now()) / 1000;
const bufferTimeInSeconds = 5 * 60; // minutes * seconds
const nowWithBuffer = now + bufferTimeInSeconds;
return nowWithBuffer >= tokenExpire;
const nowWithBuffer = now + 120;
return nowWithBuffer >= timestamp;
}
exports.tokenExpired = tokenExpired;
exports.epochTimeIsPast = epochTimeIsPast;
const errorMessageForExpiredRefreshToken = (errorMessage) => {

@@ -129,0 +128,0 @@ let expired = false;

{
"name": "react-oauth2-code-pkce",
"version": "1.3.0-alpha.1",
"version": "1.3.0-alpha.2",
"description": "Plug-and-play react package for OAuth2 Authorization Code flow with PKCE",

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

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