0.2.14 • Published 1 year ago

@iad-os/aemon-oidc-introspect v0.2.14

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

OIDC Smart Introspect middleware

Add dependency to project

npm i @iad-os/aemon-oidc-introspect

Configure

import aemonOidcIntrospect from '@iad-os/aemon-oidc-introspect';

//...

const expressApp = express()
  // other middleware ...
  .use(
    aemonOidcIntrospect({
      issuers: [
        {
          issuer: 'https://XXX/auth/realms/YYY',
          introspection_endpoint:
            'https://XXX/auth/realms/YYY/protocol/openid-connect/token/introspect',
          client: {
            client_id: 'client_id',
            client_secret: 'aClientSecret',
          },
        },
      ],
      extractToken: (req: Request): string => {
        
        // Bearer token example (Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c)

        const authorization = req.headers['authorization'];
        if (!authorization) return;
        const [, token] = authorization.split(' ');
        return token;
      },
      doPost: async (
          req: Request,
          url: string,
          queryString: string,
          options?: { headers: Record<string, string> }
        ) => {
          return await axios.create().post(url, queryString, options);
        },
      logger: (req: Request, level: string, msg: string, payload?: any) =>
        logger[level](msg, payload),
    })
  );

Usage

const myMiddleware: RequestHandler = function (req, res, next) {
  // ... code here
  if (!req.uid) {
    logger.info('User IDentity not found.');
    return next(null);
  }

  sendEmail(req.uid.email)
};
0.2.14

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.10

2 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago