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

piral-oauth2

Package Overview
Dependencies
Maintainers
1
Versions
814
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

piral-oauth2 - npm Package Compare versions

Comparing version 0.11.1-pre.1050 to 0.11.1-pre.1053

35

lib/setup.d.ts

@@ -6,2 +6,31 @@ /**

/**
* The id of the client. Required for the setup of OAuth 2.0.
*/
clientId: string;
/**
* The client secret. Only required for the `code` flow.
*/
clientSecret?: string;
/**
* The Uri pointing to the authorization endpoint of the Identity Provider.
*/
authorizationUri: string;
/**
* The Uri pointing to the access token endpoint of the Identity Provider.
*/
accessTokenUri?: string;
/**
* The redirect Uri to use. By default the origin with /auth
* is used.
*/
redirectUri?: string;
/**
* The scopes to be used.
*/
scopes?: Array<string>;
/**
* The OAuth 2.0 authorization flow type to be used.
*/
flow?: 'implicit' | 'code';
/**
* Restricts token sharing such that other integrations, e.g., with

@@ -30,6 +59,2 @@ * fetch would need to be done manually.

/**
* Retrieves the current account.
*/
account(): Account;
/**
* Gets a token.

@@ -44,5 +69,5 @@ */

/**
* Sets up a new client wrapping the oauth2 API.
* Sets up a new client wrapping the OAuth 2.0 API.
* @param config The configuration for the client.
*/
export declare function setupOAuth2Client(config: OAuth2Config): OAuth2Client;

103

lib/setup.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ClientOAuth2 = require("client-oauth2");
var callbackName = 'oauth2Cb';
/**
* Sets up a new client wrapping the oauth2 API.
* Sets up a new client wrapping the OAuth 2.0 API.
* @param config The configuration for the client.
*/
function setupOAuth2Client(config) {
var _a = config.restrict, restrict = _a === void 0 ? false : _a;
return {
login: function () {
//TODO
},
logout: function () {
//TODO
},
account: function () {
//TODO
return undefined;
},
extendHeaders: function (req) {
if (!restrict) {
//TODO
req.setHeaders(undefined);
var clientId = config.clientId, clientSecret = config.clientSecret, authorizationUri = config.authorizationUri, accessTokenUri = config.accessTokenUri, _a = config.redirectUri, redirectUri = _a === void 0 ? location.origin + "/auth" : _a, _b = config.scopes, scopes = _b === void 0 ? [] : _b, flow = config.flow, _c = config.restrict, restrict = _c === void 0 ? false : _c;
var client = new ClientOAuth2({
clientId: clientId,
clientSecret: clientSecret,
redirectUri: redirectUri,
authorizationUri: authorizationUri,
accessTokenUri: accessTokenUri,
scopes: scopes,
});
var currentToken;
if (flow === 'code') {
client.code.getToken(location.href).then(function (token) { return (currentToken = token); }, function () { });
var retrieveToken_1 = function () {
if (!currentToken) {
return Promise.reject('Not logged in. Please call `login()` to retrieve a token.');
}
},
token: function () {
//TODO
return undefined;
},
};
if (!currentToken.expired()) {
return Promise.resolve(currentToken.accessToken);
}
return currentToken.refresh().then(function (refreshedToken) {
currentToken = refreshedToken;
return currentToken.accessToken;
});
};
return {
login: function () {
window.location.href = client.code.getUri();
},
logout: function () {
currentToken = undefined;
},
extendHeaders: function (req) {
if (!restrict) {
req.setHeaders(retrieveToken_1().then(function (token) { return token && { Authorization: "Bearer " + token }; }, function () { return undefined; }));
}
},
token: retrieveToken_1,
};
}
else {
client.token.getToken(location.href).then(function (token) {
var opener = window.opener;
if (opener && typeof opener[callbackName] === 'function') {
opener[callbackName](token);
window.close();
}
currentToken = token;
}, function () { });
var retrieveToken_2 = function () {
if (!currentToken) {
return Promise.reject('Not logged in. Please call `login()` to retrieve a token.');
}
if (!currentToken.expired()) {
return Promise.resolve(currentToken.accessToken);
}
return new Promise(function (res) {
window[callbackName] = function (token) {
currentToken = token;
res(currentToken.accessToken);
};
window.open(client.token.getUri());
});
};
return {
login: function () {
window.location.href = client.token.getUri();
},
logout: function () {
currentToken = undefined;
},
extendHeaders: function (req) {
if (!restrict) {
req.setHeaders(retrieveToken_2().then(function (token) { return token && { Authorization: "Bearer " + token }; }, function () { return undefined; }));
}
},
token: retrieveToken_2,
};
}
}
exports.setupOAuth2Client = setupOAuth2Client;
//# sourceMappingURL=setup.js.map
{
"name": "piral-oauth2",
"version": "0.11.1-pre.1050",
"version": "0.11.1-pre.1053",
"description": "Plugin to integrate OAuth 2.0 authentication in Piral.",

@@ -41,4 +41,7 @@ "keywords": [

},
"dependencies": {
"client-oauth2": "^4.2.5"
},
"devDependencies": {
"piral-core": "^0.11.1-pre.1050"
"piral-core": "^0.11.1-pre.1053"
},

@@ -48,3 +51,3 @@ "peerDependencies": {

},
"gitHead": "7dfdde4ea9e8e9469ecbbba473b6a0d1f214e001"
"gitHead": "02c384db2162e9ecdf276492fce3c47457e2dc7c"
}

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

import * as ClientOAuth2 from 'client-oauth2';
/**

@@ -6,2 +8,31 @@ * Available configuration options for the OAuth 2.0 plugin.

/**
* The id of the client. Required for the setup of OAuth 2.0.
*/
clientId: string;
/**
* The client secret. Only required for the `code` flow.
*/
clientSecret?: string;
/**
* The Uri pointing to the authorization endpoint of the Identity Provider.
*/
authorizationUri: string;
/**
* The Uri pointing to the access token endpoint of the Identity Provider.
*/
accessTokenUri?: string;
/**
* The redirect Uri to use. By default the origin with /auth
* is used.
*/
redirectUri?: string;
/**
* The scopes to be used.
*/
scopes?: Array<string>;
/**
* The OAuth 2.0 authorization flow type to be used.
*/
flow?: 'implicit' | 'code';
/**
* Restricts token sharing such that other integrations, e.g., with

@@ -32,6 +63,2 @@ * fetch would need to be done manually.

/**
* Retrieves the current account.
*/
account(): Account;
/**
* Gets a token.

@@ -46,30 +73,120 @@ */

const callbackName = 'oauth2Cb';
/**
* Sets up a new client wrapping the oauth2 API.
* Sets up a new client wrapping the OAuth 2.0 API.
* @param config The configuration for the client.
*/
export function setupOAuth2Client(config: OAuth2Config): OAuth2Client {
const { restrict = false } = config;
return {
login() {
//TODO
},
logout() {
//TODO
},
account() {
//TODO
return undefined;
},
extendHeaders(req) {
if (!restrict) {
//TODO
req.setHeaders(undefined);
const {
clientId,
clientSecret,
authorizationUri,
accessTokenUri,
redirectUri = `${location.origin}/auth`,
scopes = [],
flow,
restrict = false,
} = config;
const client = new ClientOAuth2({
clientId,
clientSecret,
redirectUri,
authorizationUri,
accessTokenUri,
scopes,
});
let currentToken: ClientOAuth2.Token;
if (flow === 'code') {
client.code.getToken(location.href).then(
token => (currentToken = token),
() => {},
);
const retrieveToken = () => {
if (!currentToken) {
return Promise.reject('Not logged in. Please call `login()` to retrieve a token.');
}
},
token() {
//TODO
return undefined;
},
};
if (!currentToken.expired()) {
return Promise.resolve(currentToken.accessToken);
}
return currentToken.refresh().then(refreshedToken => {
currentToken = refreshedToken;
return currentToken.accessToken;
});
};
return {
login() {
window.location.href = client.code.getUri();
},
logout() {
currentToken = undefined;
},
extendHeaders(req) {
if (!restrict) {
req.setHeaders(
retrieveToken().then(
token => token && { Authorization: `Bearer ${token}` },
() => undefined,
),
);
}
},
token: retrieveToken,
};
} else {
client.token.getToken(location.href).then(
token => {
const opener = window.opener;
if (opener && typeof opener[callbackName] === 'function') {
opener[callbackName](token);
window.close();
}
currentToken = token;
},
() => {},
);
const retrieveToken = () => {
if (!currentToken) {
return Promise.reject('Not logged in. Please call `login()` to retrieve a token.');
}
if (!currentToken.expired()) {
return Promise.resolve(currentToken.accessToken);
}
return new Promise<string>(res => {
window[callbackName] = (token: ClientOAuth2.Token) => {
currentToken = token;
res(currentToken.accessToken);
};
window.open(client.token.getUri());
});
};
return {
login() {
window.location.href = client.token.getUri();
},
logout() {
currentToken = undefined;
},
extendHeaders(req) {
if (!restrict) {
req.setHeaders(
retrieveToken().then(
token => token && { Authorization: `Bearer ${token}` },
() => undefined,
),
);
}
},
token: retrieveToken,
};
}
}

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