UNPKG

passport-twitch-strategy

Version:

Twitch (OAuth) authentication strategies for Passport. v5

3 lines (2 loc) 1.18 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("node-fetch"),e=require("passport-oauth2");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var a=r(t),i=r(e);class o extends i.default{constructor(t,e){super({...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 a.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 i.default.InternalOAuthError("failed to fetch user profile",t)}).then(t=>{const r=t.data[0];return r.provider="twitch",r.display_name&&(r.displayName=r.display_name,delete r.display_name),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}}}const n=o;exports.OAuth2Strategy=n,exports.Strategy=o; //# sourceMappingURL=index.js.map