loopback4-authentication
Version:
A loopback-next extension for authentication feature. Various Oauth strategies supported by this package.
70 lines (69 loc) • 4.29 kB
TypeScript
/// <reference types="passport" />
/// <reference types="express" />
import { AnyObject } from '@loopback/repository';
import { Request } from '@loopback/express';
import * as SamlStrategy from '@node-saml/passport-saml';
import * as AppleStrategy from 'passport-apple';
import { DecodedIdToken } from 'passport-apple';
import * as AzureADStrategy from 'passport-azure-ad';
import * as FacebookStrategy from 'passport-facebook';
import * as GoogleStrategy from 'passport-google-oauth20';
import * as InstagramStrategy from 'passport-instagram';
import * as Auth0Strategy from 'passport-auth0';
import { Auth0, Cognito, IAuthClient, IAuthSecureClient, IAuthUser } from '../../types';
import { Keycloak } from './keycloak.types';
import { Otp } from '../passport/passport-otp';
export type VerifyCallback = (err?: string | Error | null, user?: Express.User, info?: AnyObject) => void;
export declare namespace VerifyFunction {
interface OauthClientPasswordFn<T = IAuthClient> extends GenericAuthFn<T> {
(clientId: string, clientSecret: string, req?: Request): Promise<T | null>;
}
interface OauthSecureClientPasswordFn<T = IAuthSecureClient> extends GenericAuthFn<T> {
(clientId: string, clientSecret: string, req?: Request): Promise<T | null>;
}
interface LocalPasswordFn<T = IAuthUser> extends GenericAuthFn<T> {
(username: string, password: string, req?: Request): Promise<T | null>;
}
interface OtpAuthFn<T = IAuthUser> extends GenericAuthFn<T> {
(key: string, otp: string, cb: Otp.VerifyCallback): Promise<T | null>;
}
interface BearerFn<T = IAuthUser> extends GenericAuthFn<T> {
(token: string, req?: Request): Promise<T | null>;
}
type ResourceOwnerPasswordFn<T = IAuthClient, S = IAuthUser> = (clientId: string, clientSecret: string, username: string, password: string, req?: Request) => Promise<{
client: T;
user: S;
} | null>;
type SecureResourceOwnerPasswordFn<T = IAuthSecureClient, S = IAuthUser> = (clientId: string, clientSecret: string, username: string, password: string, req?: Request) => Promise<{
client: T;
user: S;
} | null>;
interface GoogleAuthFn<T = IAuthUser> extends GenericAuthFn<T> {
(accessToken: string, refreshToken: string, profile: GoogleStrategy.Profile, cb: GoogleStrategy.VerifyCallback, req?: Request): Promise<T | null>;
}
interface AzureADAuthFn<T = IAuthUser> extends GenericAuthFn<T> {
(accessToken: string, refreshToken: string, profile: AzureADStrategy.IProfile, done: AzureADStrategy.VerifyCallback, req?: Request): Promise<T | null>;
}
interface KeycloakAuthFn<T = IAuthUser> extends GenericAuthFn<T> {
(accessToken: string, refreshToken: string, profile: Keycloak.Profile, cb: (err?: string | Error, user?: IAuthUser) => void): Promise<T | null>;
}
interface InstagramAuthFn<T = IAuthUser> extends VerifyFunction.GenericAuthFn<T> {
(accessToken: string, refreshToken: string, profile: InstagramStrategy.Profile, cb: VerifyCallback, req?: Request): Promise<T | null>;
}
interface FacebookAuthFn<T = IAuthUser> extends VerifyFunction.GenericAuthFn<T> {
(accessToken: string, refreshToken: string, profile: FacebookStrategy.Profile, cb: VerifyCallback, req?: Request): Promise<T | null>;
}
interface CognitoAuthFn<T = IAuthUser> extends GenericAuthFn<T> {
(accessToken: string, refreshToken: string, profile: Cognito.Profile, cb: Cognito.VerifyCallback, req?: Request): Promise<T | null>;
}
interface Auth0Fn<T = IAuthUser> extends GenericAuthFn<T> {
(accessToken: string, refreshToken: string, profile: Auth0Strategy.Profile, cb: Auth0.VerifyCallback, req?: Request): Promise<T | null>;
}
interface AppleAuthFn<T = IAuthUser> extends GenericAuthFn<T> {
(accessToken: string, refreshToken: string, decodedIdToken: DecodedIdToken, profile: AppleStrategy.Profile, cb: AppleStrategy.VerifyCallback, req?: Request): Promise<T | null>;
}
interface SamlFn<T = IAuthUser> extends GenericAuthFn<T> {
(profile: SamlStrategy.Profile, cb: SamlStrategy.VerifiedCallback, req?: Request): Promise<T | null>;
}
type GenericAuthFn<T = any> = (...params: any) => Promise<T | null>;
}