我使用GuzzleHTTP编写代码:
$clientToken = new \GuzzleHttp\Client();
$responseToken = $clientToken->request('post', 'https://myserwer.com/auth/realms/testrealm/protocol/openid-connect/token', [
'headers' => [
'User-Agent' => $_SERVER['HTTP_USER_AGENT'],
'Accept' => 'application/json'
],
'form_params' => [
'username' => 'user-test',
'password' => 'testpassword',
'grant_type' => 'password',
'client_id' => 'test-api',
'client_secret' => getenv("SECRET_KEYCLOAK")
]
]);
$json = json_decode($responseToken->getBody(), true);
$access_token = $json['access_token'];
$client = new \GuzzleHttp\Client();
$response = $client->request('put', 'https://myserwer.com/auth/admin/realms/testrealm/users/a9...d1/execute-actions-email', [
'headers' => [
'Authorization' => 'Bearer ' . $access_token,
'User-Agent' => $_SERVER['HTTP_USER_AGENT'],
'Content-Type' => 'application/json',
'Accept' => 'application/json'
],
'form_params' => [
json_encode([
'actions' => ['UPDATE_PASSWORD'],
])
]
]);
$status = $response->getStatusCode();
$header = $response->getHeaderLine('content-type');
$body = $response->getBody();
return response()->json($body);
我拥有服务授权,但我不知道我是否发送了所有数据。我使用方法PUT发送: 主体中的授权,用户代理,内容类型,接受和操作。 但是服务器仍然返回:
500内部服务器错误