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.10.2 to 1.10.3

22

dist/AuthContext.js

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

const errors_1 = require("./errors");
const FALLBACK_EXPIRE_TIME = 600; // 10minutes
exports.AuthContext = (0, react_1.createContext)({

@@ -48,5 +47,5 @@ token: '',

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

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

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

@@ -84,13 +83,8 @@ setTokenData(undefined);

function handleTokenResponse(response) {
var _a, _b;
var _a;
setToken(response.access_token);
setRefreshToken(response.refresh_token);
setTokenExpire((0, timeUtils_1.epochAtSecondsFromNow)((_a = response.expires_in) !== null && _a !== void 0 ? _a : 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 = (_b = response.refresh_token_expires_in) !== null && _b !== void 0 ? _b : 2 * FALLBACK_EXPIRE_TIME;
if (!response.refresh_token_expires_in && response.expires_in) {
refreshTokenExpire = response.expires_in + FALLBACK_EXPIRE_TIME;
}
setRefreshTokenExpire((0, timeUtils_1.epochAtSecondsFromNow)(refreshTokenExpire));
const tokenExpiresIn = (_a = response.expires_in) !== null && _a !== void 0 ? _a : timeUtils_1.FALLBACK_EXPIRE_TIME;
setTokenExpire((0, timeUtils_1.epochAtSecondsFromNow)(tokenExpiresIn));
setRefreshTokenExpire((0, timeUtils_1.epochAtSecondsFromNow)((0, timeUtils_1.getRefreshExpiresIn)(tokenExpiresIn, response)));
setIdToken(response.id_token);

@@ -97,0 +91,0 @@ setLoginInProgress(false);

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

import { TTokenResponse } from './Types';
export declare const FALLBACK_EXPIRE_TIME = 600;
export declare const epochAtSecondsFromNow: (secondsFromNow: number) => number;

@@ -7,1 +9,2 @@ /**

export declare function epochTimeIsPast(timestamp: number): boolean;
export declare function getRefreshExpiresIn(tokenExpiresIn: number, response: TTokenResponse): number;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.epochTimeIsPast = exports.epochAtSecondsFromNow = void 0;
exports.getRefreshExpiresIn = exports.epochTimeIsPast = exports.epochAtSecondsFromNow = exports.FALLBACK_EXPIRE_TIME = void 0;
exports.FALLBACK_EXPIRE_TIME = 600; // 10minutes
// Returns epoch time (in seconds) for when the token will expire

@@ -17,1 +18,13 @@ const epochAtSecondsFromNow = (secondsFromNow) => Math.round(Date.now() / 1000 + secondsFromNow);

exports.epochTimeIsPast = epochTimeIsPast;
const refreshExpireKeys = [
'refresh_expires_in',
'refresh_token_expires_in', // Azure AD
];
function getRefreshExpiresIn(tokenExpiresIn, response) {
for (const key of refreshExpireKeys) {
if (key in response)
return response[key];
}
return tokenExpiresIn + exports.FALLBACK_EXPIRE_TIME;
}
exports.getRefreshExpiresIn = getRefreshExpiresIn;

@@ -26,2 +26,3 @@ import { ReactNode } from 'react';

refresh_token_expires_in?: number;
refresh_expires_in?: number;
id_token?: string;

@@ -28,0 +29,0 @@ };

{
"name": "react-oauth2-code-pkce",
"version": "1.10.2",
"version": "1.10.3",
"description": "Provider agnostic 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