将帐户与Google Assistant关联会返回“来自Auth Code Exchange中IdP的错误响应”

时间:2018-08-22 22:06:17

标签: c# actions-on-google

尝试将模拟帐户链接到我的google助手服务时,当我重定向到google指定的重定向网址时,总是让我“来自Auth Code Exchange中IdP的错误响应”。我正在一边使用带有C#的MVC。

我的流程遵循此处的代码

public ActionResult Authorize(OAuthRequest request)
{

    ViewBag.Message = "Authorize Google to access your account?";
    User user = GetUserData();

    ViewBag.User = !string.IsNullOrEmpty(user?.UserName) ? user.UserName : null;
    Session["OAuth"] = request;
    return View();
}

public ActionResult LinkAccount(bool confirmation)
{
    if (Session["OAuth"] == null || !ValidateGoogleRequest((OAuthRequest)Session["OAuth"]))
    {
        return RedirectToAction("Index", "Home");
    }

    if (!confirmation)
    {
        return RedirectToAction("Index", "Home");
    }
    else
    {
        OAuthRequest request = (OAuthRequest)Session["OAuth"];

        User user = GetUserData();

        string accessCode = Token.CreateAccessCode(user.UserName);
        string url = $"{request.Redirect_URI}?code={accessCode}&state={request.State}";

        return Redirect(url);
    }
}

OAuthRequest只是存储google传递的所有参数的对象。

public class OAuthRequest
{
    public string Client_ID { get; set; }
    public string Redirect_URI { get; set; }
    public string State { get; set; }
    public string Scope { get; set; }
    public string Response_Type { get; set; }
}

我在本地主机上使用https进行测试。

1 个答案:

答案 0 :(得分:0)

结果证明此代码没有问题。之所以会出现“来自Auth Code Exchange中IdP的错误响应”响应,是因为Google的处理程序无法为我的令牌交换API查找DNS。