【问题标题】:.NET Gmail OAuth Service Passing Incorrect/Inconsistent RedirectURI.NET Gmail OAuth 服务传递不正确/不一致的 RedirectURI
【发布时间】:2020-08-23 03:16:58
【问题描述】:

我正在关注 Gmail API 的 .NET Quickstart,以便将集成添加到我的 .NET Core 2.2 应用程序中。

出于某种原因,我的请求中指定的Redirect URI 不是我指定的

credentials.json

{
  "web": {
    //redacted,
    "redirect_uris": [ "https://localhost:44393/ExternalAuth/Gmail" ]
  }
}

凭据仪表板



代码

UserCredential credential;

using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
{
  string credPath = "token.json";
  credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.Load(stream).Secrets,
    Scopes,
    "user",
    CancellationToken.None,
    new FileDataStore(credPath, true)
  ).Result;
  Console.WriteLine("Credential file saved to: " + credPath);
}

我似乎无法找到它的来源;我假设它只是从我的本地机器中提取它,但我想一定有一种方法可以覆盖请求中包含的 URI?

【问题讨论】:

    标签: .net .net-core gmail-api


    【解决方案1】:

    我已经解决了这个问题。

    在 Google 中创建 OAuth 凭据时,应用程序类型应为 桌面,而不是 Web 应用程序

    这样做之后,您应该注意到您的credentials.json 文件以installed: 开头,而不是web:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-28
      • 2021-03-03
      • 1970-01-01
      • 2010-10-30
      • 1970-01-01
      • 1970-01-01
      • 2018-02-19
      • 2010-10-30
      相关资源
      最近更新 更多