.NET Gmail OAuth服务传递IncorrectInconsistent RedirectURI。

问题描述 投票:0回答:1

我在跟踪 .NET快速入门 为Gmail API添加一个集成到我的.NET Core 2.2应用程序。

由于某些原因, Redirect URI 我的请求中指定的是 我指定的那个。

证书.json

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

全权证书仪表板

credentials


enter image description here


编码

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个回答
0
投票

我已经解决了这个问题。

当在Google中创建OAuth凭证时,应用程序类型应该是...。桌上型电脑,不 网络应用.

enter image description here

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

© www.soinside.com 2019 - 2024. All rights reserved.