drol55885602 2015-06-17 03:46
浏览 63
已采纳

Google Identity Toolkit会返回INVALID_CREDENTIALS

I'm currently trying to implement a forgot password feature using the Google Identity Toolkit. The PHP backend is trying to get the oob code because client (iOS) does not have sufficient privileges.

Whenever I run the script I get an error of INVALID_CREDENTIALS, more specifically:

oob Code: string(249) "{ "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Invalid Credentials" } } "

I am not sure where to get the authToken or whether this is sending the post request correctly.

$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);
  • 写回答

1条回答 默认 最新

  • douyun1860 2015-06-17 16:38
    关注

    This documentation on the Google API PHP client shows you how to get an OAuth token for your app.

    However, you will probably find it easier to use the Identity Toolkit specific PHP client. To generate the forgot-password link, all you need to do is call the getOobResults() method on an initialized GitkitClient.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决