我目前正在尝试使用Google Identity Toolkit实现忘记密码功能。 PHP后端试图获取oob代码,因为客户端(iOS)没有足够的权限。
每当我运行脚本时,我都会收到错误 INVALID_CREDENTIALS ,更具体地说:
oob Code: string(249) "{ "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Invalid Credentials" } } "
我不知道从哪里获取 authToken 或者是否正确发送了帖子请求。
$authToken = "xxxxxxxxxxxxxxxxx";
$email = $_POST['email'];
$uIp = $_POST['ip'];
//Post Data in Array
$postData = array(
'kind' => 'identitytoolkit#relyingparty',
'requestType' => 'PASSWORD_RESET',
'email' => '$email',
'challenge' => 'verified',
'captchaResp' => 'verified',
'userIp' => '$uIp',
'newEmail' => 'null',
'idToken' => 'null'
);
//Setup cURL
$ch = curl_init('https://www.googleapis.com/identitytoolkit/v3/relyingparty/getOobConfirmationCode?key=xxxxxxxxxxxxxxxxxxxx');
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Authorization: '.$authToken,
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode($postData)
));
//Send Request
$response = curl_exec($ch);
答案 0 :(得分:3)
This documentation会向您展示如何为您的应用获取OAuth令牌。
但是,您可能会发现使用Identity Toolkit特定PHP client更容易。要生成忘记密码链接,您需要做的就是在初始化的GitkitClient上调用getOobResults()方法。