【发布时间】:2019-06-03 16:32:11
【问题描述】:
我不知道在哪里或是否需要为 QuickBooks OAuth2 配置 API 端点。
如果我为代码请求添加基本 URL,QuickBooks 会正确返回带有代码的重定向 URL。之后,我不知道如何为令牌交换添加端点。
在令牌交换中,我遇到了异常:
Value cannot be null. Parameter name: endpoint
最终,我无法弄清楚如何正确设置端点。任何帮助将不胜感激。
public class QuickbooksController : Controller
{
public static OAuth2Client oauthClient = new OAuth2Client(
"REDACTED",
"REDACTED",
"https://localhost:302/QuickBooks/AccessToken/",
"sandbox");
// GET: Quickbooks
public ActionResult Index(string connect, string msg)
{
if (!String.IsNullOrEmpty(connect)) {
//Prepare scopes
List<OidcScopes> scopes = new List<OidcScopes>();
scopes.Add(OidcScopes.Accounting);
scopes.Add(OidcScopes.OpenId);
string authorizeUrl = oauthClient.GetAuthorizationURL(scopes);
return Redirect("https://appcenter.intuit.com/connect/oauth2" + authorizeUrl);
}
ViewBag.TokenFailed = false;
ViewBag.ConfirmMessage = msg;
return View(new QuickBooksViewModel(new App()));
}
public async Task<ActionResult> Accesstoken(string state, string code, string realmId)
{
try {
TokenResponse tokenResponse = await oauthClient.GetBearerTokenAsync(code);
if (tokenResponse.IsError) {
return RedirectToAction("Index", new { msg = "Error connecting to QuickBooks. Response: " + tokenResponse.Raw });
}
return RedirectToAction("Index", new { msg = "Connected to QuickBooks. Token: " + tokenResponse.AccessToken });
} catch (Exception ex) {
return RedirectToAction("Index", new { msg = "Error connecting to QuickBooks. Error: " + ex.Message });
}
}
【问题讨论】:
标签: .net asp.net-mvc oauth-2.0 quickbooks