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

Google client's GetUserInfo throws ArgumentNullException #28

Closed
agibalov opened this issue Aug 10, 2013 · 5 comments
Closed

Google client's GetUserInfo throws ArgumentNullException #28

agibalov opened this issue Aug 10, 2013 · 5 comments
Assignees
Labels
Milestone

Comments

@agibalov
Copy link

I'm trying to use OAuth2 0.8.25 (the latest one in NuGet). Here's my GoogleClient configuration:

<add clientType="GoogleClient"
     enabled="true"
     clientId="GOODCLIENTIDHERE"
     clientSecret="GOODCLIENTSECRETHERE"
     scope="https://www.googleapis.com/auth/userinfo.email"
     redirectUri="~/Home/AuthCallback" />

Here's where it fails:

var userInfo = googleClient.GetUserInfo(Request.QueryString);

Here's where I am after authentication:

http://localhost/OAuth2Experiment/Home/AuthCallback?code=4/JRhtJvR3WzaZWhR6jHD0ZzCFSdOP.gpR9X3xcBGcRsNf4jSVKMpZw1hfVgAI

Here's a stacktrace:

[ArgumentNullException: Value cannot be null.
Parameter name: source]
   Newtonsoft.Json.Linq.Extensions.Value(IEnumerable`1 value) +112
   OAuth2.Client.Impl.GoogleClient.ParseUserInfo(String content) +125
   OAuth2.Client.OAuth2Client.GetUserInfo() +175
   OAuth2.Client.OAuth2Client.GetUserInfo(NameValueCollection parameters) +77
   OAuth2Experiment.Controllers.HomeController.AuthCallback() in c:\dev\OAuth2Experiment\OAuth2Experiment\Controllers\HomeController.cs:35
   lambda_method(Closure , ControllerBase , Object[] ) +62
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +211
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +28
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +57
   System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +223
   System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +48
   System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +24
   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +102
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +57
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +43
   System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +14
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +57
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +47
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +25
   System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +23
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9634212
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
@agibalov
Copy link
Author

Fixed by changing

scope="https://www.googleapis.com/auth/userinfo.email"

to

scope="https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email"

Not sure if it's a workaround or by design.

@titarenko
Copy link
Owner

Hi,

Thank you for update! And excuse me for late response.

Yes, when there is no (or not enough) persmissions, Google will answer with error instead of access token. That response is not handled properly, causing faceless ArgumentNullException with poor context.

What I will do next is proper handling of error responses for GoogleClient. And yes, this solution described by is closer to "by design" than to "workaround".

Thanks again for helping to ensure better quality of OAuth2 library!

@ghost ghost assigned titarenko Sep 12, 2013
@rtumaykin
Copy link
Contributor

Actually this is not a google that throws this exception. When you ask to provide only email and nothing else, all other properties such as First name, Last name, etc aren't passed back and therefore the method used in UserInfo creation throws an exception as it does not handle null values.

@niemyjski
Copy link
Collaborator

Yes, this is logged in a second issue. It has to do with not using SafeGet. Would you mind submitting a pull request for this?

@niemyjski niemyjski added the bug label Jun 8, 2015
@niemyjski
Copy link
Collaborator

I'm closing this as a duplicate of #69.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants