fastify / fastify-oauth2

Enable to perform login using oauth2 protocol
MIT License
243 stars 69 forks source link

feat: add function to health check #257

Open RodrigoDornelles opened 2 months ago

RodrigoDornelles commented 2 months ago

Prerequisites

🚀 Feature Proposal

enable function that own auth checks if client secrets and ID are correct, in addition to being connected to the openid server, it should false if there is a connection problem.

like this curl

curl -X POST \
  'https://example.com/auth/realms/seu-realm/protocol/openid-connect/token' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'grant_type=client_credentials&client_id=seu-client-id&client_secret=seu-client-secret'

Motivation

an application that is connected to multiple systems, it is interesting to obtain a report of each dependency that is online!

Example

server.get('/health', async function() {
    return {
      keycloak: !await server.keycloak.healthCheck(),
      opensearch: !(await checkError(server.opensearch.ping)),
    };
});
mcollina commented 2 months ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.