/hapi-google-oauth2-certs

Hapi Plugin to manage Google's oAuth2 certificates.

Primary LanguageJavaScript

Build Status npm version

Introduction

Registers a Hapi server method to retrieve Google oAuth2 certificates for validation of ID tokens. Since certificates do not change frequently, they are cached using Hapi's native cache for 24 hours to eliminate unnecessary network calls.

Usage

Register this plugin:

server.register({ register: require('hapi-google-oauth2-certs') }, function (err) {
    if (err) {
        console.error('Failed to load plugin:', err);
    }
});

Retrieve a certificate:

server.methods.auth.google.getCertificate('someCertificateId', function (err, certificate) {
    if (err) {
        // Handle error
    }
    
    // Use certificate
});