Merge pull request #114 from CrustyJew/master
Reddit UserAgent Option and token fix
This commit is contained in:
@@ -75,12 +75,13 @@ namespace Owin.Security.Providers.Reddit
|
||||
body.Add(new KeyValuePair<string, string>("state", state));
|
||||
body.Add(new KeyValuePair<string, string>("scope", string.Join(",", Options.Scope)));
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, TokenEndpoint);
|
||||
request.Headers.Add("User-Agent", Options.UserAgent);
|
||||
request.Content = new FormUrlEncodedContent(body);
|
||||
|
||||
// Request the token
|
||||
|
||||
HttpResponseMessage tokenResponse =
|
||||
await httpClient.PostAsync(TokenEndpoint, new FormUrlEncodedContent(body));
|
||||
await httpClient.SendAsync(request);
|
||||
tokenResponse.EnsureSuccessStatusCode();
|
||||
string text = await tokenResponse.Content.ReadAsStringAsync();
|
||||
|
||||
@@ -92,7 +93,7 @@ namespace Owin.Security.Providers.Reddit
|
||||
|
||||
// Get the Reddit user
|
||||
HttpRequestMessage userRequest = new HttpRequestMessage(HttpMethod.Get, UserInfoEndpoint);
|
||||
userRequest.Headers.Add("User-Agent", "OWIN OAuth Provider");
|
||||
userRequest.Headers.Add("User-Agent", Options.UserAgent);
|
||||
userRequest.Headers.Add("Authorization", "bearer " + Uri.EscapeDataString(accessToken) + "");
|
||||
HttpResponseMessage graphResponse = await httpClient.SendAsync(userRequest, Request.CallCancelled);
|
||||
graphResponse.EnsureSuccessStatusCode();
|
||||
|
||||
@@ -84,6 +84,12 @@ namespace Owin.Security.Providers.Reddit
|
||||
/// </summary>
|
||||
public ISecureDataFormat<AuthenticationProperties> StateDataFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the User-Agent string sent with token requests to Reddit.
|
||||
/// Prefered Format is : "<AppName> ( by /u/<username> )"
|
||||
/// </summary>
|
||||
public string UserAgent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="RedditAuthenticationOptions" />
|
||||
/// </summary>
|
||||
@@ -93,6 +99,7 @@ namespace Owin.Security.Providers.Reddit
|
||||
Caption = Constants.DefaultAuthenticationType;
|
||||
CallbackPath = new PathString("/signin-reddit");
|
||||
AuthenticationMode = AuthenticationMode.Passive;
|
||||
UserAgent = "OWIN OAuth Provider";
|
||||
Scope = new List<string>
|
||||
{
|
||||
"identity",
|
||||
|
||||
Reference in New Issue
Block a user