相关疑难解决方法(0)

为什么我没有收到Google OAuth请求中的RefreshToken?

我正在尝试将Google日历集成到我的应用程序中,并且我在使用关闭RefreshToken的OAuth授权方面遇到了一些问题.我收到一个没有问题的AccessToken,但RefreshToken属性为null.请参阅标有"ERROR HERE:"的行,了解我遇到的问题

我的Asp.Net MVC控制器(命名OAuthController)如下所示:

    public ActionResult Index()
    {
        var client = CreateClient();
        client.RequestUserAuthorization(new[] { "https://www.googleapis.com/auth/calendar" }, new Uri("http://localhost/FL.Evaluation.Web/OAuth/CallBack"));

        return View();
    }

    public ActionResult CallBack()
    {

        if (string.IsNullOrEmpty(Request.QueryString["code"])) return null;

        var client = CreateClient();

        // Now getting a 400 Bad Request here
        var state = client.ProcessUserAuthorization();

        // ERROR HERE:  The RefreshToken is NULL
        HttpContext.Session["REFRESH_TOKEN"] = Convert.ToBase64String(Encoding.Unicode.GetBytes(state.RefreshToken));

        return JavaScript("Completed!");
    }

    private static WebServerClient CreateClient()
    {
        return
            new WebServerClient(
                new AuthorizationServerDescription()
                    {
                        TokenEndpoint = new Uri("https://accounts.google.com/o/oauth2/token"),
                        AuthorizationEndpoint = new Uri("https://accounts.google.com/o/oauth2/auth"),
                        ProtocolVersion …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc oauth dotnetopenauth oauth-2.0

7
推荐指数
2
解决办法
5868
查看次数

标签 统计

asp.net-mvc ×1

dotnetopenauth ×1

oauth ×1

oauth-2.0 ×1