PrepareRequestUserAuthorizationAsync fails
Asked Answered
O

1

7

I had very simple code which 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've updated OAuth's NuGet packages and rewrite the code this way:

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 throws exception

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

Onceover answered 18/11, 2013 at 16:52 Comment(5)
Yeah, I'm getting this too, can't find any documentation on it, it happen on the var cookies = new List<CookieHeaderValue>(); line ...Bituminize
same for me as for @Bituminize !!Baylor
In the end, I got the source and commented out the cookie code that causes the error, works now, but I'm not happy going to production with thatBituminize
I have this issue too, but am not really comfortable commenting out a security feature. Maybe @andrew arnott can shed some light on this.Vella
Did u try synchronous requestBunt
A
1

The issue is that DotNetOpenAuth.OAuth2.Client references System.Net.Http.Formatters 5.0 from the WebApi nuget package. Setting the reference to System.Net.Http.Formatters 4.0 from the .NET 4.0/4.5 BCL resolves the issue and all tests still pass.

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

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

Accede answered 18/12, 2014 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.