google oAuth尝试重定向到与我的应用程序网址不同的随机uri

时间:2019-07-04 11:19:18

标签: c# asp.net-core google-api google-oauth google-api-dotnet-client

这是.Net Core2.1 webApplication,c#。 定位为将我的联系人与google people API同步。

我有一个前端应用程序,该应用程序将授予最终用户许可并获得访问令牌。

开始同步流程时,oAuth甚至会在到达设置令牌步骤之前返回错误。

  

错误:redirect_uri_mismatch

我的应用程序网址为http://localhost:58240

在对应用程序的每个身份验证请求中,提供错误并声明为未授权的url与58240不同。它随每个请求而更改

请注意: 1-启用SS1关闭。 2-自动生成绑定重定向设置为否。

UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
           new ClientSecrets
           {
               ClientId = this._client_id,
               ClientSecret = this._client_secret
           },
              new[] { "profile", this.scope_readOnly },
              "user",
              CancellationToken.None);

1 个答案:

答案 0 :(得分:0)

  

错误:redirect_uri_mismatch

完全表示您是从重定向uri发送的,而您尚未在Google Developer Console中添加。错误屏幕上应该有一个按钮,您可以在其中确切看到要发送的URL。将该网址添加到Google开发者控制台中

它可能以AuthCallback

结尾
https://localhost:44323/AuthCallback/

您需要将自己的开发环境设置为不应用随机端口,而需要一个静态端口,以便能够在Google开发者控制台中正确设置重定向uri。