我正在尝试从我们的 fusionauth 服务器中检索 OAUTH2 令牌 1.16.1
通过 SAML 登录工作非常完美。登录页面 php 请求 /oauth2/authorize?并且重定向到 /callback 有效。
登录页面 php
$redirect_url = urlencode('http://test.eyecatcher.ch/callback');
$location = 'https://{auth domain}/oauth2/authorize?client_id={client id}&response_type=code&redirect_uri=' . $redirect_url;
header( "Location: " . $location );
在 fusionauth、OAuth 应用程序设置中,设置了“授权重定向 URL”。
不管输入哪个redirect_url,错误总是出现
回调页面php
$client_id = "{client id}";
$clientSecret = '{client secrect}';
$base64Auth = base64_encode($client_id . ":" . $clientSecret );
$code = $_GET[ "code" ];
$url = 'https://{auth domain}/oauth2/token';
$redirect_url = urlencode('http://test.eyecatcher.ch/callback');
$header = array( 'Authorization: Basic ' .$base64Auth .'',
'Content-Type: application/x-www-form-urlencoded' );
$post = [
'code' => $code,
'grant_type' => 'authorization_code',
'redirect_uri' => $redirect_url,
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header );
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
$response = curl_exec($ch);
var_export($response);
在此请求之后,我收到此错误消息。
{"error":"invalid_grant","error_description":"redirect_uri: http%3A%2F%2Ftest.eyecatcher.ch%2Fcallback is not valid.","error_reason":"invalid_redirect_uri"}