Error PrepareRequestUserAuthorizationAsync

I had a very simple code that worked fine for me:

var url = System.Web.HttpContext.Current.Request.Url; Uri callbackUrl = new System.Uri(url, "oAuth2CallBack"); var ub = new UriBuilder(callbackUrl); // decodes urlencoded pairs from uri.Query to var var httpValueCollection = HttpUtility.ParseQueryString(callbackUrl.Query); httpValueCollection.Add(UrlArguments.Param, null); // urlencodes the whole HttpValueCollection ub.Query = httpValueCollection.ToString(); var authorizationRequest = OAuthClient.PrepareRequestUserAuthorization(new[] { "somedata" }, ub.Uri); authorizationRequest.Send(); 

I updated the OAuth NuGet packages and rewrote the code as follows:

 var url = System.Web.HttpContext.Current.Request.Url; Uri callbackUrl = new System.Uri(url, "oAuth2CallBack"); var ub = new UriBuilder(callbackUrl); // decodes urlencoded pairs from uri.Query to var var httpValueCollection = HttpUtility.ParseQueryString(callbackUrl.Query); httpValueCollection.Add(UrlArguments.Param, null); // urlencodes the whole HttpValueCollection ub.Query = httpValueCollection.ToString(); var client = new WebServerClient(new AuthorizationServerDescription { TokenEndpoint = Configuration.OAuth2.TokenEndpoint, AuthorizationEndpoint = Configuration.OAuth2.AuthorizationEndpoint, }, clientIdentifier: Configuration.OAuth2.ClientIdentifier, clientCredentialApplicator: ClientCredentialApplicator.PostParameter( Configuration.OAuth2.ClientSecret)); var authorizationRequest = await client.PrepareRequestUserAuthorizationAsync(new[] { "somedata" }, ub.Uri); await authorizationRequest.SendAsync(); 

but PrepareRequestUserAuthorizationAsync exception

"An attempt by the 'DotNetOpenAuth.OAuth2.WebServerClient + d__3.MoveNext ()' method to access the access method 'System.Collections.Generic.List`1..ctor ()' failed."

+7
c # asp.net-mvc asp.net-mvc-5 dotnetopenauth
source share
1 answer

The problem is that DotNetOpenAuth.OAuth2.Client is referencing System.Net.Http.Formatters 5.0 from the WebApi nuget package. Setting a link to System.Net.Http.Formatters 4.0 from .NET 4.0 / 4.5 BCL fixes the problem and all tests still pass.

See commit on github https://github.com/rcollette/DotNetOpenAuth/commit/59fe1e820fc48df8bb079b210ac585974f8326f5

See the retrieval request https://github.com/DotNetOpenAuth/DotNetOpenAuth/pull/350

+1
source share

All Articles