gpt4 book ai didi

asp.net-mvc-4 - 如何使用 MVC 4 实现三足 OAuth?

转载 作者:行者123 更新时间:2023-12-02 17:23:32 31 4
gpt4 key购买 nike

我正在尝试使用 ASP .NET MVC 4 的内置 OAuth 功能连接到 QuickBooks。问题(我的意思是,呃挑战)是内置模板(facebook、google 等)都提供两条腿的授权。 QuickBooks 使用三个。结果这可真是把我屁股踩个泥坑了。

好消息是 QuickBooks 提供了一个 MVC 3 示例。您可以在这里找到它:

https://ipp.developer.intuit.com/0010_Intuit_Partner_Platform/0025_Intuit_Anywhere/0020_Connect/0010_From_Within_Your_App/Implement_OAuth_in_Your_App

导致我出现问题的最相关的代码在这里:

    private String consumerSecret, consumerKey, oauthLink, RequestToken, TokenSecret, oauth_callback_url;

/// <summary>
/// Action Result for Index, This flow will create OAuthConsumer Context using Consumer key and Consuler Secret key
/// obtained when Application is added at intuit workspace. It creates OAuth Session out of OAuthConsumer and Calls
/// Intuit Workpsace endpoint for OAuth.
/// </summary>
/// <returns>Redirect Result.</returns>
public RedirectResult Index()
{
oauth_callback_url = Request.Url.GetLeftPart(UriPartial.Authority) + ConfigurationManager.AppSettings["oauth_callback_url"];
consumerKey = ConfigurationManager.AppSettings["consumerKey"];
consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
oauthLink = Constants.OauthEndPoints.IdFedOAuthBaseUrl;
IToken token = (IToken)Session["requestToken"];
IOAuthSession session = CreateSession();
IToken requestToken = session.GetRequestToken();
Session["requestToken"] = requestToken;
RequestToken = requestToken.Token;
TokenSecret = requestToken.TokenSecret;

oauthLink = Constants.OauthEndPoints.AuthorizeUrl + "?oauth_token=" + RequestToken + "&oauth_callback=" + UriUtility.UrlEncode(oauth_callback_url);
return Redirect(oauthLink);
}

/// <summary>
/// Gets the Access Token
/// </summary>
/// <returns>Returns OAuth Session</returns>
protected IOAuthSession CreateSession()
{
OAuthConsumerContext consumerContext = new OAuthConsumerContext
{
ConsumerKey = consumerKey,
ConsumerSecret = consumerSecret,
SignatureMethod = SignatureMethod.HmacSha1
};

OAuthSession s = new OAuthSession(consumerContext,
Constants.OauthEndPoints.IdFedOAuthBaseUrl + Constants.OauthEndPoints.UrlRequestToken,
oauthLink,
Constants.OauthEndPoints.IdFedOAuthBaseUrl + Constants.OauthEndPoints.UrlAccessToken);

return s;
}

从中,您可以看到 MVC 3 示例创建了一个 session 并获取了一个请求 token 。我眼前的问题是在 MVC 4 中找到可以检索此请求 token 的代码位。我认为它在我的 AccountController 中:

    //
// POST: /Account/ExternalLogin
//
// Go to me first!!!

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider, string returnUrl)
{
return new ExternalLoginResult(provider, Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
}


//
// Go to me second!!!

internal class ExternalLoginResult : ActionResult
{
public ExternalLoginResult(string provider, string returnUrl)
{
Provider = provider;
ReturnUrl = returnUrl;
}

public string Provider { get; private set; }
public string ReturnUrl { get; private set; }

public override void ExecuteResult(ControllerContext context)
{
if(Provider.Equals("Quickbooks Online")){
// oauthLink = Constants.OauthEndPoints.AuthorizeUrl + "?oauth_token=" + RequestToken + "&oauth_callback=" + UriUtility.UrlEncode(oauth_callback_url);
// oauthLink "https://workplace.intuit.com/Connect/Begin?oauth_token=qyprdvh1kZ3dpyobhKfJ54C10xPJPDy0vtwdNCeZmUmbLJdr&oauth_callback=http%3A%2F%2Flocalhost%3A50671%2FOauthResponse" string
string requestToken = ""; // How do I get this?
string oauthCallback = context.HttpContext.Request.Url.Scheme + "/OauthResponse";

//
// Now do I get a request token? How?

string returnUrl = "https://workplace.intuit.com/Connect/Begin" + "?oauth_token=" + requestToken + "&oauth_callback=" + HttpUtility.UrlEncode(oauthCallback);
OAuthWebSecurity.RequestAuthentication(Provider, returnUrl);
}
else{
OAuthWebSecurity.RequestAuthentication(Provider, ReturnUrl);
}
}
}

但从这里我迷路了。任何帮助,将不胜感激。我在 google 上搜索了很多,我猜到目前为止我已经投入了超过 40 个小时来尝试让它发挥作用。

谢谢,会

最佳答案

Intuit合作伙伴平台目前支持OAuth1.0a。三足 OAuth 中的第一足是获取 OAuth 请求 token 。

我没有使用过MVC4的OAuthWebSecurity;但是,根据我从文档/源代码中快速收集到的信息,似乎您需要创建一个独特的“QuickBooksClient”(并且开源它?)。我会关注LinkedInClient class作为食谱。来自 IPP docs ,OAuth 端点是:

获取请求 token :https://oauth.intuit.com/oauth/v1/get_request_token
登录页面:https://appcenter.intuit.com/Connect/Begin
获取访问 token :https://oauth.intuit.com/oauth/v1/get_access_token

关于asp.net-mvc-4 - 如何使用 MVC 4 实现三足 OAuth?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14991992/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com