redirect_uri_mismatch 请求中的重定向 URI 与 OAuth 客户端授权的重定向 URI 不匹配

2023-12-11

我有以下客户秘密

{
  "web": {
    "client_id": "testid",
    "project_id": "testproj",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://www.googleapis.com/oauth2/v3/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "test-sec",
    "redirect_uris": [
      "https://localhost:8080/oauth2callback"
    ]
  }
}

我得到了

“错误:redirect_uri_不匹配 请求中的重定向 URI,http://127.0.0.1:8414/authorize/,与 OAuth 客户端授权的不匹配。

要更新授权的重定向 URI,请访问:“。请您建议如何修复它。

我正在使用 C#。我已经用这个创建了凭据 -

GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, scopes,
                                             "user",
                                              CancellationToken.None, 
                                              new FileDataStore(Directory.GetCurrentDirectory() + "\\AccessToken\\" , 
                                             true)).Result; 

但第一次,它弹出登录,一旦我登录,它就创建了Google.Apis.Auth.OAuth2.Responses.TokenResponse-user文件夹中的文件。有没有办法绕过第一次登录?

Thanks.


当您在中创建凭据时https://console.developers.google.com:

Credentials

点击后Create credentials通过选择OAuth client ID:

Create credentials

选择其他作为应用程序类型:

Create OAuth client ID.

您应该拥有以下格式的凭据:

{
  "installed": {
    "client_id": "...",
    "project_id": "...",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "...",
    "redirect_uris": [
      "urn:ietf:wg:oauth:2.0:oob",
      "http://localhost"
    ]
  }
}

现在,无论您在redirect_uri参数中使用什么端口,您的OAuth2链接都应该可以正常工作http://localhost:8414例如(8414 作为随机端口)。你不再有这个错误:

错误:redirect_uri_mismatch 请求中的重定向 URI,http://localhost:8414/授权/,与 OAuth 客户端授权的不匹配。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

redirect_uri_mismatch 请求中的重定向 URI 与 OAuth 客户端授权的重定向 URI 不匹配 的相关文章

随机推荐