Authorizing a request¶
ZorgAPIs API uses OAuth 2.0 to ensure that client requests access data securely. With OAuth 2.0, you first retrieve an access token for the API, then use that token to authenticate future requests.
Info
When exploring our API, fork our Postman Collection and select Get New Access Token in the Authorization tab of a request. Postman will automatically populate the relevant parts of the request. To learn more, go to Authenticate with OAuth 2.0 authentication in Postman.
How the Authorization Code flow works¶
The example diagram below illustrates the interactions that occur during the OAuth 2.0 Authorization Code Grant flow.
sequenceDiagram
participant user as User
participant client as Application
participant idp as Authorization server
participant api as API
autonumber
activate user
user->>client: Access
activate client
client->>idp: Request authorization
deactivate client
activate idp
idp->>user: Show sign in page
user->>idp: Sign in with credentials
deactivate user
idp->>client: Issue authorization code
activate client
client->>idp: Request token
idp->>idp: Validate request
idp->>client: Return access token
deactivate idp
client->>api: Call API with access token
activate api
api->>client: Return data
deactivate api
client->>user: Display data
deactivate client
- A user tries to access the application (the client)
-
The application redirects to the authorization server's
auth
endpointhttps://auth.zorgapis.nl/realms/zorgapis/protocol/openid-connect/auth ?response_type=code &client_id=<client-id> <!-- (1)! --> &redirect_uri=<redirect-uri> <!-- (2)! --> &scope=<scopes> <!-- (3)! --> &state=<state>
- For example,
zorgapis.postman
. - For example,
https://oauth.pstmn.io/v1/browser-callback
. - For example,
api-requirements-versions:read
.
- For example,
-
The authorization server shows the sign in page
- The user signs in with its credentials
- The authorization server issues an authorization code to the application
-
The application requests an access token from the
token
endpoint -
The authorization server validates the request
- The authorization server returns the access token
- The application calls a protected API endpoint using the access token
- The API validates the access token and returns the data
- The application displays the data to the user