Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to get this library working with Twitch's New API #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/passport-twitch/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function Strategy(options, verify) {
OAuth2Strategy.call(this, options, verify);
this.name = "twitch";

this._oauth2.setAuthMethod("OAuth");
this._oauth2.setAuthMethod("Bearer");
this._oauth2.useAuthorizationHeaderforGET(true);
}

Expand All @@ -72,21 +72,24 @@ util.inherits(Strategy, OAuth2Strategy);
* @api protected
*/
Strategy.prototype.userProfile = function(accessToken, done) {
this._oauth2.get("https://api.twitch.tv/kraken/user", accessToken, function (err, body, res) {
this._oauth2.get("https://api.twitch.tv/helix/users", accessToken, function (err, body, res) {
if (err) { return done(new InternalOAuthError("failed to fetch user profile", err)); }

try {
var json = JSON.parse(body);

var profile = { provider: "twitch" };
profile.id = json._id;
profile.username = json.name;
profile.displayName = json.display_name;
profile.email = json.email;
profile.id = json.data[0].id;
profile.userName = json.data[0].login;
profile.displayName = json.data[0].display_name;
profile.profileImageUrl = json.data[0].profile_image_url;
profile.viewCount = json.data[0].view_count;

profile._raw = body;
profile._json = json;

console.log(json);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this log and merge this PR


done(null, profile);
} catch(e) {
done(e);
Expand All @@ -108,7 +111,6 @@ Strategy.prototype.authorizationParams = function(options) {
}
return params;
};

/**
* Expose `Strategy`.
*/
Expand Down