我似乎错过了oauth2的一些东西.我得到access_token但不是id_token!
我通过传递给我的"代码"来使用以下内容来获取google access_token https://accounts.google.com/o/oauth2/auth
$oauth2token_url = "https://accounts.google.com/o/oauth2/token";
$clienttoken_post = array(
"code" => $code,
"client_id" => $client_id,
"client_secret" => $client_secret,
"redirect_uri" => $redirect_uri,
"grant_type" => "authorization_code"
);
$curl = curl_init($oauth2token_url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clienttoken_post);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$json_response = curl_exec($curl);
curl_close($curl);
var_dump($json_response);
Run Code Online (Sandbox Code Playgroud)
一切似乎都有效,但根据谷歌的文档https://developers.google.com/accounts/docs/OAuth2Login#exchangecode我应该得到access_token, id_token, expires_in, token_type我做的除了id_token
var_dump($json_response); 显示以下内容:
string(126) "{ "access_token" : "ya29.AHES6ZSGlHVW9qA23xs8bHBP578Ef8S5cntJIcPT_SHWA", "token_type" : "Bearer", "expires_in" : 3598 }
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?
我有 v-for 循环,其中的元素有 :click 调用函数。该功能会在页面加载时的每个元素上自动触发!
<li v-if="itemSaved.length > 0" v-for="(item, index) in items" class="list-group-item">
<div class="pull-right m-l">
<i v-if="itemSaved[index] == 'not saved'" class="icon-plus" :click="addItem(item.id)"></i>
<i v-else class="icon-check" :click="removeItem(item.id)"></i>
</div>
</li>
export default {
data: () => ({
itemSaved: [{"id":1, "name":"Jim"},{"id":2, "name":"Max"}]
}),
methods: {
addItem: function(id){
console.log('add item ' + id)
},
removeItem: function(id){
console.log('remove item ' + id)
}
}
}
Run Code Online (Sandbox Code Playgroud)
基本上我在控制台日志中得到了add item 1和的列表add item 2