【问题标题】:Problems with Azure Website and OAuthAzure 网站和 OAuth 的问题
【发布时间】:2016-10-07 17:40:23
【问题描述】:

我在 Azure 网站上发布了我的 MVC .NET 项目。

问题是当我创建UserCredential 时,我得到一个Exception,上面写着“访问被拒绝”

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
            new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
            , scopes
            , userName
            , CancellationToken.None
            , new DataStore()).Result;

我的 GoogleAPIs 控制台凭据如下所示 (Client Secret):

ClientSecret

然后,在我的 Azure 门户中,我配置了 Authentication/Authorization

Azure Portal Authentication

我确定问题是 凭据问题,因为当我在 localhost 中尝试它时,它可以正常工作。当它使用完全相同的凭据部署在 azure 中时,问题就出现了。

  • 我是否遗漏了任何一步?
  • 我的 Google 凭据有问题吗?
  • 我是否应该在 Azure 中启用其他功能?

【问题讨论】:

    标签: azure oauth google-api google-drive-api azure-web-app-service


    【解决方案1】:

    对于这种情况,我建议您尝试改用 GoogleAuthorizationCodeFlow。有关如何使用 GoogleAuthorizationCodeFlow 的详细步骤,请参考this article。我测试了代码并将用户 ID 显示到页面索引。它在 Azure Web App 中运行良好。

    这里是 HomeController:

        public class HomeController : AsyncController
        {
            public async Task<ActionResult> IndexAsync(CancellationToken cancellationToken)
            {
                var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
                    AuthorizeAsync(cancellationToken);
    
                if (result.Credential != null)
                {
                    ViewBag.Message = result.Credential.UserId;
                    return View();
                }
                else
                {
                    return new RedirectResult(result.RedirectUri);
                }
            }
        }
    

    结果如下:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-31
      • 2014-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-05
      相关资源
      最近更新 更多