Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reporting and Logging errors while using DotnetopenAuth

Wanted to connect with the Withings API. I used the same Controller in an other project, where he worked perfectly. In a project where the site is an Azure webrole(don't know how that is the issue) it just doesn't work. First I got

The type initializer for 'DotNetOpenAuth.Reporting' threw an exception.

So I turned it off in the web.config

reporting enabled="false"

Now I got

The type initializer for 'DotNetOpenAuth.Logger' threw an exception.

I don't use log4net.

 public ActionResult StartOAuth()
    {

        var serviceProvider = GetServiceDescription();
        var consumer = new WebConsumer(serviceProvider, _tokenManager);

        // Url to redirect to
        var authUrl = new Uri(Request.Url.Scheme + "://" + Request.Url.Authority + "/Withings/OAuthCallBack");

        // request access
        consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(authUrl, null, null));

        // This will not get hit!
        return null;
    }

private ServiceProviderDescription GetServiceDescription()
    {
        return new ServiceProviderDescription
        {
            AccessTokenEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/access_token", HttpDeliveryMethods.PostRequest),
            RequestTokenEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/request_token", HttpDeliveryMethods.PostRequest),
            UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/authorize", HttpDeliveryMethods.PostRequest),
            TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
            ProtocolVersion = ProtocolVersion.V10a
        };
    }
like image 831
Łukasz Młynik Avatar asked Sep 24 '26 19:09

Łukasz Młynik


1 Answers

So it turns out it was Azure's fault. In web.config there is a section which broke DotnetOpenAuth. Deleting this section is a workaround. Probably adding log4net would also fix this issue, but I didn't test.

<trace> 
<listeners> 
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics"> 

<filter type="" /> 
</add> 
</listeners> 
</trace>
like image 62
Łukasz Młynik Avatar answered Sep 26 '26 10:09

Łukasz Młynik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!