Tutorial: C# Application-restricted RESTful APIs - signed JWT authentication


I was capable of finishing open-access and API key authentication tutorials (for both I got the following json response from the Hello World API):

“message”: “Hello Application!”

I need your help in order to complete Application-restricted RESTful APIs - signed JWT authentication tutorial.

I followed the tutorial: Signed JWT authentication - C# tutorial - NHS Digital

  1. Link Application-restricted RESTful APIs - signed JWT authentication - NHS Digital teaches how to generate a key pair ( Generate your own private/public key pair - for production or test environments)

  2. I upload my public key (the json file generated by the bash shell) to my developer account.

  3. I downloaded Git examples and opened application-restricted-signed-jwt-tutorials C# project.

  4. I changed the code here:
    4.1. var tokenUrl = “https:// sandbox .api.service.nhs.uk/oauth2/token” (without the spaces);
    4.2. var privateKeyFile = “PRIVATE_KEY_MY_PC_FULL_PATH_AND_NAME” (Here, I changed the file name from MY_KID.pem to MY_KID.key because of the JwtHandler method);
    4.3. var clientId = “MY_API_KEY”;
    4.4. var kid = “MY_KID”;
    4.5. var endpoint = “https:// sandbox . api .service.nhs.uk/hello-world/hello/application” (without the spaces);

  5. I ran the code and I got the following answer in AccessToken method:
    5.1. StatusCode: 401;
    5.2. ReasonPhrase: ‘Unauthorized’;
    5.3. Version: 1.1;
    5.4. Content: System.Net.Http.HttpConnectionResponseContent;

Can you help me?

Thank you.

Best regards,

Tiago Marçal


I was able to solve the problem.

To solve the problem, I logon into my developer hub account, and edit my application, sandbox environment.
There, I clicked “Enable” for the API with name “hello-world - Application Restricted (Sandbox)” and description “hello-world - Application Restricted (Sandbox)”. Finally, I clicked in the save button and a check symbol appears after column description.

Note: I had already tried to enable the API, but together with another application (hello-world - Hello World (Sandbox)). In this case, clicking in the save button didn’t enable the APIs.

1 Like

Thank you for sharing the solution!