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 namespace VerifyFunction { export interface OauthClientPasswordFn< T = IAuthClient, > extends GenericAuthFn { (clientId: string, clientSecret: string, req?: Request): Promise; } export interface OauthSecureClientPasswordFn< T = IAuthSecureClient, > extends GenericAuthFn { (clientId: string, clientSecret: string, req?: Request): Promise; } export interface LocalPasswordFn extends GenericAuthFn { (username: string, password: string, req?: Request): Promise; } export interface OtpAuthFn extends GenericAuthFn { (key: string, otp: string, cb: Otp.VerifyCallback): Promise; } export interface BearerFn extends GenericAuthFn { (token: string, req?: Request): Promise; } export type ResourceOwnerPasswordFn = ( clientId: string, clientSecret: string, username: string, password: string, req?: Request, ) => Promise<{client: T; user: S} | null>; export type SecureResourceOwnerPasswordFn< T = IAuthSecureClient, S = IAuthUser, > = ( clientId: string, clientSecret: string, username: string, password: string, req?: Request, ) => Promise<{client: T; user: S} | null>; export interface GoogleAuthFn extends GenericAuthFn { ( accessToken: string, refreshToken: string, profile: GoogleStrategy.Profile, cb: GoogleStrategy.VerifyCallback, req?: Request, ): Promise; } export interface AzureADAuthFn extends GenericAuthFn { ( accessToken: string, refreshToken: string, profile: AzureADStrategy.IProfile, done: AzureADStrategy.VerifyCallback, req?: Request, ): Promise; } export interface KeycloakAuthFn extends GenericAuthFn { ( accessToken: string, refreshToken: string, profile: Keycloak.Profile, cb: (err?: string | Error, user?: IAuthUser) => void, ): Promise; } export interface InstagramAuthFn< T = IAuthUser, > extends VerifyFunction.GenericAuthFn { ( accessToken: string, refreshToken: string, profile: InstagramStrategy.Profile, cb: VerifyCallback, req?: Request, ): Promise; } export interface FacebookAuthFn< T = IAuthUser, > extends VerifyFunction.GenericAuthFn { ( accessToken: string, refreshToken: string, profile: FacebookStrategy.Profile, cb: VerifyCallback, req?: Request, ): Promise; } export interface CognitoAuthFn extends GenericAuthFn { ( accessToken: string, refreshToken: string, profile: Cognito.Profile, cb: Cognito.VerifyCallback, req?: Request, ): Promise; } export interface Auth0Fn extends GenericAuthFn { ( accessToken: string, refreshToken: string, profile: Auth0Strategy.Profile, cb: Auth0.VerifyCallback, req?: Request, ): Promise; } export interface AppleAuthFn extends GenericAuthFn { ( accessToken: string, refreshToken: string, decodedIdToken: DecodedIdToken, profile: AppleStrategy.Profile, cb: AppleStrategy.VerifyCallback, req?: Request, ): Promise; } export interface SamlFn extends GenericAuthFn { ( profile: SamlStrategy.Profile, cb: SamlStrategy.VerifiedCallback, req?: Request, ): Promise; } // eslint-disable-next-line @typescript-eslint/no-explicit-any export type GenericAuthFn = (...params: any) => Promise; // NOSONAR }