Error with NHS Login Sandpit Api

I am trying to get access token for NHS login in sandbox environment
using below url

I am getting below error
{“error”: “invalid_request”}

how to find error reason ?

Hi, Rajkamal,

maybe better to share the all info you used to request.

$request_params = array(
‘client_id’ => ‘f11b9123-xxxxxx-4139-bd8f-xxxxxxxxxxxx’, // application id
‘redirect_uri’ => base_url(‘page/nhs_authorize_callback’),
‘response_type’ => ‘code’,
‘scope’ => ‘openid profile phone email basic_demographics profile_extended’,
‘state’ => ‘appstate’,
‘nonce’ => ‘randomnonce’
); redirect(‘auth .sandpit .signin .nhs .uk/authorize?’.http_build_query($request_params));

After redirect

$payload = [
“iss”=> ‘f11b9123-xxxxx-4139-bd8f-xxxxxxxxxx’, // application id
“sub”=> ‘f11b9123-xxxx-4139-bd8f-xxxxxxxxxxxx’,
“aud”=> ‘auth .sandpit .signin .nhs .uk/token’,
“jti”=> (string)rand(9999,99999999),
“exp”=> time() + 300,
$private_key = file_get_contents(FCPATH . “/keys/local/jwtxxxx.key”);
$jwt_token = JWTPerformer::getJWTToken($payload, $private_key, “RS512”);

$post_fields = http_build_query([
‘code’=> $inputs[‘code’],
‘client_id’ => ‘f11b9123-xxxxx-4139-bd8f-xxxxxxxxxx’,
‘redirect_uri’=> base_url(‘page/nhs_authorize_callback’),
‘grant_type’=> ‘authorization_code’,
‘client_assertion_type’=> ‘urn:ietf:params:oauth:client-assertion-type:jwt-bearer’,
$headers = [‘Content-Type: application/x-www-form-urlencoded’];
$token_res = $this->nhs_lib->callCurlRequest(‘POST’, ‘auth .sandpit .signin .nhs .uk/token’,
$post_fields, $headers);

In $token_res i am getting below error with http status 400
{“error”: “invalid_request”}

1 Like