我有以下客户 secret
{
"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"
]
}
}
我得到
"Error: redirect_uri_mismatch The redirect URI in the request, http://127.0.0.1:8414/authorize/, does not match the ones authorized for the OAuth client.
要更新授权的重定向 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
文件。有没有办法绕过第一次登录?谢谢。
最佳答案
在 https://console.developers.google.com 中创建凭据时:
通过选择 Create credentials
来点击 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"
]
}
}
现在,您的 OAuth2 链接应该可以在 redirection_uri 参数中的任何端口作为
http://localhost:8414
使用(例如,8414 作为随机端口)。而你不再是这个错误:Error: redirect_uri_mismatch The redirect URI in the request, http://localhost:8414/authorize/, does not match the ones authorized for the OAuth client.
关于google-api - redirect_uri_mismatch 请求中的重定向 URI 与 OAuth 客户端授权的不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53680886/