我正在尝试向 League/oauth2-client 的身份验证请求和令牌请求添加一些键/值
在邮递员中它看起来像这样:
我尝试将它们作为 GET 添加到 auth/token url 中,但这不起作用.. 我也尝试了一些其他的东西,但没有成功..
事实证明库并不是真正需要的..对于身份验证请求,您可以执行如下简单的网址:
function getRandomAuthState($length = 32) {
return bin2hex(random_bytes($length / 2));
}
$url = $urlAuthorize;
$url .= '?state='.getRandomAuthState();
$url .= '&token_content_type=jwt';
$url .= '&response_type=code';
$url .= '&approval_prompt=auto';
$url .= '&redirect_uri='.$redirectUri;
$url .= '&client_id='.$clientId;
header('Location: ' . $url);
对于令牌,你可以像这样使用curl
if (isset($_GET['code'])) {
$code = $_GET['code'];
$data = array(
'client_id'=>$clientId,
'client_secret'=>$clientSecret,
'redirect_uri'=>$redirectUri,
'grant_type'=>'authorization_code',
'code'=>$code,
'token_content_type'=>'jwt',
);
$body = http_build_query($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlAccessToken );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $body );
curl_setopt($ch, CURLOPT_HTTPHEADER, array("application\/x-www-form-urlencoded"));
$response = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
print_r($response);
}