Handlers
Creating a Handler
It's incredibly simple to create a custom handler!
// my-custom-handler.ts
import { Handler } from '@salte-auth/salte-auth';
export class CustomHandler extends Handler {
/**
* This is the default name of the handler.
*/
get name() {
return 'iframe';
}
/**
* This determines whether the handler supports being automatically triggered
* Handlers that require user input such as '@salte-auth/tab'
* and '@salte-auth/popup' don't support this.
*/
get auto() {
return true;
}
/**
* This is invoked when `salte-auth` starts up.
*/
connected({ action }: Handler.ConnectedOptions): OAuth2Provider.Validation | OpenIDProvider.Validation | void {
// Generally this won't be needed, however in certain cases such
// as `@salte-auth/redirect` it's used to wrap up authentication.
}
/**
* This is invoked when the developer invokes `login` or `logout`
* The expected response is a promise with the parsed url parameters.
*
* For fully implemented examples check out our official handlers.
* https://salte-auth.gitbook.io/salte-auth/usage/handlers
*/
open({ url, redirectUrl }: Handler.OpenOptions): Promise<OAuth2Provider.Validation | OpenIDProvider.Validation> {
// For the given example: https://google.com?token=12345&state=54321
// This would be the expected response.
return Promise.resolve({
token: '12345',
state: '54321'
});
}
}Using your Custom Handler
It's equally as easy to use a custom handler.
Last updated
Was this helpful?