From 3daf34ccfad8b25b4931eb26e21ff08d6f1cd054 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 17 Sep 2020 14:44:49 +0000 Subject: [PATCH] implemented missed methods --- dist/index.js | 2 +- dist/index.js.map | 2 +- dist/twitch-strategy.d.ts | 2 ++ src/twitch-strategy.ts | 5 +++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index e0c0594..672bcdc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("node-fetch"),e=require("passport-oauth2"),r=require("pkginfo");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=o(t),a=o(e),n=o(r);class u extends a.default{constructor(t,e){super(Object.assign(Object.assign({},t),{authorizationURL:"https://id.twitch.tv/oauth2/authorize",tokenURL:"https://id.twitch.tv/oauth2/token"}),e),this.name="twitch",this.clientID=t.clientID,this._oauth2.setAuthMethod("Bearer"),this._oauth2.useAuthorizationHeaderforGET(!0)}userProfile(t,e){return i.default("https://api.twitch.tv/helix/users",{method:"GET",headers:{"Client-ID":this.clientID,Accept:"application/vnd.twitchtv.v5+json",Authorization:"Bearer "+t}}).then(t=>{if(t.ok)return t.json();throw new a.default.InternalOAuthError("failed to fetch user profile",t)}).then(t=>{const r=t.data[0];return e(null,r)}).catch(t=>e(t,null))}authorizationParams(t){return{force_verify:"boolean"==typeof t.forceVerify&&t.forceVerify}}}n.default(module,"version");const s=u;exports.OAuth2Strategy=s,exports.Strategy=u; +"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("node-fetch"),e=require("passport-oauth2"),r=require("pkginfo");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=o(t),a=o(e),n=o(r);class u extends a.default{constructor(t,e){super(Object.assign(Object.assign({},t),{authorizationURL:"https://id.twitch.tv/oauth2/authorize",tokenURL:"https://id.twitch.tv/oauth2/token"}),e),this.name="twitch",this.clientID=t.clientID,this._oauth2.setAuthMethod("Bearer"),this._oauth2.useAuthorizationHeaderforGET(!0)}userProfile(t,e){return i.default("https://api.twitch.tv/helix/users",{method:"GET",headers:{"Client-ID":this.clientID,Accept:"application/vnd.twitchtv.v5+json",Authorization:"Bearer "+t}}).then(t=>{if(t.ok)return t.json();throw new a.default.InternalOAuthError("failed to fetch user profile",t)}).then(t=>{const r=t.data[0];return e(null,r)}).catch(t=>e(t,null))}authenticate(t,e){super.authenticate(t,e)}authorizationParams(t){return{force_verify:"boolean"==typeof t.forceVerify&&t.forceVerify}}}n.default(module,"version");const s=u;exports.OAuth2Strategy=s,exports.Strategy=u; //# sourceMappingURL=index.js.map diff --git a/dist/index.js.map b/dist/index.js.map index e7247fd..94defb7 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["../src/twitch-strategy.ts","../src/index.ts"],"sourcesContent":["import fetch from \"node-fetch\";\r\nimport OAuth2Strategy from \"passport-oauth2\";\r\n\r\ninterface Options {\r\n clientID: string;\r\n clientSecret: string;\r\n callbackURL: string;\r\n scope: string;\r\n}\r\n\r\nexport class Strategy extends OAuth2Strategy {\r\n private clientID: string;\r\n public name: string;\r\n /**\r\n * `Strategy` constructor.\r\n *\r\n * The Twitch authentication strategy authenticates requests by delegating to\r\n * Twitch using the OAuth 2.0 protocol.\r\n *\r\n * Applications must supply a `verify` callback which accepts an `accessToken`,\r\n * `refreshToken` and service-specific `profile`, and then calls the `done`\r\n * callback supplying a `user`, which should be set to `false` if the\r\n * credentials are not valid. If an exception occured, `err` should be set.\r\n *\r\n * Options:\r\n * - `clientID` your Twitch application\"s client id\r\n * - `clientSecret` your Twitch application\"s client secret\r\n * - `callbackURL` URL to which Twitch will redirect the user after granting authorization\r\n *\r\n * Examples:\r\n *\r\n * passport.use(new TwitchStrategy({\r\n * clientID: \"123-456-789\",\r\n * clientSecret: \"shhh-its-a-secret\"\r\n * callbackURL: \"https://www.example.net/auth/twitch/callback\"\r\n * },\r\n * function(accessToken, refreshToken, profile, done) {\r\n * User.findOrCreate(..., function (err, user) {\r\n * done(err, user);\r\n * });\r\n * }\r\n * ));\r\n *\r\n * @param {Options} options\r\n * @param {Function} verify\r\n */\r\n constructor(options: Options, verify: Function) {\r\n const params: OAuth2Strategy._StrategyOptionsBase = {\r\n ...options,\r\n authorizationURL: 'https://id.twitch.tv/oauth2/authorize',\r\n tokenURL: 'https://id.twitch.tv/oauth2/token'\r\n }\r\n super(params, verify as OAuth2Strategy.VerifyFunction | OAuth2Strategy.VerifyFunctionWithRequest);\r\n this.name = 'twitch';\r\n this.clientID = options.clientID;\r\n this._oauth2.setAuthMethod('Bearer');\r\n this._oauth2.useAuthorizationHeaderforGET(true);\r\n }\r\n\r\n /**\r\n * Retrieve user profile from Twitch.\r\n * This function constructs a normalized profile, with the following properties:\r\n * - `provider` always set to `twitch`\r\n * - `id`\r\n * - `username`\r\n * - `displayName`\r\n * @param {String} accessToken\r\n * @param {Function} done\r\n * @api protected\r\n */\r\n userProfile(accessToken: string, done: (err?: Error | null, profile?: any) => void) {\r\n return fetch('https://api.twitch.tv/helix/users', {\r\n method: 'GET',\r\n headers: {\r\n 'Client-ID': this.clientID,\r\n 'Accept': 'application/vnd.twitchtv.v5+json',\r\n 'Authorization': 'Bearer ' + accessToken\r\n }\r\n }).then(response => {\r\n if (!response.ok) throw new OAuth2Strategy.InternalOAuthError(\"failed to fetch user profile\", response);\r\n else return response.json();\r\n }).then(json => {\r\n const body = json.data[0];\r\n return done(null, body);\r\n }).catch(error => {\r\n return done(error, null);\r\n });\r\n }\r\n\r\n /**\r\n * Return extra parameters to be included in the authorization request.\r\n * @param {{ forceVerify?: boolean }} options\r\n * @return {Object}\r\n * @api protected\r\n */\r\n authorizationParams(options: { forceVerify?: boolean }): object {\r\n return {\r\n force_verify: (typeof options.forceVerify !== 'boolean') ? false : options.forceVerify\r\n };\r\n }\r\n}\r\n\r\nexport default Strategy;","import { Strategy } from './twitch-strategy';\r\nimport pkginfo from 'pkginfo';\r\n\r\npkginfo(module, \"version\");\r\n\r\nconst OAuth2Strategy = Strategy;\r\nexport { Strategy, OAuth2Strategy };"],"names":["Strategy","OAuth2Strategy","[object Object]","options","verify","super","authorizationURL","tokenURL","this","name","clientID","_oauth2","setAuthMethod","useAuthorizationHeaderforGET","accessToken","done","fetch","method","headers","Client-ID","Accept","Authorization","then","response","ok","json","InternalOAuthError","body","data","catch","error","force_verify","forceVerify","pkginfo","module"],"mappings":"yPAUaA,UAAiBC,UAoC1BC,YAAYC,EAAkBC,GAM1BC,qCAJOF,IACHG,iBAAkB,wCAClBC,SAAU,sCAEAH,GACdI,KAAKC,KAAO,SACZD,KAAKE,SAAWP,EAAQO,SACxBF,KAAKG,QAAQC,cAAc,UAC3BJ,KAAKG,QAAQE,8BAA6B,GAc9CX,YAAYY,EAAqBC,GAC7B,OAAOC,UAAM,oCAAqC,CAC9CC,OAAQ,MACRC,QAAS,CACLC,YAAaX,KAAKE,SAClBU,OAAU,mCACVC,cAAiB,UAAYP,KAElCQ,KAAKC,IACJ,GAAKA,EAASC,GACT,OAAOD,EAASE,OADH,MAAM,IAAIxB,UAAeyB,mBAAmB,+BAAgCH,KAE/FD,KAAKG,IACJ,MAAME,EAAOF,EAAKG,KAAK,GACvB,OAAOb,EAAK,KAAMY,KACnBE,MAAMC,GACEf,EAAKe,EAAO,OAU3B5B,oBAAoBC,GAChB,MAAO,CACH4B,aAA8C,kBAAxB5B,EAAQ6B,aAAqC7B,EAAQ6B,cC9FvFC,UAAQC,OAAQ,iBAEVjC,EAAiBD"} \ No newline at end of file +{"version":3,"file":"index.js","sources":["../src/twitch-strategy.ts","../src/index.ts"],"sourcesContent":["import { Request } from \"express\";\nimport fetch from \"node-fetch\";\nimport OAuth2Strategy from \"passport-oauth2\";\n\ninterface Options {\n clientID: string;\n clientSecret: string;\n callbackURL: string;\n scope: string;\n}\n\nexport class Strategy extends OAuth2Strategy {\n private clientID: string;\n public name: string;\n /**\n * `Strategy` constructor.\n *\n * The Twitch authentication strategy authenticates requests by delegating to\n * Twitch using the OAuth 2.0 protocol.\n *\n * Applications must supply a `verify` callback which accepts an `accessToken`,\n * `refreshToken` and service-specific `profile`, and then calls the `done`\n * callback supplying a `user`, which should be set to `false` if the\n * credentials are not valid. If an exception occured, `err` should be set.\n *\n * Options:\n * - `clientID` your Twitch application\"s client id\n * - `clientSecret` your Twitch application\"s client secret\n * - `callbackURL` URL to which Twitch will redirect the user after granting authorization\n *\n * Examples:\n *\n * passport.use(new TwitchStrategy({\n * clientID: \"123-456-789\",\n * clientSecret: \"shhh-its-a-secret\"\n * callbackURL: \"https://www.example.net/auth/twitch/callback\"\n * },\n * function(accessToken, refreshToken, profile, done) {\n * User.findOrCreate(..., function (err, user) {\n * done(err, user);\n * });\n * }\n * ));\n *\n * @param {Options} options\n * @param {Function} verify\n */\n constructor(options: Options, verify: Function) {\n const params: OAuth2Strategy._StrategyOptionsBase = {\n ...options,\n authorizationURL: 'https://id.twitch.tv/oauth2/authorize',\n tokenURL: 'https://id.twitch.tv/oauth2/token'\n }\n super(params, verify as OAuth2Strategy.VerifyFunction | OAuth2Strategy.VerifyFunctionWithRequest);\n this.name = 'twitch';\n this.clientID = options.clientID;\n this._oauth2.setAuthMethod('Bearer');\n this._oauth2.useAuthorizationHeaderforGET(true);\n }\n\n /**\n * Retrieve user profile from Twitch.\n * This function constructs a normalized profile, with the following properties:\n * - `provider` always set to `twitch`\n * - `id`\n * - `username`\n * - `displayName`\n * @param {String} accessToken\n * @param {Function} done\n * @api protected\n */\n userProfile(accessToken: string, done: (err?: Error | null, profile?: any) => void) {\n return fetch('https://api.twitch.tv/helix/users', {\n method: 'GET',\n headers: {\n 'Client-ID': this.clientID,\n 'Accept': 'application/vnd.twitchtv.v5+json',\n 'Authorization': 'Bearer ' + accessToken\n }\n }).then(response => {\n if (!response.ok) throw new OAuth2Strategy.InternalOAuthError(\"failed to fetch user profile\", response);\n else return response.json();\n }).then(json => {\n const body = json.data[0];\n return done(null, body);\n }).catch(error => {\n return done(error, null);\n });\n }\n\n authenticate(req: Request, args?: any): void {\n super.authenticate(req, args);\n }\n\n /**\n * Return extra parameters to be included in the authorization request.\n * @param {{ forceVerify?: boolean }} options\n * @return {Object}\n * @api protected\n */\n authorizationParams(options: { forceVerify?: boolean }): object {\n return {\n force_verify: (typeof options.forceVerify !== 'boolean') ? false : options.forceVerify\n };\n }\n}\n\nexport default Strategy;","import { Strategy } from './twitch-strategy';\nimport pkginfo from 'pkginfo';\n\npkginfo(module, \"version\");\n\nconst OAuth2Strategy = Strategy;\nexport { Strategy, OAuth2Strategy };"],"names":["Strategy","OAuth2Strategy","[object Object]","options","verify","super","authorizationURL","tokenURL","this","name","clientID","_oauth2","setAuthMethod","useAuthorizationHeaderforGET","accessToken","done","fetch","method","headers","Client-ID","Accept","Authorization","then","response","ok","json","InternalOAuthError","body","data","catch","error","req","args","authenticate","force_verify","forceVerify","pkginfo","module"],"mappings":"yPAWaA,UAAiBC,UAoC1BC,YAAYC,EAAkBC,GAM1BC,qCAJOF,IACHG,iBAAkB,wCAClBC,SAAU,sCAEAH,GACdI,KAAKC,KAAO,SACZD,KAAKE,SAAWP,EAAQO,SACxBF,KAAKG,QAAQC,cAAc,UAC3BJ,KAAKG,QAAQE,8BAA6B,GAc9CX,YAAYY,EAAqBC,GAC7B,OAAOC,UAAM,oCAAqC,CAC9CC,OAAQ,MACRC,QAAS,CACLC,YAAaX,KAAKE,SAClBU,OAAU,mCACVC,cAAiB,UAAYP,KAElCQ,KAAKC,IACJ,GAAKA,EAASC,GACT,OAAOD,EAASE,OADH,MAAM,IAAIxB,UAAeyB,mBAAmB,+BAAgCH,KAE/FD,KAAKG,IACJ,MAAME,EAAOF,EAAKG,KAAK,GACvB,OAAOb,EAAK,KAAMY,KACnBE,MAAMC,GACEf,EAAKe,EAAO,OAI3B5B,aAAa6B,EAAcC,GACvB3B,MAAM4B,aAAaF,EAAKC,GAS5B9B,oBAAoBC,GAChB,MAAO,CACH+B,aAA8C,kBAAxB/B,EAAQgC,aAAqChC,EAAQgC,cCnGvFC,UAAQC,OAAQ,iBAEVpC,EAAiBD"} \ No newline at end of file diff --git a/dist/twitch-strategy.d.ts b/dist/twitch-strategy.d.ts index eb3567b..d4214d5 100644 --- a/dist/twitch-strategy.d.ts +++ b/dist/twitch-strategy.d.ts @@ -1,3 +1,4 @@ +import { Request } from "express"; import OAuth2Strategy from "passport-oauth2"; interface Options { clientID: string; @@ -54,6 +55,7 @@ export declare class Strategy extends OAuth2Strategy { * @api protected */ userProfile(accessToken: string, done: (err?: Error | null, profile?: any) => void): Promise; + authenticate(req: Request, args?: any): void; /** * Return extra parameters to be included in the authorization request. * @param {{ forceVerify?: boolean }} options diff --git a/src/twitch-strategy.ts b/src/twitch-strategy.ts index f644c12..05f656a 100644 --- a/src/twitch-strategy.ts +++ b/src/twitch-strategy.ts @@ -1,3 +1,4 @@ +import { Request } from "express"; import fetch from "node-fetch"; import OAuth2Strategy from "passport-oauth2"; @@ -87,6 +88,10 @@ export class Strategy extends OAuth2Strategy { }); } + authenticate(req: Request, args?: any): void { + super.authenticate(req, args); + } + /** * Return extra parameters to be included in the authorization request. * @param {{ forceVerify?: boolean }} options