api-example-nodejs-client is a sample Node.js application that provides a reference implementation of a HMRC client application.
It accesses three endpoints, each with their own authorisation requirements:
- Hello World - an Open endpoint that responds with the message “Hello World!”
- Hello Application - an Application-restricted endpoint that responds with the message “Hello Application!”
- Hello User - a User-restricted endpoint (accessed using an OAuth 2.0 token) that responds with the message “Hello User!”
The implementation of the Hello User flow requests an OAuth 2.0 token and subsequently uses that token to access the dummy secured endpoint.
API documentation is available on the HMRC Developer Hub.
- Register for a developer account on the HMRC Developer Hub
- Create a new application on the Developer Hub, and when prompted to subscribe to some APIs select the Hello World API only
- Once the application has been created you will be given a Client ID and prompted to generate a Client Secret - take note of both these values
- Select your application from the View all applications page
- Select the Redirect URIs link and then click Add a redirect URL
- Enter the URI value
http://localhost:8080/oauth20/callback
- Within your local copy of this project, edit the app.js file, updating the
clientId
andclientSecret
variables with the values noted previously
The node dependencies can be installed locally by running:
npm install
The server can be started with the following command:
npm start
Once running, the application will be available here.
This code is open source software licensed under the Apache 2.0 License.