From 23ae356b00ec3c971dfb8a782c3db95b8044766d Mon Sep 17 00:00:00 2001 From: Rashi Sharma Date: Wed, 8 Jan 2025 12:31:10 +0530 Subject: [PATCH] docs(docs): update README.md file 256 --- README.md | 37 +++++++++++++++++++++++++++++++++++++ docs/README.md | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/README.md b/README.md index d0500bc..809d86f 100644 --- a/README.md +++ b/README.md @@ -2978,6 +2978,43 @@ this.component(AuthenticationComponent); This binding needs to be done before adding the Authentication component to your application. Apart from this all other steps for authentication for all strategies remain the same. +### Custom Sequence Support + +You can also configure `ClientAuthenticationMiddlewareProvider` and `UserAuthenticationMiddlewareProvider` options, which can be invoked using a custom sequence. See the sample below. + +```ts title="custom-sequence.ts" +export class CustomSequence implements SequenceHandler { + @inject(SequenceActions.INVOKE_MIDDLEWARE, {optional: true}) + protected invokeMiddleware: InvokeMiddleware = () => false; + ... + + async handle(context: RequestContext) { + ... + ... + // call custom registered middlewares in the pre-invoke chain + let finished = await this.invokeMiddleware(context, { + chain: CustomMiddlewareChain.PRE_INVOKE, + }); + if (finished) return; + const result = await this.invoke(route, args); + this.send(response, result); + ... + } +} +``` + +```ts title="application.ts" +import {ClientAuthenticationMiddlewareProvider} from 'loopback4-authentication'; +... +... + +// bind middleware with custom options +this.middleware(ClientAuthenticationMiddlewareProvider, { + chain: CustomMiddlwareChain.PRE_INVOKE +}); + +``` + ### Passport Auth0 In order to use it, run `npm install passport-auth0` and `npm install @types/passport-auth0`. diff --git a/docs/README.md b/docs/README.md index d0500bc..eaf52ab 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2978,6 +2978,42 @@ this.component(AuthenticationComponent); This binding needs to be done before adding the Authentication component to your application. Apart from this all other steps for authentication for all strategies remain the same. +### Custom Sequence Support + +You can also configure `ClientAuthenticationMiddlewareProvider` and `UserAuthenticationMiddlewareProvider` options, which can be invoked using a custom sequence. See the sample below. + +```ts title="custom-sequence.ts" +export class CustomSequence implements SequenceHandler { + @inject(SequenceActions.INVOKE_MIDDLEWARE, {optional: true}) + protected invokeMiddleware: InvokeMiddleware = () => false; + ... + + async handle(context: RequestContext) { + ... + ... + // call custom registered middlewares in the pre-invoke chain + let finished = await this.invokeMiddleware(context, { + chain: CustomMiddlewareChain.PRE_INVOKE, + }); + if (finished) return; + const result = await this.invoke(route, args); + this.send(response, result); + ... + } +} +``` + +```ts title="application.ts" +import {ClientAuthenticationMiddlewareProvider} from 'loopback4-authentication'; +... +... +// bind middleware with custom options +this.middleware(ClientAuthenticationMiddlewareProvider, { + chain: CustomMiddlwareChain.PRE_INVOKE +}); + +``` + ### Passport Auth0 In order to use it, run `npm install passport-auth0` and `npm install @types/passport-auth0`.