通过DotNetOpenAuth身份验证FreshBooks [英] Authentication to FreshBooks via DotNetOpenAuth

查看:326
本文介绍了通过DotNetOpenAuth身份验证FreshBooks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用OAuth认证从我的ASP.NET MVC C#应用程序的FreshBooks API。以下是我迄今为止:

I'm trying to use OAuth for authentication for the FreshBooks API from my ASP.NET MVC C# app. Here is what I have so far:

我在这里使用DotNetOpenAuth是我在我的控制器操作的代码

I'm using DotNetOpenAuth here is the code I have in my controller action

if (TokenManager != null)
{
    ServiceProviderDescription provider = new ServiceProviderDescription();
    provider.ProtocolVersion = ProtocolVersion.V10a;
    provider.AccessTokenEndpoint = new MessageReceivingEndpoint     ("https://myfbid.freshbooks.com/oauth/oauth_access.php", DotNetOpenAuth.Messaging.HttpDeliveryMethods.PostRequest);
    provider.RequestTokenEndpoint = new DotNetOpenAuth.Messaging.MessageReceivingEndpoint("https://myfbid.freshbooks.com/oauth/oauth_request.php", DotNetOpenAuth.Messaging.HttpDeliveryMethods.PostRequest);
    provider.UserAuthorizationEndpoint = new DotNetOpenAuth.Messaging.MessageReceivingEndpoint("https://myfbid.freshbooks.com/oauth/oauth_authorize.php", DotNetOpenAuth.Messaging.HttpDeliveryMethods.GetRequest);
    provider.TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() };

    var consumer = new WebConsumer(provider, TokenManager);

    var response = consumer.ProcessUserAuthorization();
    if (response != null)
    {
        this.AccessToken = response.AccessToken;
    }
    else
    {
        // we need to request authorization
        consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(
            new Uri("http://localhost:9876/home/testoauth/"), null, null));
    }
}



的TokenManager是设置有相同的类DotNetOpenAuth样,我已经把我的消费者的秘密,FreshBooks送给我的。

The TokenManager is the same class that is provided with the DotNetOpenAuth sample, I've set my consumer secret that FreshBooks gave me.

consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(.. ))我有以下异常:

远程服务器返回错误:(400 )错误的请求。

"The remote server returned an error: (400) Bad Request.".

我是不是做正确吗?基于FreshBooks文档和DotNetOpenAuth样本应该正常工作。

Am I doing this correctly? Based on FreshBooks documentation and DotNetOpenAuth samples that should work correctly.

有没有更简单通过OAuth认证方式,因为DotNetOpenAuth是有点大了单纯使用OAuth认证?

Is there a simpler way to authenticate with OAuth, as DotNetOpenAuth is a bit huge for simply using OAuth authentication?

推荐答案

如果你想使用DotNetOpenAuth你需要确保:

if you want to use DotNetOpenAuth you need to make sure that:


  • 您使用签名法文本的

  • 和使用PlaintextSigningBindingElement作为TamperProtectionElements

这样的事情对我的作品:

something like this works for me:

public static readonly ServiceProviderDescription ServiceDescription = new ServiceProviderDescription
{
    ProtocolVersion = ProtocolVersion.V10a,
    RequestTokenEndpoint = new MessageReceivingEndpoint(oAuthBase + "/oauth_request.php", HttpDeliveryMethods.PostRequest),
    UserAuthorizationEndpoint = new MessageReceivingEndpoint(oAuthBase + "/oauth_authorize.php", HttpDeliveryMethods.GetRequest | HttpDeliveryMethods.AuthorizationHeaderRequest),
    AccessTokenEndpoint = new MessageReceivingEndpoint(oAuthBase + "/oauth_access.php", HttpDeliveryMethods.PostRequest | HttpDeliveryMethods.AuthorizationHeaderRequest),
    TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new PlaintextSigningBindingElement() }
};

public static void RequestAuthorization(WebConsumer consumer)
{
    if (consumer == null)
    {
        throw new ArgumentNullException("consumer");
    }

    var extraParameters = new Dictionary<string, string> {
        { "oauth_signature_method", "PLAINTEXT" },
    };
    Uri callback = Util.GetCallbackUrlFromContext();
    var request = consumer.PrepareRequestUserAuthorization(callback, extraParameters, null);
    consumer.Channel.Send(request);
}

这篇关于通过DotNetOpenAuth身份验证FreshBooks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆