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

@jfront/oauth-context

Package Overview
Dependencies
Maintainers
5
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jfront/oauth-context - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

12

CHANGELOG.md

@@ -6,2 +6,14 @@ # Change Log

# [0.3.0](https://github.com/Jepria/jfront-oauth/compare/@jfront/oauth-context@0.2.2...@jfront/oauth-context@0.3.0) (2023-07-30)
### Features
- added the ability to request oauthContextPath from the application REST API
([9e0d6f2](https://github.com/Jepria/jfront-oauth/commit/9e0d6f2a8cdfd4a23009b1cf80cf9e8084b71383))
# Change Log
All notable changes to this project will be documented in this file. See
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [0.2.2](https://github.com/Jepria/jfront-oauth/compare/@jfront/oauth-context@0.2.1...@jfront/oauth-context@0.2.2) (2022-12-29)

@@ -8,0 +20,0 @@

147

dist/cjs/OAuthContextProvider.js

@@ -16,2 +16,6 @@ "use strict";

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
/**

@@ -33,2 +37,3 @@ * Базовый Provider OAuth контекста. Не содержит реализаций платформозависимых методов. Они переведены в callback'и в props.

oauthContextPath = _ref.oauthContextPath,
applicationApiPath = _ref.applicationApiPath,
axiosInstance = _ref.axiosInstance,

@@ -41,2 +46,3 @@ children = _ref.children;

_useReducer$ = _useReducer[0],
oauthContextPathExt = _useReducer$.oauthContextPathExt,
accessToken = _useReducer$.accessToken,

@@ -56,10 +62,102 @@ expiresIn = _useReducer$.expiresIn,

var oauth = new _oauthCore.OAuth(clientId, redirectUri, oauthContextPath + "/authorize", oauthContextPath + "/token", oauthContextPath + "/logout", storage);
var getOAuthContextPath = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
var metaString, meta, responseData;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!oauthContextPath) {
_context.next = 2;
break;
}
return _context.abrupt("return", Promise.resolve(oauthContextPath));
case 2:
if (!oauthContextPathExt) {
_context.next = 4;
break;
}
return _context.abrupt("return", Promise.resolve(oauthContextPathExt));
case 4:
if (!state) {
_context.next = 10;
break;
}
metaString = storage.getItem(state);
if (!metaString) {
_context.next = 10;
break;
}
meta = JSON.parse(metaString);
if (!(meta != null && meta.oauthContextPath)) {
_context.next = 10;
break;
}
return _context.abrupt("return", Promise.resolve(meta.oauthContextPath));
case 10:
if (applicationApiPath) {
_context.next = 12;
break;
}
throw new Error("url for oauthContextPath request is empty");
case 12:
_context.prev = 12;
dispatch((0, _oauthCore.oauthContextPathRequest)());
_context.next = 16;
return (0, _oauthCore.getOAuthContextPathFromApi)(applicationApiPath + "/oauth/oauth-context-path");
case 16:
responseData = _context.sent;
if (responseData != null && responseData.oauthContextPath) {
_context.next = 19;
break;
}
return _context.abrupt("return", Promise.reject(new Error("received an empty oauthContextPath from the application API")));
case 19:
return _context.abrupt("return", Promise.resolve(responseData.oauthContextPath));
case 22:
_context.prev = 22;
_context.t0 = _context["catch"](12);
return _context.abrupt("return", Promise.reject(_context.t0));
case 25:
case "end":
return _context.stop();
}
}
}, _callee, null, [[12, 22]]);
}));
return function getOAuthContextPath() {
return _ref2.apply(this, arguments);
};
}();
var authorize = function authorize() {
if (!isOAuthCallback()) {
oauth.authorize("code", getCurrentUrl()).then(function (result) {
dispatch((0, _oauthCore.authorizationRequest)(result));
getOAuthContextPath().then(function (result) {
var oauth = new _oauthCore.OAuth(clientId, redirectUri, result + "/authorize", result + "/token", result + "/logout", storage);
oauth.authorize("code", getCurrentUrl()).then(function (result) {
dispatch((0, _oauthCore.authorizationRequest)(result));
})["catch"](function (error) {
dispatch((0, _oauthCore.authorizationRequestFailure)("UNHANDLED_ERROR", error.message));
});
})["catch"](function (error) {
dispatch((0, _oauthCore.authorizationRequestFailure)("UNHANDLED_ERROR", error.message));
dispatch((0, _oauthCore.oauthContextPathRequestFailure)("INVALID_REQUEST", "Error getting oauthContextPath from application API." + (error != null && error.message ? " Cause: " + error.message : "")));
});

@@ -69,4 +167,5 @@ }

var getToken = function getToken(authCode, state) {
var getToken = function getToken(authCode, state, oauthContextPath) {
dispatch((0, _oauthCore.tokenRequest)());
var oauth = new _oauthCore.OAuth(clientId, redirectUri, oauthContextPath + "/authorize", oauthContextPath + "/token", oauthContextPath + "/logout", storage);
return oauth.getTokenWithAuthCode(authCode, state);

@@ -83,18 +182,23 @@ };

if (authorizationCode && state) {
var metaString = storage.getItem(state);
getToken(authorizationCode, state).then(function (result) {
if (!metaString) {
throw new Error("state not found");
}
getOAuthContextPath().then(function (result) {
dispatch((0, _oauthCore.oauthContextPathRequestSuccess)(result));
var metaString = storage.getItem(state);
getToken(authorizationCode, state, result).then(function (result) {
if (!metaString) {
throw new Error("state not found");
}
var meta = JSON.parse(metaString);
var meta = JSON.parse(metaString);
if (result.token_type === "Bearer") {
forward(meta.currentPath);
dispatch((0, _oauthCore.tokenRequestSuccess)(result.access_token, result.expires_in, result.token_type, result.refresh_token));
} else {
dispatch((0, _oauthCore.tokenRequestFailure)("INVALID_RESPONSE", "Not supported token type"));
}
if (result.token_type === "Bearer") {
forward(meta.currentPath);
dispatch((0, _oauthCore.tokenRequestSuccess)(result.access_token, result.expires_in, result.token_type, result.refresh_token));
} else {
dispatch((0, _oauthCore.tokenRequestFailure)("INVALID_RESPONSE", "Not supported token type"));
}
})["catch"](function (error) {
dispatch((0, _oauthCore.tokenRequestFailure)(error.error, error.errorUri, error.errorDescription, error.errorId));
});
})["catch"](function (error) {
dispatch((0, _oauthCore.tokenRequestFailure)(error.error, error.errorUri, error.errorDescription, error.errorId));
dispatch((0, _oauthCore.oauthContextPathRequestFailure)("INVALID_REQUEST", "Error getting oauthContextPath from application API." + (error != null && error.message ? " Cause: " + error.message : "")));
});

@@ -145,3 +249,8 @@ } // eslint-disable-next-line react-hooks/exhaustive-deps

var logout = function logout() {
onLogout(oauth.logout(getCurrentUrl()));
getOAuthContextPath().then(function (result) {
var oauth = new _oauthCore.OAuth(clientId, redirectUri, result + "/authorize", result + "/token", result + "/logout", storage);
onLogout(oauth.logout(getCurrentUrl()));
})["catch"](function (error) {
dispatch((0, _oauthCore.oauthContextPathRequestFailure)("INVALID_REQUEST", "Error getting oauthContextPath from application API." + (error != null && error.message ? " Cause: " + error.message : "")));
});
};

@@ -148,0 +257,0 @@

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

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
import React, { useReducer, useEffect } from "react";
import { OAuthReducer, OAuth, authorizationRequest, authorizationRequestFailure, tokenRequest, tokenRequestSuccess, tokenRequestFailure, authorizationRequestSuccess } from "@jfront/oauth-core";
import { OAuthReducer, OAuth, authorizationRequest, authorizationRequestFailure, tokenRequest, tokenRequestSuccess, tokenRequestFailure, authorizationRequestSuccess, oauthContextPathRequest, oauthContextPathRequestSuccess, oauthContextPathRequestFailure, getOAuthContextPathFromApi } from "@jfront/oauth-core";
import { OAuthContext } from "./OAuthContext";

@@ -22,2 +26,3 @@

oauthContextPath,
applicationApiPath,
axiosInstance,

@@ -27,2 +32,3 @@ children

var [{
oauthContextPathExt,
accessToken,

@@ -43,10 +49,59 @@ expiresIn,

});
var oauth = new OAuth(clientId, redirectUri, oauthContextPath + "/authorize", oauthContextPath + "/token", oauthContextPath + "/logout", storage);
var getOAuthContextPath = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator(function* () {
if (oauthContextPath) {
return Promise.resolve(oauthContextPath);
}
if (oauthContextPathExt) {
return Promise.resolve(oauthContextPathExt);
}
if (state) {
var metaString = storage.getItem(state);
if (metaString) {
var meta = JSON.parse(metaString);
if (meta != null && meta.oauthContextPath) {
return Promise.resolve(meta.oauthContextPath);
}
}
}
if (!applicationApiPath) {
throw new Error("url for oauthContextPath request is empty");
}
try {
dispatch(oauthContextPathRequest());
var responseData = yield getOAuthContextPathFromApi(applicationApiPath + "/oauth/oauth-context-path");
if (!(responseData != null && responseData.oauthContextPath)) {
return Promise.reject(new Error("received an empty oauthContextPath from the application API"));
}
return Promise.resolve(responseData.oauthContextPath);
} catch (error) {
return Promise.reject(error);
}
});
return function getOAuthContextPath() {
return _ref2.apply(this, arguments);
};
}();
var authorize = () => {
if (!isOAuthCallback()) {
oauth.authorize("code", getCurrentUrl()).then(result => {
dispatch(authorizationRequest(result));
getOAuthContextPath().then(result => {
var oauth = new OAuth(clientId, redirectUri, result + "/authorize", result + "/token", result + "/logout", storage);
oauth.authorize("code", getCurrentUrl()).then(result => {
dispatch(authorizationRequest(result));
}).catch(error => {
dispatch(authorizationRequestFailure("UNHANDLED_ERROR", error.message));
});
}).catch(error => {
dispatch(authorizationRequestFailure("UNHANDLED_ERROR", error.message));
dispatch(oauthContextPathRequestFailure("INVALID_REQUEST", "Error getting oauthContextPath from application API." + (error != null && error.message ? " Cause: " + error.message : "")));
});

@@ -56,4 +111,5 @@ }

var getToken = (authCode, state) => {
var getToken = (authCode, state, oauthContextPath) => {
dispatch(tokenRequest());
var oauth = new OAuth(clientId, redirectUri, oauthContextPath + "/authorize", oauthContextPath + "/token", oauthContextPath + "/logout", storage);
return oauth.getTokenWithAuthCode(authCode, state);

@@ -70,18 +126,23 @@ };

if (authorizationCode && state) {
var metaString = storage.getItem(state);
getToken(authorizationCode, state).then(result => {
if (!metaString) {
throw new Error("state not found");
}
getOAuthContextPath().then(result => {
dispatch(oauthContextPathRequestSuccess(result));
var metaString = storage.getItem(state);
getToken(authorizationCode, state, result).then(result => {
if (!metaString) {
throw new Error("state not found");
}
var meta = JSON.parse(metaString);
var meta = JSON.parse(metaString);
if (result.token_type === "Bearer") {
forward(meta.currentPath);
dispatch(tokenRequestSuccess(result.access_token, result.expires_in, result.token_type, result.refresh_token));
} else {
dispatch(tokenRequestFailure("INVALID_RESPONSE", "Not supported token type"));
}
if (result.token_type === "Bearer") {
forward(meta.currentPath);
dispatch(tokenRequestSuccess(result.access_token, result.expires_in, result.token_type, result.refresh_token));
} else {
dispatch(tokenRequestFailure("INVALID_RESPONSE", "Not supported token type"));
}
}).catch(error => {
dispatch(tokenRequestFailure(error.error, error.errorUri, error.errorDescription, error.errorId));
});
}).catch(error => {
dispatch(tokenRequestFailure(error.error, error.errorUri, error.errorDescription, error.errorId));
dispatch(oauthContextPathRequestFailure("INVALID_REQUEST", "Error getting oauthContextPath from application API." + (error != null && error.message ? " Cause: " + error.message : "")));
});

@@ -132,3 +193,8 @@ } // eslint-disable-next-line react-hooks/exhaustive-deps

var logout = () => {
onLogout(oauth.logout(getCurrentUrl()));
getOAuthContextPath().then(result => {
var oauth = new OAuth(clientId, redirectUri, result + "/authorize", result + "/token", result + "/logout", storage);
onLogout(oauth.logout(getCurrentUrl()));
}).catch(error => {
dispatch(oauthContextPathRequestFailure("INVALID_REQUEST", "Error getting oauthContextPath from application API." + (error != null && error.message ? " Cause: " + error.message : "")));
});
};

@@ -135,0 +201,0 @@

3

dist/types/OAuthContextProvider.d.ts

@@ -21,3 +21,4 @@ import React from "react";

redirectUri: string;
oauthContextPath: string;
oauthContextPath?: string;
applicationApiPath?: string;
axiosInstance?: AxiosInstance;

@@ -24,0 +25,0 @@ }

{
"name": "@jfront/oauth-context",
"version": "0.2.2",
"version": "0.3.0",
"license": "Apache-2.0",

@@ -11,3 +11,3 @@ "repository": "https://github.com/Jepria/jfront-oauth",

"dependencies": {
"@jfront/oauth-core": "^0.2.2"
"@jfront/oauth-core": "^0.3.0"
},

@@ -35,3 +35,3 @@ "peerDependencies": {

},
"gitHead": "15f07fca8a3f767553f9c3b017da4f8fe78b1d53"
"gitHead": "9720adf4f759ce33a6e2f1001ea87f75b9bc9d82"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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