@salesforce/b2c-tooling-sdk / cli / AuthMiddlewareHook
Type Alias: AuthMiddlewareHook
AuthMiddlewareHook =
Hook<"b2c:auth-middleware">
Defined in: packages/b2c-tooling-sdk/src/cli/hooks.ts:331
Hook type for b2c:auth-middleware.
Implement this hook in your oclif plugin to provide custom middleware that will be applied to OAuth token requests.
The hook is called during command initialization, after flags are parsed but before any authentication is performed.
Plugin Registration
Register the hook in your plugin's package.json:
json
{
"oclif": {
"hooks": {
"b2c:auth-middleware": "./dist/hooks/auth-middleware.js"
}
}
}Hook Context
Inside the hook function, you have access to:
this.config- oclif Config objectthis.debug(),this.log(),this.warn(),this.error()- logging methods
Example
typescript
import type { AuthMiddlewareHook } from '@salesforce/b2c-tooling-sdk/cli';
import type { AuthMiddlewareProvider } from '@salesforce/b2c-tooling-sdk/auth';
const hook: AuthMiddlewareHook = async function(options) {
this.debug('Registering auth middleware');
const userAgentProvider: AuthMiddlewareProvider = {
name: 'custom-user-agent',
getMiddleware() {
return {
onRequest({ request }) {
request.headers.set('User-Agent', 'my-app/1.0');
return request;
},
};
},
};
return { providers: [userAgentProvider] };
};
export default hook;