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

- Added the possibility to get the email in the Twitter implementation #118

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion OAuth2/Client/IClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface IClient
/// Callback request payload (parameters).
/// <example>Request.QueryString</example>
/// </param>
UserInfo GetUserInfo(NameValueCollection parameters);
UserInfo GetUserInfo(NameValueCollection parameters, NameValueCollection queryParameters = null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't we use parameters for this? I'm not sure we need to introduce a new field as all the other implementations are passing state when needed already.

Choose a reason for hiding this comment

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

I think is the only form to pass parameters to the QueryUserInfo() method...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please confirm this as configuration is passed through to each oauth implementation. I know extra state parameters can be set on the initial request.

Choose a reason for hiding this comment

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

I think it's only for OAuth1 clients, Twitter specific, but maybe another OAuth1 client needs this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@titarenko do you have any more info on this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you covert this to be a IDictionary<string,string>. It would be nice to not use any super specialized collections.


/// <summary>
/// Client configuration object.
Expand Down
3 changes: 2 additions & 1 deletion OAuth2/Client/Impl/TwitterClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Newtonsoft.Json.Linq;
using OAuth2.Configuration;
using OAuth2.Infrastructure;
Expand Down Expand Up @@ -109,7 +110,7 @@ protected override UserInfo ParseUserInfo(string content)
return new UserInfo
{
Id = response["id"].Value<string>(),
Email = null,
Email = response["email"] == null ? null : response["email"].Value<string>(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be better to call SafeGet to get the string value here so we don't blow up.

FirstName = firstName,
LastName = lastName,
AvatarUri =
Expand Down
4 changes: 3 additions & 1 deletion OAuth2/Client/OAuth2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ public virtual string GetLoginLinkUri(string state = null)
/// Obtains user information using OAuth2 service and data provided via callback request.
/// </summary>
/// <param name="parameters">Callback request payload (parameters).</param>
public UserInfo GetUserInfo(NameValueCollection parameters)
/// <param name="queryParameters">Callback request payload (query parameters).</param>
public UserInfo GetUserInfo(NameValueCollection parameters, NameValueCollection queryParameters = null)
{
queryParameters = queryParameters ?? new NameValueCollection();
GrantType = "authorization_code";
CheckErrorAndSetState(parameters);
QueryAccessToken(parameters);
Expand Down
15 changes: 12 additions & 3 deletions OAuth2/Client/OAuthClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Specialized;
using System.Runtime.InteropServices.ComTypes;
using System.Web;
using OAuth2.Configuration;
using OAuth2.Infrastructure;
Expand Down Expand Up @@ -78,13 +79,16 @@ public string GetLoginLinkUri(string state = null)
/// </summary>
/// <param name="parameters">Callback request payload (parameters).
/// <example>Request.QueryString</example></param>
/// <param name="queryParameters">Callback request payload for query user info (parameters).
/// <example>Request.QueryString</example></param>
/// <returns></returns>
public UserInfo GetUserInfo(NameValueCollection parameters)
public UserInfo GetUserInfo(NameValueCollection parameters, NameValueCollection queryParameters = null)
{
queryParameters = queryParameters ?? new NameValueCollection();
AccessToken = parameters.GetOrThrowUnexpectedResponse(OAuthTokenKey);
QueryAccessToken(parameters.GetOrThrowUnexpectedResponse("oauth_verifier"));

var result = ParseUserInfo(QueryUserInfo());
var result = ParseUserInfo(QueryUserInfo(queryParameters));
result.ProviderName = Name;

return result;
Expand Down Expand Up @@ -207,14 +211,19 @@ protected virtual void BeforeGetUserInfo(BeforeAfterRequestArgs args)
/// <summary>
/// Queries user info using corresponding service and data received by access token request.
/// </summary>
private string QueryUserInfo()
private string QueryUserInfo(NameValueCollection queryParameters)
{
var client = _factory.CreateClient(UserInfoServiceEndpoint);
client.Authenticator = OAuth1Authenticator.ForProtectedResource(
Configuration.ClientId, Configuration.ClientSecret, AccessToken, AccessTokenSecret);

var request = _factory.CreateRequest(UserInfoServiceEndpoint);

foreach(var parameter in queryParameters.AllKeys)
{
request.AddParameter(parameter, queryParameters[parameter]);
}

BeforeGetUserInfo(new BeforeAfterRequestArgs
{
Client = client,
Expand Down