Coder Social home page Coder Social logo

oauth2's Introduction

OAuth2

Build status NuGet Version

OAuth2 is a library for user authentication using third-party services (OAuth/OAuth2 protocol) such as Google, Facebook and so on.

Current Version and Status

Current version is 0.10.x Status is "release candidate" - despite we already have several real life projects built with usage of this library, we will change status to "stable" only after comprehensive set of acceptance tests is ready and runs successfully.

Standard Flow

Following are the steps of standard flow:

  • generate login URL and render page with it
  • define callback which will be called by third-party service on successful authentication
  • retrieve user info on callback from third-party service

Usage Example

Several simple steps to plug in the library into your app:

Install OAuth2 package via NuGet

Install-Package OAuth2

Your action function that needs to generate and redirect to the third-party service will look like

public ActionResult GoogleLogin()
{
  var redirectUri = new Uri(Url.Action("GoogleLoginCallBack", "Account", null, protocol: Request.Url.Scheme));
  var googleClient = new GoogleClient(new RequestFactory(), new OAuth2.Configuration.ClientConfiguration
  {
    ClientId = auth.ClientId?.Trim(),
    ClientSecret = auth.ClientSecret?.Trim(),
    RedirectUri = redirectUrl,
    Scope = "profile email"
  });
  return Redirect(googleClient.GetLoginLinkUri("SomeStateValueYouWantToUse"));
}

Finally the action that handles the callback will look like this :

public ActionResult GoogleLoginCallBack()
{
  var code = Request.QueryString["code"];
  var redirectUri = new Uri(Url.Action("GoogleLoginCallBack", "Account", null, protocol: Request.Url.Scheme));
  var googleClient = new GoogleClient(new RequestFactory(), new OAuth2.Configuration.ClientConfiguration
  {
    ClientId = auth.ClientId?.Trim(),
    ClientSecret = auth.ClientSecret?.Trim(),
    RedirectUri = redirectUrl,
    Scope = "profile email"
  });

  try
  {
    userInfo = oauth.GetUserInfo(new NameValueCollection() { { "code", code } });
  }
  catch(Exception ex)
  {
    return RedirectToAction("LoginError", new {error = ex.Message});
  }

  // do your validation and allow the user to proceed
  if (SignInManager.IsUserValid(userInfo.Email))
  {
    SignInManager.Login(userInfo.Email);
    return RedirectToAction("Index", "Home", new {error = ex.Message});
  }
  return Redirect(googleClient"LoginError", new {error = "User does not exists in the system"});
}

Supported Services

  • Asana
  • DigitalOcean
  • Facebook
  • Foursquare
  • GitHub
  • Google
  • Instagram
  • LinkedIn
  • MailRu
  • Odnoklassniki
  • Salesforce
  • Spotify
  • Todoist
  • Twitter
  • VK (Vkontakte)
  • Visual Studio Team Services (VSTS)
  • Windows Live
  • Yahoo
  • Yandex
  • Uber

Goals

Before I started working on this project I considered available solutions: several ones were found, but I wasn't satisfied with results:

  • some of them were too complex for such simple task as authentication via OAuth2
  • some - didn't have usage examples or documentation

So, I decided to implement this library striving to achieve following goals:

  • simplicity in usage - so even newbie can just call couple of methods and receive expected results
  • well-documented, testable and tested (!) code - current coverage (according to NCrunch) is greater than 80%, several acceptance tests are also implemented (SpecFlow + WatiN)
  • flexible, transparent and easily understandable design, so library can be used both by people who need only certain parts and fine-grained control over them and by people who want just plug it in and immediately receive expected result
  • self-education :) - it was interesting to see how OAuth2 works

Dependencies

This library is dependent on:

Contributors

  • Constantin Titarenko (started development, defined library structure, released initial version)
  • Blake Niemyjski (helped a lot to maintain the project, currently (since 2015) - top maintainer)
  • Andriy Somak (helped a lot with improvements on configuration as well as with extending list of supported services by implementing their clients)
  • Sascha Kiefer (simplified extending library with own provider implementations, added GitHub client)
  • Krisztián Pócza (added LinkedIn (OAuth 2) client)
  • Jamie Houston (added a Todoist client)
  • Sasidhar Kasturi (added Uber, Spotify, Yahoo)
  • Jamie Dalton (added Visual Studio Team Services)

Acknowledgements

Many thanks to JetBrains company for providing free OSS licenses for ReSharper and dotCover - these tools allow us to work on this project with pleasure!

Also we glad to have opportunity to use free Teamcity CI server provided by Codebetter.com and JetBrains - many thanks for supporting OSS!

JetBrains

OAuth2 optimization would never be so simple without YourKit .NET profiler! We appreciate kind support of open source projects by YourKit LLC - the creator of innovative and intelligent tools for profiling .NET YourKit .NET Profiler and Java applications YourKit Java Profiler.

Roadmap

  • Implement more acceptance tests
  • Increase code coverage by finalizing unit tests

License

The MIT License (MIT) Copyright (c) 2012-2013 Constantin Titarenko, Andrew Semack and others

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

oauth2's People

Contributors

boo1ean avatar ccoulson avatar daltskin avatar eitoball avatar ejsmith avatar etcdema avatar gkathire avatar jamiehouston avatar jholzer-cciq avatar jsiegmund avatar kekekeks avatar lucky-ly avatar magomes-dev avatar niemyjski avatar niieani avatar pronotion avatar ptmt avatar robert-hoffmann avatar rtumaykin avatar samble avatar sdebruyn avatar semack avatar skasturi avatar titarenko avatar tngraf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oauth2's Issues

Callback without providerName

Your current example requires storing providerName inside Session, we are not using sessions since our app runs on load balancer. Is there anyway providerName could be specified in URL State of GetLoginLinkUri() method? and can it be retrieved in callback?

Adding parameter to UserInfoServiceEndPoint

I am trying to get a Yahoo client working and they make you jump through hoops to get at the profile.

protected override Endpoint UserInfoServiceEndpoint
{
  get
  {
    return new Endpoint()
    {
      BaseUri = "https://social.yahooapis.com",
      Resource = "/v1/user/{guid}/profile/usercard"
    };
  }
}

The value I need for {guid} should be returned in the Request token response but how can I can get that value at this point? I think maybe I've been looking at this too long?

Thanks, Simon

Documentation

Write at least basic documentation on internals of OAuth2 library implementation.

How to handle cancelled login or access denied

How are people handling the scenario where someone chooses a login service, gets redirected to the service login page and then decides to cancel the process. Currently an exception of type 'OAuth2.Client.UnexpectedResponseException' is thrown but that doesn't really handle the situation.

Thanks

Google client's GetUserInfo throws ArgumentNullException

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

Remove System.Web Dependency

First, thanks for the great implementation of OAuth2. First package I found that was easy to reuse for different providers.

Is there a way to remove the System.Web Dependency in UriUtility.cs. Just wondering if anyone has done it already?

I would like to use this with Nancy if possible. Works great in our MVC website, but need it for a Nancy installation.

Provide refresh Token for Google

I want to fetch refresh token along with access token. So it would have been better if a method to fetch refresh token was provided.

Use-case - service layer wants access token, front-end is responsible for providing it

First of all, guys you build the great thing. I really like OAuth2 and its idea of being as simple and easy to use as possible. Thank you for this.

I'd like to propose some changes which I believe won't make the entire solution more complicated, but will enable few other use-cases.

As a distributed web-solution developer, I want my service layer to be designed as a standalone web API. This API will provide authentication methods like:

POST /AuthenticateWithGoogle/?accessToken={accessToken}
POST /AuthenticateWithFacebook/?accessToken={accessToken}
etc.

These methods will provide a session token which the service users will then use to tell the service who they are when they want to access the API:

GET /Dashboard/?sessionToken={sessionToken}

In this scenario, front-end (be it a web application or mobile client) is responsible for getting the google access token and then providing it to web API for authentication. Service behind web API will use this token to understand if or not we already have this user registered, create/update this user's details, etc.

I would really love OAuth2 library to provide a simple API to independently "authenticate and get access token" and "use access token to get user details". Based on the code I've seen, everything is already there, but it's just not a part of user API. Here's a pseudo code snippet:

// Web application
public ActionResult RedirectToGoogleAuthentication()
{
  return Redirect(_googleClient.GetAuthenticationUri());
}

public ActionResult GoogleAuthenticationCallback(string code)
{
  var accessToken = _googleClient.GetAccessToken(code);
  var serviceAuthResult = _myService.AuthenticateWithGoogle(accessToken);
  // DONE!
}

// Web API
public AuthenticationResult AuthenticateWithGoogle(string accessToken)
{
  // _googleClient is either OAuth2's GoogleClient or something hand-made
  var userDetails = _googleClient.GetUserInfo(accessToken);
  var user = _authenticationService.GetOrCreateUserByGoogleUserId(userDetails.Id);
  return StartSessionForUser(user);
}

What is the recommended pattern to use when adding custom endpoints?

(Not really an "issue" per se, more like a question or request.)

OAuth2 is really great. Its so much easier than any of the alternatives.
However, Im having a hard time understanding how I should add custom endpoints, not how I should but how the original developers had in mind for me to do it.

Anyway, an example would be great, it would really make it easier for new developers to use this easy and straight forward library.

Many thanks.

Get twitter user handle (username)

Hi,

not sure what you think would be the best approach for this, but it would be cool if the lib supported parsing of twitter username.

What I did currently is I made a custom TwitterClient class like this:

/// <summary>
/// This class is used to override the original TwitterClient's ParseUserInfo() method, to 
/// get the twitter username instead of first/last name which we're not using in our app.
/// </summary>
public class CustomTwitterClient : TwitterClient
{
    public CustomTwitterClient(IRequestFactory factory, IClientConfiguration configuration) : base(factory, configuration)
    {
    }

    protected override UserInfo ParseUserInfo(string content)
    {
        var response = JObject.Parse(content);

        var avatarUri = response["profile_image_url"].Value<string>();
        return new UserInfo
        {
            Id = response["id"].Value<string>(),
            Email = null,
            // NOTE: here we're setting the screen_name (username) as firstName if we 
            // ever need the firstName, we'll have to handle the parsing differently
            FirstName = response["screen_name"].Value<string>(),
            AvatarUri =
                {
                    Small = avatarUri.Replace("normal", "mini"),
                    Normal = avatarUri,
                    Large = avatarUri.Replace("normal", "bigger")
                }
        };
    }
}

Which I then use in the AccountController to handle twitter registration through oauth. I don't see us using the FirstName or the LastName at all so I simply set the screen_name as FirstName. It's a dirty hack but I didn't feel like overriding any additional classes (UserInfo, OauthClient, and possibly a few more) just to get the userName with oauthClient.GetUserInfo().

So perhaps with a few more generic and/or virtual methods (GetUserInfo, and ParseUserInfo this could be done in a slightly cleaner way). Or if the UserInfo class had a UserName property, in my opinion that would be good enough as well - we would be able to use a custom parser without messing with other properties and mapping them to something else.

What do you think?

Allow custom clients to be discovered

Currently it is not possible to add your own custom clients from your own assembly. This means that unless it is an existing client native to this project you have to create a custom build of the project. I've forked the project and made a small change to allow discovery of clients in other assemblies and will initiate a pull request shortly for consideration.

Thanks, Simon

C# 5.0 Async API

This is new feature request to implement async await pattern for Client token authorization.

Exception throw when calling GetLoginLinkUri for Twitter

[NullReferenceException: Object reference not set to an instance of an object.]
RestSharp.RestClient.EncodeParameters(IRestRequest request) +556
RestSharp.RestClient.BuildUri(IRestRequest request) +1615
OAuth2.Client.OAuthClient.GetLoginRequestUri(NameValueCollection response, String state) +844
OAuth2.Client.OAuthClient.GetLoginLinkUri(String state) +79

Facebook and Windows Live profile photo

In case of Windows Live client the profile photo is not valid. The avatar photo Url points to a target where there is no photo.

I see some complex Url combination logic in WindowsLiveClient.cs. Will it work for users who integrated their Windows 8, 8.1 with their live account?

You should use something like that: https://apis.live.net/v5.0/{0}/picture
where {0} is the userId.

Related documentation: http://msdn.microsoft.com/en-us/library/live/hh243648.aspx

Facebook avatar Urls that are provided by Oauth2 point to very small images even the Large ones.

The following call will give the correct profile photo Url:
https://graph.facebook.com/{0}/picture?type={1}
where {0} is the user id and {1] is the type (small, normal, large).

According to this there is a better method:
https://developers.facebook.com/docs/graph-api/reference/user/picture/

Bugs when accessing Google

I created a new Google OAuth Credential, set the client ID and secret in the web.config file.

When I run the example application, I get an InvalidCastException on the following line:

        AccessToken = (string) ParseTokenResponse(response.Content, AccessTokenKey);

Additional information: Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type 'System.String'.

The OAuth response from Google was:

{
  "access_token" : "ya29.kwEojw5CBL9Q-sDriuCMp8vu9AmC0MBc5jXNb2ZjRElYqxxK191x5HhPjrEkKDG4regV2hhQ5Rp0dg",
  "token_type" : "Bearer",
  "expires_in" : 3596,
  "id_token" : "eyJhbGciOiJSUzI1NiIsImtpZCI6IjQyZWJmNWQ2OGI2YzQ3ODQ2YTU1OTM4ZTZmMTY1NzlmYjlhZmJhZTMifQ.eyJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwic3ViIjoiMTEyMjE1NDE0NjczNjAyOTU2MjUzIiwiYXpwIjoiMTU2MTMwMzk0ODA0LXVtdXExOXZnaXI1aXE0c2I0dXBvdXQxbzNwcmVlOWtkLmFwcHMuZ29vZ2xldXNlcmNvbnRlbnQuY29tIiwiZW1haWwiOiJzYW1ia25pZ2h0QGdtYWlsLmNvbSIsImF0X2hhc2giOiJsdkNmUTJsRUNVUlFBbTVuSmlOZTFnIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImF1ZCI6IjE1NjEzMDM5NDgwNC11bXVxMTl2Z2lyNWlxNHNiNHVwb3V0MW8zcHJlZTlrZC5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsImlhdCI6MTQzNDM3MTM5NiwiZXhwIjoxNDM0Mzc0OTk2fQ.Etqr_U7derEAwjqcfnE3u8ozpViLvIftUlgtdvWcqgGtOO9OOi_BqYcPZT08dYzPMCtRkofgix7m6gV0mVtYHCkfLg0_gY1cqm7VdRu07LD2F0mNjgXOo406E8LRCScEyi2jcUf_1zNSAgtMyB2VAuzzNzkS4BXkRI0bvrKrlfrUL1SusBK32loIw9ItTe5peDIS1nWYmEqC-O28RtFvd_F8sLzpQQJo67x1k8Z-hOj-Hd4QmlUGWW1BExTzW4MeiHi5Q3IaWoqKiCPiEBaDI2DaJmVZMDIkC-t9g_MNYjsiUMIBRbgQ6GBCQLk28DCulhwCDUutAM-ZThLxonevoA"
}

The fix here that works for me is to amend ParseTokenResponse to return token.ToString()

The next issue is the following:

if (GrantType != "refresh_token")
                RefreshToken = (string) ParseTokenResponse(response.Content, RefreshTokenKey);

The RefreshToken assignment line throws a NullReferenceException in ParseTokenResponse -

var token = JObject.Parse(content).SelectToken(key);
                if (token.ToString().IsEmpty())

The exception happens on token.ToString() as token is null.

Instagram client authorize exception

As said in http://instagram.com/developer/authentication/ we have to use POST request instead GET. As I see in your RequestFactoryExtensions.CreateRequest creates only GET requests. Can you adjust to use POST requests to Instagram access_token requests?
Sorry, the problem is in getUserInfo endpoint. It is incorrect. And this request needs to be invoked with url parameter "acces_token". Can you fix this problem? I realy need in it. Thanks.

Use Sample

Is it possible to have a use sample? I'm new to the whole web development and I'm doing a personal project. I have already installed the package and modified the web.config, but I'm lost in how to implement it.

If I'm instructed on how to use it, I wouldn't mind creating some documentation for future references and posting it here.

How to return the user to the original url

Because the redirect url is preconfigured how can we ensure the user user is redirected back to their original url? Is the only way to store something in session prior to the login?

Aside from this thanks so much for sharing as I've had a nightmare trying to get a working OAuth2 solution to fit into an existing app. I've written a Yahoo provider also now so will send a pull request when I'm finished.

Thanks, Simon

Check Server Response: GetLoginRequestUri (OAuth)

Check response for errors, to avoid obscure exceptions like following:

[NullReferenceException: Object reference not set to an instance of an object.]
RestSharp.RestClient.EncodeParameters(IRestRequest request) +556
RestSharp.RestClient.BuildUri(IRestRequest request) +1615
OAuth2.Client.OAuthClient.GetLoginRequestUri(NameValueCollection response, String state) +844
OAuth2.Client.OAuthClient.GetLoginLinkUri(String state) +79

GitHub client's GetUserInfo throws multiple exceptions.

I'm getting two exceptions lately with the GitHub GetUserInfo method:

System.ArgumentNullException: Value cannot be null. Parameter name: source
at Newtonsoft.Json.Linq.Extensions.Value[T,U](System.Collections.Generic.IEnumerable`1 value) at offset 21
at OAuth2.Client.Impl.GitHubClient.ParseUserInfo(System.String content) at offset 7
at OAuth2.Client.OAuth2Client.GetUserInfo at offset 112

and

System.NullReferenceException: Object reference not set to an instance of an object.
at OAuth2.Client.Impl.GitHubClient.ParseUserInfo(System.String content) at offset 7
at OAuth2.Client.OAuth2Client.GetUserInfo at offset 112

State parameter

It would be very useful to have a way to pass "State" parameter to login uri and get it back after auth.

Problems with providers

Hi, I've successfully connected to google and facebook, but have problems with LinkedIn, Live and Twitter.
Windows Live: it redirects me to login.live, which displays "We're unable to complete your request"
LinkedIn is failing on RedirectResult(), with uri - https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id={guid}&redirect_uri=http:%2F%2Flocalhost:6260%2Fauth&scope=&state=626ba52acf754d79942422c4fd884b6f
Twitter: I've got Exception of type 'OAuth2.Client.UnexpectedResponseException' was thrown. here is stack trace:
[UnexpectedResponseException: Exception of type 'OAuth2.Client.UnexpectedResponseException' was thrown.]
OAuth2.Infrastructure.RestClientExtensions.ExecuteAndVerify(IRestClient client, IRestRequest request) +130
OAuth2.Client.OAuthClient.QueryRequestToken() +245
OAuth2.Client.OAuthClient.GetLoginLinkUri(String state) +35
Oauth2Test.Controllers.HomeController.Login(String providerName) +215
lambda_method(Closure , ControllerBase , Object[] ) +127
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) +242 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) +39
System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +12
System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) +139 System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +112 System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +452 System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +37 System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +241 System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +111
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +19 System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +111
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

Check User Info Response

Do not allow obscure exceptions like this. Do necessary check after receiving response from endpoint.

Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Path '', line 0, position 0.
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader)
at Newtonsoft.Json.Linq.JObject.Parse(String json)
at OAuth2.Client.Impl.FacebookClient.ParseUserInfo(String content)
at OAuth2.Client.OAuth2Client.GetUserInfo(String accessToken)
at OAuth2.Client.OAuth2Client.GetUserInfo(NameValueCollection parameters)

Twitter Login Fails on BeforeGetAccessToken because of missing code parameter

I'm trying to get my Twitter login working and after a few teething issues such as making sure the Twitter app has a Callback URL I got it to the point where the callback is made however it is failing because the response is missing the "code" parameter in the callback. What is returned is oauth_token and oauth_verifier.

Is there something else I am missing?

Thanks, this project has been a big help to me so far!

Exception for some users

Hey,

I see that some users are getting exception from the OAuth2 client. Havnt managed to reproduce it on my accounts , But its there. Have seen it both on facebook and google accounts. Here is a stacktrace of a facebook faild attempt.

Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Path '', line 0, position 0.
at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader)
at Newtonsoft.Json.Linq.JObject.Parse(String json)
at OAuth2.Client.Impl.FacebookClient.ParseUserInfo(String content)
at OAuth2.Client.OAuth2Client.GetUserInfo(String accessToken)
at OAuth2.Client.OAuth2Client.GetUserInfo(NameValueCollection parameters)

Why can't I do this

            var cfg = new OAuth2.Configuration.RuntimeClientConfiguration {
                ClientId = "......",
                ClientSecret = "......"
            };
            var auth = new OAuth2.Client.OAuth2Client (cfg);

            return auth.GetToken ("https://api..../accesstoken");

Please someone make a simple example, that don't involve config files and abstract class ?

Получение информации о пользователе только по Access token

Хотелось бы иметь возможность получаться информацию о пользователе только при помощи Access token. Например, если я использую библиотеку при создании API для мобильного приложения. В самом приложении происходит авторизация, где получаем access token.
Сейчас получить данные можно только через QueryString.


I would like to be able to obtain information about the user only through Access token. For example, if I use the API library when creating mobile applications. In the application there is authorization, which obtain access token.
Now you get the data only through the QueryString.

Dll version error on Clone > Build > Run VS15

`"Could not load file or assembly 'Autofac, Version=2.6.3.862, Culture=neutral, PublicKeyToken=17863af14b0044da' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"

=== Pre-bind state information ===
LOG: DisplayName = Autofac, Version=2.6.3.862, Culture=neutral, PublicKeyToken=17863af14b0044da
(Fully-specified)
LOG: Appbase = file:///C:/Users/briod/Desktop/OAuthTest/OAuth2/Oauth2/OAuth2.Example/
LOG: Initial PrivatePath = C:\Users\briod\Desktop\OAuthTest\OAuth2\Oauth2\OAuth2.Example\bin
Calling assembly : Autofac.Integration.Mvc, Version=2.6.3.862, Culture=neutral, PublicKeyToken=17863af14b0044da.

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\briod\Desktop\OAuthTest\OAuth2\Oauth2\OAuth2.Example\web.config
LOG: Using host configuration file: C:\Users\briod\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Autofac, Version=2.6.3.862, Culture=neutral, PublicKeyToken=17863af14b0044da
LOG: Attempting download of new URL file:///C:/Users/briod/AppData/Local/Temp/Temporary ASP.NET Files/vs/e002a6b1/3f91f652/Autofac.DLL.
LOG: Attempting download of new URL file:///C:/Users/briod/AppData/Local/Temp/Temporary ASP.NET Files/vs/e002a6b1/3f91f652/Autofac/Autofac.DLL.
LOG: Attempting download of new URL file:///C:/Users/briod/Desktop/OAuthTest/OAuth2/Oauth2/OAuth2.Example/bin/Autofac.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.`

the new downloaded Autofac.DLL has newer version 3.5.2.

Acceptance Tests

Create acceptance tests using browser automation to ensure each and every client is fully working.

Store extra oauth user data as extended data on the userinfo object

It seems like we are getting a lot of valuable information returned by our user info responses and we throw it away like a list of all their email addresses, sex/age and much more... It would be nice if this was shredded and anything that we didn't know about was placed in key value pairs on a userinfo data property.

I'd be more than happy to pair on this functionally..

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.