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

Update Twitch to latest API #259

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ public class TwitchAuthenticatedContext : BaseContext
/// Initializes a <see cref="TwitchAuthenticatedContext"/>
/// </summary>
/// <param name="context">The OWIN environment</param>
/// <param name="user">The JSON-serialized user</param>
/// <param name="users">The JSON-serialized users</param>
/// <param name="accessToken">Twitch Access token</param>
public TwitchAuthenticatedContext(IOwinContext context, JObject user, string accessToken)
public TwitchAuthenticatedContext(IOwinContext context, JObject users, string accessToken)
: base(context)
{
User = user;
User = (JObject) ((JArray) users.GetValue("data")).First;
AccessToken = accessToken;

Id = TryGetValue(user, "_id");
Name = TryGetValue(user, "name");
Link = TryGetValue(user, "url");
UserName = TryGetValue(user, "name");
Email = TryGetValue(user, "email");
Id = TryGetValue(User, "_id");
Name = TryGetValue(User, "name");
Link = TryGetValue(User, "url");
UserName = TryGetValue(User, "name");
Email = TryGetValue(User, "email");
}

/// <summary>
/// Gets the JSON-serialized user
/// </summary>
/// <remarks>
/// Contains the Twitch user obtained from the User Info endpoint. By default this is https://api.Twitch.com/user but it can be
/// Contains the Twitch user obtained from the User Info endpoint. By default this is https://api.twitch.tv/helix/users but it can be
/// overridden in the options
/// </remarks>
public JObject User { get; private set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
var accessToken = (string)response.access_token;

// Get the Twitch user
var userRequest = new HttpRequestMessage(HttpMethod.Get, Options.Endpoints.UserInfoEndpoint + "?oauth_token=" + Uri.EscapeDataString(accessToken));
var userRequest = new HttpRequestMessage(HttpMethod.Get, Options.Endpoints.UserInfoEndpoint);
userRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
userRequest.Headers.Add("Authorization", "Bearer " + accessToken);
var userResponse = await _httpClient.SendAsync(userRequest, Request.CallCancelled);
userResponse.EnsureSuccessStatusCode();
text = await userResponse.Content.ReadAsStringAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ public class TwitchAuthenticationEndpoints
/// Endpoint which is used to redirect users to request Twitch access
/// </summary>
/// <remarks>
/// Defaults to https://api.twitch.tv/kraken/oauth2/authorize
/// Defaults to https://id.twitch.tv/oauth2/authorize
/// </remarks>
public string AuthorizationEndpoint { get; set; }

/// <summary>
/// Endpoint which is used to exchange code for access token
/// </summary>
/// <remarks>
/// Defaults to https://api.twitch.tv/kraken/oauth2/token
/// Defaults to https://id.twitch.tv/oauth2/token
/// </remarks>
public string TokenEndpoint { get; set; }

/// <summary>
/// Endpoint which is used to obtain user information after authentication
/// </summary>
/// <remarks>
/// Defaults to https://api.twitch.tv/kraken/user
/// Defaults to https://api.twitch.tv/helix/users
/// </remarks>
public string UserInfoEndpoint { get; set; }
}

private const string AuthorizationEndPoint = "https://api.twitch.tv/kraken/oauth2/authorize";
private const string TokenEndpoint = "https://api.twitch.tv/kraken/oauth2/token";
private const string UserInfoEndpoint = "https://api.twitch.tv/kraken/user";
private const string AuthorizationEndPoint = "https://id.twitch.tv/oauth2/authorize";
private const string TokenEndpoint = "https://id.twitch.tv/oauth2/token";
private const string UserInfoEndpoint = "https://api.twitch.tv/helix/users";

/// <summary>
/// Gets or sets the a pinned certificate validator to use to validate the endpoints used
Expand Down Expand Up @@ -141,7 +141,7 @@ public TwitchAuthenticationOptions()
AuthenticationMode = AuthenticationMode.Passive;
Scope = new List<string>
{
"user_read"
"user:read:email"
};
BackchannelTimeout = TimeSpan.FromSeconds(60);
Endpoints = new TwitchAuthenticationEndpoints
Expand Down