【问题标题】:GMail OAUTH not asking for permission when publishedGMail OAUTH 发布时未请求许可
【发布时间】:2017-12-21 12:22:16
【问题描述】:

我已经开始使用 GMail API,它在我的本地机器上运行良好;它将打开 Google 权限页面,我可以选择我的帐户。然后它会存储返回的 json 令牌,并且只会再次询问该令牌是否被移除。

当我发布到服务器时,OAUTH 页面永远不会显示,并且应用程序似乎因“线程被中止”异常而超时。

我的代码;

    try
    {
        using (var stream = new FileStream(HttpContext.Current.Server.MapPath("~/credentials/client_id.json"), FileMode.Open, FileAccess.Read))
        {
            string credPath = HttpContext.Current.Server.MapPath("~/credentials/gmail_readonly_token.json");

            _credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                Scopes,
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;
            db.writeLog("INFO", "Gmail Credentials Saved","Credential file saved to: " + credPath);

        }
        // Create Gmail API service.
        service = new GmailService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = _credential,
        });
    }
    catch (Exception e)
    {
        db.writeLog("Error", "Failure when creating Gmail class", e.Message, null, _username, null);
    }

我需要在“client_id.json”(正式为 client_secret.json)文件中进行更改吗?我唯一改变的是redirect_uris 行。

欢迎提出任何其他建议,我能找到的唯一其他类似问题是here,但没有答案。

谢谢,

丹尼。

【问题讨论】:

    标签: json oauth token gmail-api


    【解决方案1】:

    第一个有效,因为您遵循了预期的用例,即客户端。但是,要在服务器上实现授权,请遵循 Implementing Server-Side AUthorization 指南。

    【讨论】:

    • 抱歉回复慢!我会试一试,我很难看出在 IIS Express 中运行的 Web 应用程序和在服务器上的 IIS 中运行的 Web 应用程序之间的区别,尤其是当服务器应用程序池已设置为像我一样运行时。干杯!
    猜你喜欢
    • 2018-04-12
    • 1970-01-01
    • 1970-01-01
    • 2014-10-05
    • 1970-01-01
    • 2011-08-19
    • 1970-01-01
    • 2018-02-03
    相关资源
    最近更新 更多