tch请求中的重定向URI与为OAuth客户端授权的重定向URI

tch请求中的重定向URI与为OAuth客户端授权的重定向URI

本文介绍了redirect_uri_mismatch请求中的重定向URI与为OAuth客户端授权的重定向URI不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下客户机密

{
  "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"
    ]
  }
}

我得到

要更新授权的重定向URI,请访问:".请提出建议,以解决问题.

To update the authorized redirect URIs, visit:". Could you please suggest, how to fix it.

我正在使用C#.我已经用它创建了凭据-

I am using C#. I have created credentials with this -

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

但是,这是第一次,它弹出并显示登录信息,一旦我登录,它就在该文件夹中创建了Google.Apis.Auth.OAuth2.Responses.TokenResponse-user文件.有没有一种方法可以绕过首次登录?

But for first time , it popped up with login and once I logged in , it has created Google.Apis.Auth.OAuth2.Responses.TokenResponse-user file in the folder. Is there a way to bypass first time login ?

谢谢.

推荐答案

https: //console.developers.google.com :

通过选择OAuth client IDCreate credentials上攀爬之后:

After cliking on Create credentials by choosing OAuth client ID:

选择其他"作为应用类型:

Choose Other as Aplication type:

.

您应具有以下格式的凭据:

You should have this format of credentials:

{
  "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"
    ]
  }
}

现在,无论您在redirection_uri参数中的端口如何(例如8414作为随机端口),您的OAuth2链接都应该可以使用.而且您不再是这个错误:

Now your OAuth2 link should works whatever your port in redirection_uri paramater as http://localhost:8414 for example (with 8414 as random port). And you are no more this error:

这篇关于redirect_uri_mismatch请求中的重定向URI与为OAuth客户端授权的重定向URI不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 23:00