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

@fusion.io/authenticate-gateways

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fusion.io/authenticate-gateways - npm Package Compare versions

Comparing version 2.5.0-rc18 to 2.5.0-rc19

24

lib/gateways/facebook.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -12,9 +20,11 @@ const authenticate_1 = require("@fusion.io/authenticate");

}
async provide({ access_token }) {
const response = await protocols_1.callAPI({
url: `https://graph.facebook.com/v${this.graphAPIVersion}/me`,
qs: { access_token },
json: true
provide({ access_token }) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield protocols_1.callAPI({
url: `https://graph.facebook.com/v${this.graphAPIVersion}/me`,
qs: { access_token },
json: true
});
return { access_token, profile: response.body };
});
return { access_token, profile: response.body };
}

@@ -26,3 +36,3 @@ }

}
options = { ...options, host: 'https://graph.facebook.com', path: '/oauth/authorize' };
options = Object.assign({}, options, { host: 'https://graph.facebook.com', path: '/oauth/authorize' });
const protocol = 'express' === framework ? new protocols_1.ExpressOAuth2(options) : new protocols_1.KoaOAuth2(options);

@@ -29,0 +39,0 @@ const identityProvider = new authenticate_1.IdentityProviderChain([

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -12,11 +20,13 @@ const authenticate_1 = require("@fusion.io/authenticate");

}
async provide({ access_token }) {
let profile = await protocols_1.callAPI({
url: 'https://api.github.com/user',
qs: { access_token },
headers: {
'user-agent': this.ua
}
provide({ access_token }) {
return __awaiter(this, void 0, void 0, function* () {
let profile = yield protocols_1.callAPI({
url: 'https://api.github.com/user',
qs: { access_token },
headers: {
'user-agent': this.ua
}
});
return { access_token, profile };
});
return { access_token, profile };
}

@@ -28,3 +38,3 @@ }

}
options = { ...options, host: 'https://github.com/login' };
options = Object.assign({}, options, { host: 'https://github.com/login' });
const Protocol = 'express' === framework ? protocols_1.ExpressOAuth2 : protocols_1.KoaOAuth2;

@@ -31,0 +41,0 @@ const protocol = new Protocol(options);

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -16,10 +24,12 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

}
async provide({ access_token, id_token }) {
try {
const profile = jsonwebtoken_1.default.decode(id_token, this.clientSecret);
return { access_token, id_token, profile };
}
catch (error) {
throw new authenticate_1.UnAuthenticated(`Invalid id token. Reason: ${error.message}`);
}
provide({ access_token, id_token }) {
return __awaiter(this, void 0, void 0, function* () {
try {
const profile = jsonwebtoken_1.default.decode(id_token, this.clientSecret);
return { access_token, id_token, profile };
}
catch (error) {
throw new authenticate_1.UnAuthenticated(`Invalid id token. Reason: ${error.message}`);
}
});
}

@@ -31,3 +41,3 @@ }

}
options = { ...options, tokenPath: 'https://oauth2.googleapis.com/token', host: 'https://accounts.google.com', path: '/o/oauth2/v2/auth' };
options = Object.assign({}, options, { tokenPath: 'https://oauth2.googleapis.com/token', host: 'https://accounts.google.com', path: '/o/oauth2/v2/auth' });
const Protocol = 'express' === framework ? protocols_1.ExpressOAuth2 : protocols_1.KoaOAuth2;

@@ -34,0 +44,0 @@ const protocol = new Protocol(options);

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -9,4 +17,6 @@ const authenticate_1 = require("@fusion.io/authenticate");

class InstagramIDP {
async provide({ access_token, user }) {
return { access_token, profile: user };
provide({ access_token, user }) {
return __awaiter(this, void 0, void 0, function* () {
return { access_token, profile: user };
});
}

@@ -18,3 +28,3 @@ }

}
options = { ...options, host: 'https://api.instagram.com', path: '/oauth/authorize' };
options = Object.assign({}, options, { host: 'https://api.instagram.com', path: '/oauth/authorize' });
const Protocol = 'express' === framework ? protocols_1.ExpressOAuth2 : protocols_1.KoaOAuth2;

@@ -21,0 +31,0 @@ const protocol = new Protocol(options);

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -18,10 +26,12 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

}
async provide({ token }) {
try {
const payload = await verifyJWT(token, this.privateKey);
return { token, payload };
}
catch (e) {
throw new authenticate_1.UnAuthenticated(`JWT Signature invalid. Reason: ${e}`);
}
provide({ token }) {
return __awaiter(this, void 0, void 0, function* () {
try {
const payload = yield verifyJWT(token, this.privateKey);
return { token, payload };
}
catch (e) {
throw new authenticate_1.UnAuthenticated(`JWT Signature invalid. Reason: ${e}`);
}
});
}

@@ -28,0 +38,0 @@ }

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -9,4 +17,6 @@ const authenticate_1 = require("@fusion.io/authenticate");

class SlackIDP {
async provide({ access_token, user, team }) {
return { access_token, profile: user, team };
provide({ access_token, user, team }) {
return __awaiter(this, void 0, void 0, function* () {
return { access_token, profile: user, team };
});
}

@@ -18,8 +28,3 @@ }

}
options = {
...options,
host: 'https://slack.com',
path: '/oauth/authorize',
tokenPath: 'https://slack.com/api/oauth.access'
};
options = Object.assign({}, options, { host: 'https://slack.com', path: '/oauth/authorize', tokenPath: 'https://slack.com/api/oauth.access' });
const Protocol = 'express' === framework ? protocols_1.ExpressOAuth2 : protocols_1.KoaOAuth2;

@@ -26,0 +31,0 @@ const protocol = new Protocol(options);

@@ -8,3 +8,3 @@ "use strict";

return (request, response, next) => {
consumer({ ...request.body, context: 'http', httpContext: { request, response } })
consumer(Object.assign({}, request.body, { context: 'http', httpContext: { request, response } }))
.then(identity => {

@@ -29,7 +29,3 @@ request.identity = identity;

mount(consumer) {
return (ctx, next) => consumer({
...ctx.request.body,
context: 'http',
httpContext: ctx
}).then(identity => {
return (ctx, next) => consumer(Object.assign({}, ctx.request.body, { context: 'http', httpContext: ctx })).then(identity => {
ctx.identity = identity;

@@ -50,7 +46,3 @@ return next();

mount(consumer) {
return (socket, next) => consumer({
context: 'socket',
...socket.handshake.query,
socketContext: socket
}).then(identity => {
return (socket, next) => consumer(Object.assign({ context: 'socket' }, socket.handshake.query, { socketContext: socket })).then(identity => {
socket.identity = identity;

@@ -57,0 +49,0 @@ next();

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -8,14 +16,16 @@ const authenticate_1 = require("@fusion.io/authenticate");

}
async resolve(context) {
const usernameField = this.options['usernameField'] || 'username';
const passwordField = this.options['passwordField'] || 'password';
const username = context[usernameField];
const password = context[passwordField];
if (!username) {
throw new authenticate_1.UnAuthenticated("Username is required");
}
if (!password) {
throw new authenticate_1.UnAuthenticated("Password is required");
}
return { username, password };
resolve(context) {
return __awaiter(this, void 0, void 0, function* () {
const usernameField = this.options['usernameField'] || 'username';
const passwordField = this.options['passwordField'] || 'password';
const username = context[usernameField];
const password = context[passwordField];
if (!username) {
throw new authenticate_1.UnAuthenticated("Username is required");
}
if (!password) {
throw new authenticate_1.UnAuthenticated("Password is required");
}
return { username, password };
});
}

@@ -22,0 +32,0 @@ }

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -22,7 +30,11 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

}
async makeState() {
return this.state;
makeState() {
return __awaiter(this, void 0, void 0, function* () {
return this.state;
});
}
async verify(stateFromOAuth2Server) {
return stateFromOAuth2Server === this.state.toString();
verify(stateFromOAuth2Server) {
return __awaiter(this, void 0, void 0, function* () {
return stateFromOAuth2Server === this.state.toString();
});
}

@@ -63,24 +75,26 @@ }

*/
async redirectToAuthorizeEndpoint({ httpContext: { response } }) {
let { host, path, clientId, redirectUri, scope } = this.options;
const qs = {
response_type: 'code',
client_id: clientId,
redirect_uri: redirectUri
};
if (scope) {
qs['scope'] = scope instanceof Array ? scope.join(',') : scope;
}
// If the state is configured. We'll ask the verifier make a state for us.
if (this.stateVerifier) {
qs['state'] = await this.stateVerifier.makeState();
}
if (!path) {
path = '/oauth2/authorize';
}
const authorizeUri = `${host}${path}?${querystring_1.default.stringify(qs)}`;
response.redirect(authorizeUri);
// After we redirect. We'll abort this authentication context.
// The actual authentication is the resolveAccessToken.
throw new authenticate_1.Aborted("Aborted");
redirectToAuthorizeEndpoint({ httpContext: { response } }) {
return __awaiter(this, void 0, void 0, function* () {
let { host, path, clientId, redirectUri, scope } = this.options;
const qs = {
response_type: 'code',
client_id: clientId,
redirect_uri: redirectUri
};
if (scope) {
qs['scope'] = scope instanceof Array ? scope.join(',') : scope;
}
// If the state is configured. We'll ask the verifier make a state for us.
if (this.stateVerifier) {
qs['state'] = yield this.stateVerifier.makeState();
}
if (!path) {
path = '/oauth2/authorize';
}
const authorizeUri = `${host}${path}?${querystring_1.default.stringify(qs)}`;
response.redirect(authorizeUri);
// After we redirect. We'll abort this authentication context.
// The actual authentication is the resolveAccessToken.
throw new authenticate_1.Aborted("Aborted");
});
}

@@ -93,29 +107,31 @@ /**

*/
async resolveAccessToken({ httpContext: { request } }) {
const code = request.query['code'];
// If the state is configured. We'll ask the verifier to verify if the state
// is the actual one it sent before.
if (this.stateVerifier && !await this.stateVerifier.verify(request.query['state'])) {
throw new authenticate_1.UnAuthenticated(`OAuth2 state [${request.query['state']}] is invalid`);
}
const form = {
client_id: this.options.clientId,
client_secret: this.options.clientSecret,
redirect_uri: this.options.redirectUri,
code,
grant_type: 'authorization_code'
};
const tokenPath = this.options['tokenPath'] || `${this.options.host}/oauth/access_token`;
// @ts-ignore
const response = await callAPI({
url: tokenPath,
method: 'POST',
form,
json: true
resolveAccessToken({ httpContext: { request } }) {
return __awaiter(this, void 0, void 0, function* () {
const code = request.query['code'];
// If the state is configured. We'll ask the verifier to verify if the state
// is the actual one it sent before.
if (this.stateVerifier && !(yield this.stateVerifier.verify(request.query['state']))) {
throw new authenticate_1.UnAuthenticated(`OAuth2 state [${request.query['state']}] is invalid`);
}
const form = {
client_id: this.options.clientId,
client_secret: this.options.clientSecret,
redirect_uri: this.options.redirectUri,
code,
grant_type: 'authorization_code'
};
const tokenPath = this.options['tokenPath'] || `${this.options.host}/oauth/access_token`;
// @ts-ignore
const response = yield callAPI({
url: tokenPath,
method: 'POST',
form,
json: true
});
const responseAsJson = response.toJSON();
if (response.statusCode >= 300) {
throw new authenticate_1.UnAuthenticated(`OAuth2 Server Error. Response from server: ${JSON.stringify(responseAsJson.body)}`);
}
return responseAsJson.body;
});
const responseAsJson = response.toJSON();
if (response.statusCode >= 300) {
throw new authenticate_1.UnAuthenticated(`OAuth2 Server Error. Response from server: ${JSON.stringify(responseAsJson.body)}`);
}
return responseAsJson.body;
}

@@ -127,10 +143,12 @@ /**

*/
async resolve(context) {
return context.httpContext.request.query['code'] ?
// If there was a code. We'll exchange it to get the
// access_token.
await this.resolveAccessToken(context) :
// If no code in the query string. We'll redirect to the OAuth2 server
// to get one.
await this.redirectToAuthorizeEndpoint(context);
resolve(context) {
return __awaiter(this, void 0, void 0, function* () {
return context.httpContext.request.query['code'] ?
// If there was a code. We'll exchange it to get the
// access_token.
yield this.resolveAccessToken(context) :
// If no code in the query string. We'll redirect to the OAuth2 server
// to get one.
yield this.redirectToAuthorizeEndpoint(context);
});
}

@@ -137,0 +155,0 @@ }

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -11,11 +19,13 @@ const authenticate_1 = require("@fusion.io/authenticate");

}
async resolve({ session, httpContext: { request } }) {
session = session || request.session;
if (!session) {
throw new Error("Session is not started");
}
if (!session[this.sessionKey]) {
throw new authenticate_1.UnAuthenticated("UnAuthenticated");
}
return session[this.sessionKey];
resolve({ session, httpContext: { request } }) {
return __awaiter(this, void 0, void 0, function* () {
session = session || request.session;
if (!session) {
throw new Error("Session is not started");
}
if (!session[this.sessionKey]) {
throw new authenticate_1.UnAuthenticated("UnAuthenticated");
}
return session[this.sessionKey];
});
}

@@ -22,0 +32,0 @@ }

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -14,17 +22,19 @@ const authenticate_1 = require("@fusion.io/authenticate");

*/
async resolve({ httpContext: { request } }) {
if (request.headers['authorization']) {
let bearer = request.headers['authorization'];
if (!bearer.startsWith('bearer ')) {
throw new authenticate_1.UnAuthenticated("No token provided");
resolve({ httpContext: { request } }) {
return __awaiter(this, void 0, void 0, function* () {
if (request.headers['authorization']) {
let bearer = request.headers['authorization'];
if (!bearer.startsWith('bearer ')) {
throw new authenticate_1.UnAuthenticated("No token provided");
}
return { token: bearer.replace('bearer ', '') };
}
return { token: bearer.replace('bearer ', '') };
}
if (request.query['token']) {
return { token: request.query['token'] };
}
if (request.body && request.body['token']) {
return { token: request.body['token'] };
}
throw new authenticate_1.UnAuthenticated("No token provided");
if (request.query['token']) {
return { token: request.query['token'] };
}
if (request.body && request.body['token']) {
return { token: request.body['token'] };
}
throw new authenticate_1.UnAuthenticated("No token provided");
});
}

@@ -31,0 +41,0 @@ }

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -24,7 +32,9 @@ const authenticate_1 = require("@fusion.io/authenticate");

}
async resolve({ socket: { handshake } }) {
if (!handshake.query.token) {
throw new authenticate_1.UnAuthenticated("No token provided");
}
return { token: handshake.query.token };
resolve({ socket: { handshake } }) {
return __awaiter(this, void 0, void 0, function* () {
if (!handshake.query.token) {
throw new authenticate_1.UnAuthenticated("No token provided");
}
return { token: handshake.query.token };
});
}

@@ -31,0 +41,0 @@ }

{
"name": "@fusion.io/authenticate-gateways",
"version": "2.5.0-rc18",
"version": "2.5.0-rc19",
"description": "Better gateways for better authentication for the Geeks, by the Geeks",

@@ -31,5 +31,5 @@ "author": "rikky <son.levuthai@gmail.com>",

"dependencies": {
"@fusion.io/authenticate": "^2.5.0-rc18"
"@fusion.io/authenticate": "^2.5.0-rc19"
},
"gitHead": "62fa7ea795c9146fb5018e730a3ee722a6f1ed73"
"gitHead": "3e1ae4c3091f8fad7b4024725e8a362ea6232211"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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