@aoberoi/passport-slack
Advanced tools
Comparing version 2.0.0-beta.5 to 2.0.0-beta.6
@@ -36,3 +36,3 @@ /// <reference types="node" /> | ||
*/ | ||
skipUserProfile?: boolean; | ||
skipUserProfile?: boolean | ((accessToken: string, callback: (err: Error | null | undefined, skip: boolean) => void) => void); | ||
/** | ||
@@ -43,6 +43,2 @@ * A dictionary of HTTP header names and values to be used in all requests made to the Slack API from this Strategy. | ||
/** | ||
* The name for this strategy within passport. Defaults to `slack`. | ||
*/ | ||
name?: string; | ||
/** | ||
* Whether or not the `verify` callback should be called with the incoming HTTP request as its first argument. | ||
@@ -181,3 +177,3 @@ * Defaults to false. | ||
*/ | ||
userProfile(accessToken: string, done: (err?: Error | null, profile?: UsersIdentityResponse) => void): void; | ||
userProfile(accessToken: any, done: (err?: Error | null, profile?: UsersIdentityResponse) => void): void; | ||
/** | ||
@@ -184,0 +180,0 @@ * Return extra parameters to be included in the authorization request. `state` and `redirect_url` are handled by |
@@ -32,3 +32,2 @@ "use strict"; | ||
profileURL: 'https://slack.com/api/users.identity', | ||
name: 'slack', | ||
// Apply a default since the wrapVerify behavior depends on resolving this option | ||
@@ -55,4 +54,4 @@ passReqToCallback: false, | ||
const overrideOptions = { passReqToCallback: true }; | ||
super(Object.assign({}, resolvedOptions, overrideOptions), wrapVerify(verify, resolvedOptions.passReqToCallback)); | ||
this.name = resolvedOptions.name; | ||
super(Object.assign({}, resolvedOptions, overrideOptions), wrapVerify(verify, resolvedOptions.passReqToCallback, resolvedOptions.skipUserProfile)); | ||
this.name = 'slack'; | ||
this.slack = { | ||
@@ -67,13 +66,16 @@ profileURL: resolvedOptions.profileURL, | ||
userProfile(accessToken, done) { | ||
needle_1.default.request('get', this.slack.profileURL, { token: accessToken }, (error, _res, body) => { | ||
if (error) { | ||
done(error); | ||
needle_1.default('get', this.slack.profileURL, { token: accessToken }) | ||
.then(({ body }) => { | ||
if (!body.ok) { | ||
// Check for an error related to the X-Slack-User header missing | ||
if (body.error === 'user_not_specified') { | ||
done(null, undefined); | ||
} | ||
else { | ||
throw new Error(body.error); | ||
} | ||
} | ||
else if (!body.ok) { | ||
done(new Error(body.error)); | ||
} | ||
else { | ||
done(null, body); | ||
} | ||
}); | ||
done(null, body); | ||
}) | ||
.catch(done); | ||
} | ||
@@ -98,5 +100,8 @@ /** | ||
*/ | ||
function wrapVerify(verify, passReqToCallback) { | ||
function wrapVerify(verify, passReqToCallback, _skipUserProfile) { | ||
return function _verify(req, accessToken, refreshToken, results, // TODO: define some types for the oauth.access response shapes | ||
profile, verified) { | ||
// TODO: If the profile is undefined, but the skipUserProfile option says there should be a profile, it may have | ||
// been skipped because there was no user ID available to use for the X-Slack-User header. We can attempt to | ||
// retrieve it now. | ||
const info = { | ||
@@ -103,0 +108,0 @@ access_token: accessToken, |
{ | ||
"name": "@aoberoi/passport-slack", | ||
"version": "2.0.0-beta.5", | ||
"version": "2.0.0-beta.6", | ||
"description": "Slack authentication strategy for Passport", | ||
@@ -5,0 +5,0 @@ "main": "dist/strategy.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29162
371