New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@digigov/auth

Package Overview
Dependencies
Maintainers
3
Versions
269
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@digigov/auth - npm Package Compare versions

Comparing version 0.0.1-fix-logout.10 to 0.0.1-fix-reused-token-bug.6

1

AuthProvider.d.ts

@@ -13,3 +13,2 @@ import React from 'react';

navigate: (url: string) => void;
userUpdatedAt?: number | null;
};

@@ -16,0 +15,0 @@ declare type ContextValue = {

18

authReducer.js

@@ -26,4 +26,3 @@ "use strict";

error: null,
code: null,
userUpdatedAt: Date.now()
code: null
}));

@@ -37,4 +36,3 @@

processing: false,
error: null,
userUpdatedAt: null
error: null
}));

@@ -48,4 +46,3 @@

error: null,
code: null,
userUpdatedAt: null
code: null
}));

@@ -61,4 +58,3 @@

code: null,
error: null,
userUpdatedAt: null
error: null
}));

@@ -70,4 +66,3 @@

error: null,
authenticated: false,
userUpdatedAt: null
authenticated: false
}));

@@ -89,4 +84,3 @@

token: null,
id: false,
userUpdatedAt: null
id: false
}));

@@ -93,0 +87,0 @@

@@ -14,4 +14,3 @@ import _extends from "@babel/runtime/helpers/extends";

error: null,
code: null,
userUpdatedAt: Date.now()
code: null
}));

@@ -25,4 +24,3 @@

processing: false,
error: null,
userUpdatedAt: null
error: null
}));

@@ -36,4 +34,3 @@

error: null,
code: null,
userUpdatedAt: null
code: null
}));

@@ -49,4 +46,3 @@

code: null,
error: null,
userUpdatedAt: null
error: null
}));

@@ -58,4 +54,3 @@

error: null,
authenticated: false,
userUpdatedAt: null
authenticated: false
}));

@@ -77,4 +72,3 @@

token: null,
id: false,
userUpdatedAt: null
id: false
}));

@@ -81,0 +75,0 @@

@@ -7,4 +7,2 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";

import { useDisableLoginNext } from '@digigov/auth/hooks';
export var TOKEN_REVALIDATION_INTERVAL = 10; // seconds
export function useAuth() {

@@ -119,3 +117,3 @@ var _useContext = useContext(AuthContext),

_handleToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(state, dispatch, onError) {
var token, userUpdatedAt, revalidatedBefore, data, _user;
var token, data, _user;

@@ -129,30 +127,11 @@ return _regeneratorRuntime.wrap(function _callee2$(_context2) {

if (!state.config.userDataURL) {
_context2.next = 31;
_context2.next = 24;
break;
}
userUpdatedAt = localStorage.getItem('userUpdatedAt');
if (!userUpdatedAt) {
_context2.next = 8;
break;
}
revalidatedBefore = (Date.now() - parseInt(userUpdatedAt)) / 1000;
if (!(revalidatedBefore < TOKEN_REVALIDATION_INTERVAL)) {
_context2.next = 8;
break;
}
console.log("Token validated before ".concat(revalidatedBefore, ". Aborting request."));
return _context2.abrupt("return");
case 8:
localStorage.setItem('userUpdatedAt', "".concat(Date.now()));
dispatch({
type: 'authenticating'
});
_context2.prev = 10;
_context2.next = 13;
_context2.prev = 3;
_context2.next = 6;
return fetch(state.config.userDataURL, {

@@ -164,7 +143,7 @@ headers: {

case 13:
case 6:
data = _context2.sent;
if (!(data.status === 404 || data.status === 401 || !data.ok)) {
_context2.next = 20;
_context2.next = 13;
break;

@@ -179,20 +158,20 @@ }

logout(onError);
_context2.next = 24;
_context2.next = 17;
break;
case 20:
_context2.next = 22;
case 13:
_context2.next = 15;
return data.json();
case 22:
case 15:
_user = _context2.sent;
login(token, _user);
case 24:
_context2.next = 31;
case 17:
_context2.next = 24;
break;
case 26:
_context2.prev = 26;
_context2.t0 = _context2["catch"](10);
case 19:
_context2.prev = 19;
_context2.t0 = _context2["catch"](3);
console.error('Error in fetch userDataURL', _context2.t0);

@@ -205,3 +184,3 @@ logout(onError);

case 31:
case 24:
case "end":

@@ -211,3 +190,3 @@ return _context2.stop();

}
}, _callee2, null, [[10, 26]]);
}, _callee2, null, [[3, 19]]);
}));

@@ -218,13 +197,2 @@ return _handleToken.apply(this, arguments);

function revalidateToken(onError) {
if (state.userUpdatedAt) {
// check if a revalidation was asked during the specified interval
// and stop the process
var revalidatedBefore = (Date.now() - state.userUpdatedAt) / 1000;
console.log("Token validated before ".concat(revalidatedBefore));
if (revalidatedBefore < TOKEN_REVALIDATION_INTERVAL) {
return;
}
}
handleToken(state, dispatch, onError);

@@ -231,0 +199,0 @@ }

@@ -24,3 +24,5 @@ import React, { useEffect } from 'react';

} else {
auth.resolveTokenFromCode(code);
if (auth.code !== code) {
auth.resolveTokenFromCode(code);
}
}

@@ -31,4 +33,8 @@ }, [code]);

if (!isPopup) {
isBrowser && window.localStorage.removeItem('login-next');
navigate(next || '/');
if (auth.code !== code) {
isBrowser && window.localStorage.removeItem('login-next');
navigate(next || '/');
} else {
window.history.forward();
}
} else {

@@ -35,0 +41,0 @@ isBrowser && window.close();

@@ -14,4 +14,3 @@ import _extends from "@babel/runtime/helpers/extends";

error: null,
code: null,
userUpdatedAt: Date.now()
code: null
}));

@@ -25,4 +24,3 @@

processing: false,
error: null,
userUpdatedAt: null
error: null
}));

@@ -36,4 +34,3 @@

error: null,
code: null,
userUpdatedAt: null
code: null
}));

@@ -49,4 +46,3 @@

code: null,
error: null,
userUpdatedAt: null
error: null
}));

@@ -58,4 +54,3 @@

error: null,
authenticated: false,
userUpdatedAt: null
authenticated: false
}));

@@ -77,4 +72,3 @@

token: null,
id: false,
userUpdatedAt: null
id: false
}));

@@ -81,0 +75,0 @@

@@ -1,2 +0,2 @@

/** @license Digigov v0.0.1-fix-logout.10+968775c
/** @license Digigov v0.0.1-fix-reused-token-bug.6+f3174d0
*

@@ -12,4 +12,2 @@ * This source code is licensed under the MIT license found in the

import { useDisableLoginNext } from '@digigov/auth/hooks';
export var TOKEN_REVALIDATION_INTERVAL = 10; // seconds
export function useAuth() {

@@ -124,3 +122,3 @@ var _useContext = useContext(AuthContext),

_handleToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(state, dispatch, onError) {
var token, userUpdatedAt, revalidatedBefore, data, _user;
var token, data, _user;

@@ -134,30 +132,11 @@ return _regeneratorRuntime.wrap(function _callee2$(_context2) {

if (!state.config.userDataURL) {
_context2.next = 31;
_context2.next = 24;
break;
}
userUpdatedAt = localStorage.getItem('userUpdatedAt');
if (!userUpdatedAt) {
_context2.next = 8;
break;
}
revalidatedBefore = (Date.now() - parseInt(userUpdatedAt)) / 1000;
if (!(revalidatedBefore < TOKEN_REVALIDATION_INTERVAL)) {
_context2.next = 8;
break;
}
console.log("Token validated before ".concat(revalidatedBefore, ". Aborting request."));
return _context2.abrupt("return");
case 8:
localStorage.setItem('userUpdatedAt', "".concat(Date.now()));
dispatch({
type: 'authenticating'
});
_context2.prev = 10;
_context2.next = 13;
_context2.prev = 3;
_context2.next = 6;
return fetch(state.config.userDataURL, {

@@ -169,7 +148,7 @@ headers: {

case 13:
case 6:
data = _context2.sent;
if (!(data.status === 404 || data.status === 401 || !data.ok)) {
_context2.next = 20;
_context2.next = 13;
break;

@@ -184,20 +163,20 @@ }

logout(onError);
_context2.next = 24;
_context2.next = 17;
break;
case 20:
_context2.next = 22;
case 13:
_context2.next = 15;
return data.json();
case 22:
case 15:
_user = _context2.sent;
login(token, _user);
case 24:
_context2.next = 31;
case 17:
_context2.next = 24;
break;
case 26:
_context2.prev = 26;
_context2.t0 = _context2["catch"](10);
case 19:
_context2.prev = 19;
_context2.t0 = _context2["catch"](3);
console.error('Error in fetch userDataURL', _context2.t0);

@@ -210,3 +189,3 @@ logout(onError);

case 31:
case 24:
case "end":

@@ -216,3 +195,3 @@ return _context2.stop();

}
}, _callee2, null, [[10, 26]]);
}, _callee2, null, [[3, 19]]);
}));

@@ -223,13 +202,2 @@ return _handleToken.apply(this, arguments);

function revalidateToken(onError) {
if (state.userUpdatedAt) {
// check if a revalidation was asked during the specified interval
// and stop the process
var revalidatedBefore = (Date.now() - state.userUpdatedAt) / 1000;
console.log("Token validated before ".concat(revalidatedBefore));
if (revalidatedBefore < TOKEN_REVALIDATION_INTERVAL) {
return;
}
}
handleToken(state, dispatch, onError);

@@ -236,0 +204,0 @@ }

@@ -24,3 +24,5 @@ import React, { useEffect } from 'react';

} else {
auth.resolveTokenFromCode(code);
if (auth.code !== code) {
auth.resolveTokenFromCode(code);
}
}

@@ -31,4 +33,8 @@ }, [code]);

if (!isPopup) {
isBrowser && window.localStorage.removeItem('login-next');
navigate(next || '/');
if (auth.code !== code) {
isBrowser && window.localStorage.removeItem('login-next');
navigate(next || '/');
} else {
window.history.forward();
}
} else {

@@ -35,0 +41,0 @@ isBrowser && window.close();

@@ -5,3 +5,2 @@ export declare type UserID = string | number;

export declare type CodeType = string | Record<string, any> | null;
export declare const TOKEN_REVALIDATION_INTERVAL = 10;
export declare type AuthConfig = {

@@ -8,0 +7,0 @@ userDataURL?: string;

@@ -1,2 +0,2 @@

/** @license Digigov v0.0.1-fix-logout.10+968775c
/** @license Digigov v0.0.1-fix-reused-token-bug.6+f3174d0
*

@@ -14,7 +14,6 @@ * This source code is licensed under the MIT license found in the

var _exportNames = {
TOKEN_REVALIDATION_INTERVAL: true,
useAuth: true
};
exports.useAuth = useAuth;
exports["default"] = exports.TOKEN_REVALIDATION_INTERVAL = void 0;
exports["default"] = void 0;

@@ -67,6 +66,3 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

});
var TOKEN_REVALIDATION_INTERVAL = 10; // seconds
exports.TOKEN_REVALIDATION_INTERVAL = TOKEN_REVALIDATION_INTERVAL;
function useAuth() {

@@ -181,3 +177,3 @@ var _useContext = (0, _react.useContext)(_AuthProvider.AuthContext),

_handleToken = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(state, dispatch, onError) {
var token, userUpdatedAt, revalidatedBefore, data, _user;
var token, data, _user;

@@ -191,30 +187,11 @@ return _regenerator["default"].wrap(function _callee2$(_context2) {

if (!state.config.userDataURL) {
_context2.next = 31;
_context2.next = 24;
break;
}
userUpdatedAt = localStorage.getItem('userUpdatedAt');
if (!userUpdatedAt) {
_context2.next = 8;
break;
}
revalidatedBefore = (Date.now() - parseInt(userUpdatedAt)) / 1000;
if (!(revalidatedBefore < TOKEN_REVALIDATION_INTERVAL)) {
_context2.next = 8;
break;
}
console.log("Token validated before ".concat(revalidatedBefore, ". Aborting request."));
return _context2.abrupt("return");
case 8:
localStorage.setItem('userUpdatedAt', "".concat(Date.now()));
dispatch({
type: 'authenticating'
});
_context2.prev = 10;
_context2.next = 13;
_context2.prev = 3;
_context2.next = 6;
return fetch(state.config.userDataURL, {

@@ -226,7 +203,7 @@ headers: {

case 13:
case 6:
data = _context2.sent;
if (!(data.status === 404 || data.status === 401 || !data.ok)) {
_context2.next = 20;
_context2.next = 13;
break;

@@ -241,20 +218,20 @@ }

logout(onError);
_context2.next = 24;
_context2.next = 17;
break;
case 20:
_context2.next = 22;
case 13:
_context2.next = 15;
return data.json();
case 22:
case 15:
_user = _context2.sent;
login(token, _user);
case 24:
_context2.next = 31;
case 17:
_context2.next = 24;
break;
case 26:
_context2.prev = 26;
_context2.t0 = _context2["catch"](10);
case 19:
_context2.prev = 19;
_context2.t0 = _context2["catch"](3);
console.error('Error in fetch userDataURL', _context2.t0);

@@ -267,3 +244,3 @@ logout(onError);

case 31:
case 24:
case "end":

@@ -273,3 +250,3 @@ return _context2.stop();

}
}, _callee2, null, [[10, 26]]);
}, _callee2, null, [[3, 19]]);
}));

@@ -280,13 +257,2 @@ return _handleToken.apply(this, arguments);

function revalidateToken(onError) {
if (state.userUpdatedAt) {
// check if a revalidation was asked during the specified interval
// and stop the process
var revalidatedBefore = (Date.now() - state.userUpdatedAt) / 1000;
console.log("Token validated before ".concat(revalidatedBefore));
if (revalidatedBefore < TOKEN_REVALIDATION_INTERVAL) {
return;
}
}
handleToken(state, dispatch, onError);

@@ -293,0 +259,0 @@ }

{
"name": "@digigov/auth",
"version": "0.0.1-fix-logout.10+968775c",
"version": "0.0.1-fix-reused-token-bug.6+f3174d0",
"description": "@digigov authentication client",

@@ -20,5 +20,5 @@ "author": "GRNET Developers <devs@lists.grnet.gr>",

},
"gitHead": "968775cf329b3ac8a1a82fba3830c7a988fe9bf4",
"gitHead": "f3174d0438c96496b78a092108b4c2e9849105d8",
"private": false,
"typings": "./index.d.ts"
}

@@ -41,3 +41,5 @@ "use strict";

} else {
auth.resolveTokenFromCode(code);
if (auth.code !== code) {
auth.resolveTokenFromCode(code);
}
}

@@ -48,4 +50,8 @@ }, [code]);

if (!isPopup) {
isBrowser && window.localStorage.removeItem('login-next');
navigate(next || '/');
if (auth.code !== code) {
isBrowser && window.localStorage.removeItem('login-next');
navigate(next || '/');
} else {
window.history.forward();
}
} else {

@@ -52,0 +58,0 @@ isBrowser && window.close();

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