Merge pull request #114 from CrustyJew/master

Reddit UserAgent Option and token fix
This commit is contained in:
Jerrie Pelser
2015-07-18 07:51:52 +07:00
2 changed files with 10 additions and 2 deletions

View File

@@ -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();

View File

@@ -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 : "&lt;AppName&gt; ( by /u/&lt;username&gt; )"
/// </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",