Google OAuth 2.0“错误":“redirect_uri_mismatch" [英] Google OAuth 2.0 "error" : "redirect_uri_mismatch"
问题描述
我已经花了一天,砸了一个玻璃,我真的很生气,我不明白谷歌想要我做什么,哪里出了问题.
I spend already one day, crashed one glass and I am really angry about it, I do not understand what google want from me, and what is wrong.
我在开发者控制台中启用了 Google+ Api,创建了新的 OAuth 客户端 ID
I've enabled Google+ Api in developers console , created new OAuth Client ID
$ch = curl_init('https://accounts.google.com/o/oauth2/token');
curl_setopt($ch,CURLOPT_POSTFIELDS,'code=4%2FPp1GWqC6PIr3wNYrZ5kK4T9oitxBoo0fBqBrVNQfE-g.ElKDUjQ7E28SoiIBeO6P2m-0RPaolgI&grant_type=authorization_code&redirect_uri=https%3A%2F%2Fmyprivatedomain.local.com%2Foauth2callback&client_id=%mycliet_id%&client_secret=%mysecret%');
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
var_dump(curl_exec($ch));
按照此处的说明创建所有内容:https://developers.google.com/+/web/signin/server-side-flow,页面出现gplus按钮,成功请求授权用户访问.但是当我完成第 8 步第 8 步:初始化 Google API 客户端库并启动 Google+ 服务我的请求每次都得到响应 "error" : "redirect_uri_mismatch"
created all like in instructions here: https://developers.google.com/+/web/signin/server-side-flow, gplus button appear on page, and it successfully request access for authorized user. but when I made step 8 Step 8: Initialize the Google API client library and start the Google+ service my request every time get response "error" : "redirect_uri_mismatch"
我知道,当您未在 Google Console 中注册 redirect_uri 或在其中输入类型错误时会出现此错误,但我注册了它,并且仅用于测试尝试设置不同的 url(更改域名,将协议从 https 更改为 https),但它从来没有工作!我不知道我还能检查什么,请至少提供一些建议.
I know, that this error appear when you do not registered redirect_uri in Google Console, or when you make a type mistake in it, but I registered it, and also just for testing tried to setup different urls (changed domain names, changed protocols from https to https), but it never working! I have no idea what else I can check, please advice at least something.
推荐答案
文档在步骤 1 中说.https://developers.google.com/+/web/signin/server-side-flow#step_1_create_a_client_id_and_client_secret 必须没有配置重定向 URI,只有授权的 JavaScript 来源".在授权请求和令牌交换中,redirect_uri
参数值应设置为postmessage
.
The docs say in Step 1. https://developers.google.com/+/web/signin/server-side-flow#step_1_create_a_client_id_and_client_secret that there must be no redirect URIs configured, only "Authorized JavaScript origins". In the authorization request and the token exchange, the redirect_uri
parameter value should be set to postmessage
.
关于此的现有技术:Google OAuth 2 授权 - 错误:redirect_uri_mismatch
这篇关于Google OAuth 2.0“错误":“redirect_uri_mismatch"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!