diff --git a/src/__tests__/fixtures/providers/azuread-auth.provider.ts b/src/__tests__/fixtures/providers/azuread-auth.provider.ts index a8cf649..0e94167 100644 --- a/src/__tests__/fixtures/providers/azuread-auth.provider.ts +++ b/src/__tests__/fixtures/providers/azuread-auth.provider.ts @@ -7,8 +7,6 @@ import {Request} from '@loopback/rest'; export class BearerTokenVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.AzureADAuthFn { return async ( accessToken: string, diff --git a/src/strategies/client-auth-strategy.provider.ts b/src/strategies/client-auth-strategy.provider.ts index e8b92c4..fade687 100644 --- a/src/strategies/client-auth-strategy.provider.ts +++ b/src/strategies/client-auth-strategy.provider.ts @@ -29,7 +29,9 @@ export class ClientAuthStrategyProvider this.clientMetadata.options as StrategyOptionsWithRequestInterface, ); } else { - return Promise.reject(`The strategy ${name} is not available.`); + return Promise.reject( + new Error(`The strategy ${name} is not available.`), + ); } } } diff --git a/src/strategies/passport/passport-apple-oauth2/apple-auth-strategy-factory-provider.ts b/src/strategies/passport/passport-apple-oauth2/apple-auth-strategy-factory-provider.ts index 73ef292..9cc6bf9 100644 --- a/src/strategies/passport/passport-apple-oauth2/apple-auth-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-apple-oauth2/apple-auth-strategy-factory-provider.ts @@ -1,25 +1,23 @@ import {inject, Provider} from '@loopback/core'; +import {AnyObject} from '@loopback/repository'; import {HttpErrors, Request} from '@loopback/rest'; import {HttpsProxyAgent} from 'https-proxy-agent'; -import { - Profile, +// eslint-disable-next-line @typescript-eslint/naming-convention +import Strategy, { AuthenticateOptions, AuthenticateOptionsWithRequest, - VerifyCallback, DecodedIdToken, + Profile, + VerifyCallback, } from 'passport-apple'; import {AuthErrorKeys} from '../../../error-keys'; import {Strategies} from '../../keys'; - import {VerifyFunction} from '../../types'; -// eslint-disable-next-line @typescript-eslint/naming-convention -import Strategy from 'passport-apple'; -export interface AppleAuthStrategyFactory { - ( - options: AuthenticateOptions | AuthenticateOptionsWithRequest, - verifierPassed?: VerifyFunction.AppleAuthFn, - ): Strategy; -} + +export type AppleAuthStrategyFactory = ( + options: AuthenticateOptions | AuthenticateOptionsWithRequest, + verifierPassed?: VerifyFunction.AppleAuthFn, +) => Strategy; export class AppleAuthStrategyFactoryProvider implements Provider @@ -109,8 +107,7 @@ export class AppleAuthStrategyFactoryProvider return strategy; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private _setupProxy(strategy: any) { + private _setupProxy(strategy: AnyObject) { // Setup proxy if any let httpsProxyAgent; if (process.env['https_proxy']) { @@ -119,6 +116,6 @@ export class AppleAuthStrategyFactoryProvider } else if (process.env['HTTPS_PROXY']) { httpsProxyAgent = new HttpsProxyAgent(process.env['HTTPS_PROXY']); strategy._oauth2.setAgent(httpsProxyAgent); - } + } else return; } } diff --git a/src/strategies/passport/passport-azure-ad/azuread-auth-verify.provider.ts b/src/strategies/passport/passport-azure-ad/azuread-auth-verify.provider.ts index 1219c41..f8bea20 100644 --- a/src/strategies/passport/passport-azure-ad/azuread-auth-verify.provider.ts +++ b/src/strategies/passport/passport-azure-ad/azuread-auth-verify.provider.ts @@ -11,8 +11,6 @@ import {VerifyFunction} from '../../types'; export class AzureADAuthVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.AzureADAuthFn { return async ( accessToken: string, diff --git a/src/strategies/passport/passport-bearer/bearer-token-verify.provider.ts b/src/strategies/passport/passport-bearer/bearer-token-verify.provider.ts index 1bc9921..22f5959 100644 --- a/src/strategies/passport/passport-bearer/bearer-token-verify.provider.ts +++ b/src/strategies/passport/passport-bearer/bearer-token-verify.provider.ts @@ -11,8 +11,6 @@ import {VerifyFunction} from '../../types'; export class BearerTokenVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.BearerFn { return async (token: string) => { throw new HttpErrors.NotImplemented( diff --git a/src/strategies/passport/passport-client-password/client-password-verify.provider.ts b/src/strategies/passport/passport-client-password/client-password-verify.provider.ts index 9618a8f..b6fc3b1 100644 --- a/src/strategies/passport/passport-client-password/client-password-verify.provider.ts +++ b/src/strategies/passport/passport-client-password/client-password-verify.provider.ts @@ -11,8 +11,6 @@ import {VerifyFunction} from '../../types'; export class ClientPasswordVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.OauthClientPasswordFn { return async (clientId: string, clientSecret: string) => { throw new HttpErrors.NotImplemented( diff --git a/src/strategies/passport/passport-cognito-oauth2/cognito-auth-verify.provider.ts b/src/strategies/passport/passport-cognito-oauth2/cognito-auth-verify.provider.ts index 602dc28..2c754af 100644 --- a/src/strategies/passport/passport-cognito-oauth2/cognito-auth-verify.provider.ts +++ b/src/strategies/passport/passport-cognito-oauth2/cognito-auth-verify.provider.ts @@ -10,8 +10,6 @@ import {Cognito, VerifyFunction} from '../../types'; export class CognitoAuthVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.CognitoAuthFn { return async ( accessToken: string, diff --git a/src/strategies/passport/passport-facebook-oauth2/facebook-auth-strategy-factory-provider.ts b/src/strategies/passport/passport-facebook-oauth2/facebook-auth-strategy-factory-provider.ts index a9917cc..9f4efe5 100644 --- a/src/strategies/passport/passport-facebook-oauth2/facebook-auth-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-facebook-oauth2/facebook-auth-strategy-factory-provider.ts @@ -1,4 +1,5 @@ import {inject, Provider} from '@loopback/core'; +import {AnyObject} from '@loopback/repository'; import {HttpErrors, Request} from '@loopback/rest'; import {HttpsProxyAgent} from 'https-proxy-agent'; import { @@ -7,7 +8,6 @@ import { StrategyOption, StrategyOptionWithRequest, } from 'passport-facebook'; - import {AuthErrorKeys} from '../../../error-keys'; import {Strategies} from '../../keys'; import {VerifyCallback, VerifyFunction} from '../../types'; @@ -99,8 +99,7 @@ export class FacebookAuthStrategyFactoryProvider return strategy; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private _setupProxy(strategy: any) { + private _setupProxy(strategy: AnyObject) { // Setup proxy if any let httpsProxyAgent; if (process.env['https_proxy']) { diff --git a/src/strategies/passport/passport-facebook-oauth2/facebook-auth-verify.provider.ts b/src/strategies/passport/passport-facebook-oauth2/facebook-auth-verify.provider.ts index 3bce569..0924415 100644 --- a/src/strategies/passport/passport-facebook-oauth2/facebook-auth-verify.provider.ts +++ b/src/strategies/passport/passport-facebook-oauth2/facebook-auth-verify.provider.ts @@ -11,8 +11,6 @@ import {VerifyCallback, VerifyFunction} from '../../types'; export class FacebookAuthVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.FacebookAuthFn { return async ( accessToken: string, diff --git a/src/strategies/passport/passport-google-oauth2/google-auth-strategy-factory-provider.ts b/src/strategies/passport/passport-google-oauth2/google-auth-strategy-factory-provider.ts index 1c176c5..1f7c151 100644 --- a/src/strategies/passport/passport-google-oauth2/google-auth-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-google-oauth2/google-auth-strategy-factory-provider.ts @@ -8,7 +8,7 @@ import { StrategyOptionsWithRequest, VerifyCallback, } from 'passport-google-oauth20'; - +import {AnyObject} from '@loopback/repository'; import {AuthErrorKeys} from '../../../error-keys'; import {Strategies} from '../../keys'; import {VerifyFunction} from '../../types'; @@ -97,8 +97,7 @@ export class GoogleAuthStrategyFactoryProvider return strategy; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private _setupProxy(strategy: any) { + private _setupProxy(strategy: AnyObject) { // Setup proxy if any let httpsProxyAgent; if (process.env['https_proxy']) { diff --git a/src/strategies/passport/passport-google-oauth2/google-auth-verify.provider.ts b/src/strategies/passport/passport-google-oauth2/google-auth-verify.provider.ts index 54fa76e..854ff9d 100644 --- a/src/strategies/passport/passport-google-oauth2/google-auth-verify.provider.ts +++ b/src/strategies/passport/passport-google-oauth2/google-auth-verify.provider.ts @@ -13,8 +13,6 @@ import {VerifyFunction} from '../../types'; export class GoogleAuthVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.GoogleAuthFn { return async ( accessToken: string, diff --git a/src/strategies/passport/passport-insta-oauth2/insta-auth-strategy-factory-provider.ts b/src/strategies/passport/passport-insta-oauth2/insta-auth-strategy-factory-provider.ts index 804f372..44603d4 100644 --- a/src/strategies/passport/passport-insta-oauth2/insta-auth-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-insta-oauth2/insta-auth-strategy-factory-provider.ts @@ -1,4 +1,5 @@ import {inject, Provider} from '@loopback/core'; +import {AnyObject} from '@loopback/repository'; import {HttpErrors, Request} from '@loopback/rest'; import {HttpsProxyAgent} from 'https-proxy-agent'; import { @@ -7,7 +8,6 @@ import { StrategyOption, StrategyOptionWithRequest, } from 'passport-instagram'; - import {AuthErrorKeys} from '../../../error-keys'; import {Strategies} from '../../keys'; import {VerifyCallback, VerifyFunction} from '../../types'; @@ -95,8 +95,7 @@ export class InstagramAuthStrategyFactoryProvider return strategy; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private _setupProxy(strategy: any) { + private _setupProxy(strategy: AnyObject) { // Setup proxy if any let httpsProxyAgent; if (process.env['https_proxy']) { diff --git a/src/strategies/passport/passport-insta-oauth2/insta-auth-verify.provider.ts b/src/strategies/passport/passport-insta-oauth2/insta-auth-verify.provider.ts index 00a17fe..91a0eea 100644 --- a/src/strategies/passport/passport-insta-oauth2/insta-auth-verify.provider.ts +++ b/src/strategies/passport/passport-insta-oauth2/insta-auth-verify.provider.ts @@ -11,8 +11,6 @@ import {VerifyCallback, VerifyFunction} from '../../types'; export class InstagramAuthVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.InstagramAuthFn { return async ( accessToken: string, diff --git a/src/strategies/passport/passport-keycloak/keycloak-verify.provider.ts b/src/strategies/passport/passport-keycloak/keycloak-verify.provider.ts index 3a882e1..58fcf0e 100644 --- a/src/strategies/passport/passport-keycloak/keycloak-verify.provider.ts +++ b/src/strategies/passport/passport-keycloak/keycloak-verify.provider.ts @@ -11,8 +11,6 @@ import {Keycloak, VerifyFunction} from '../../types'; export class KeycloakVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.KeycloakAuthFn { return async ( accessToken: string, diff --git a/src/strategies/passport/passport-local/local-password-verify.provider.ts b/src/strategies/passport/passport-local/local-password-verify.provider.ts index 37ada1e..b8a354c 100644 --- a/src/strategies/passport/passport-local/local-password-verify.provider.ts +++ b/src/strategies/passport/passport-local/local-password-verify.provider.ts @@ -11,8 +11,6 @@ import {VerifyFunction} from '../../types'; export class LocalPasswordVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.LocalPasswordFn { return async (username: string, password: string) => { throw new HttpErrors.NotImplemented( diff --git a/src/strategies/passport/passport-otp/otp-auth.ts b/src/strategies/passport/passport-otp/otp-auth.ts index be45726..2b51e90 100644 --- a/src/strategies/passport/passport-otp/otp-auth.ts +++ b/src/strategies/passport/passport-otp/otp-auth.ts @@ -1,11 +1,16 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ +import {AnyObject} from '@loopback/repository'; +import {Request} from '@loopback/rest'; import * as passport from 'passport'; export namespace Otp { export type VerifyFunction = ( key: string, otp: string, - done: (error: any, user?: any, info?: any) => void, + done: ( + error?: string | Error | null, + user?: AnyObject, + info?: AnyObject, + ) => void, ) => void; export interface StrategyOptions { @@ -15,8 +20,8 @@ export namespace Otp { export type VerifyCallback = ( err?: string | Error | null, - user?: any, - info?: any, + user?: AnyObject, + info?: AnyObject, ) => void; export class Strategy extends passport.Strategy { @@ -31,7 +36,7 @@ export namespace Otp { name: string; private readonly verify: VerifyFunction; - authenticate(req: any, options?: StrategyOptions): void { + authenticate(req: Request, options?: StrategyOptions): void { const key = req.body.key || options?.key; const otp = req.body.otp || options?.otp; @@ -40,7 +45,11 @@ export namespace Otp { return; } - const verified = (err?: any, user?: any, _info?: any) => { + const verified = ( + err?: string | Error | null, + user?: AnyObject, + _info?: AnyObject, + ) => { if (err) { this.error(err); return; diff --git a/src/strategies/passport/passport-otp/otp-verify.provider.ts b/src/strategies/passport/passport-otp/otp-verify.provider.ts index 2a379b9..0e7d3d7 100644 --- a/src/strategies/passport/passport-otp/otp-verify.provider.ts +++ b/src/strategies/passport/passport-otp/otp-verify.provider.ts @@ -4,8 +4,6 @@ import {HttpErrors} from '@loopback/rest'; import {VerifyFunction} from '../../types'; export class OtpVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.OtpAuthFn { return async (_key: string, _otp: string) => { throw new HttpErrors.NotImplemented( diff --git a/src/strategies/passport/passport-resource-owner-password/resource-owner-strategy-factory-provider.ts b/src/strategies/passport/passport-resource-owner-password/resource-owner-strategy-factory-provider.ts index c06d832..4bd2a96 100644 --- a/src/strategies/passport/passport-resource-owner-password/resource-owner-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-resource-owner-password/resource-owner-strategy-factory-provider.ts @@ -8,12 +8,10 @@ import {VerifyFunction} from '../../types'; import {Oauth2ResourceOwnerPassword} from './oauth2-resource-owner-password-grant'; import {isEmpty} from 'lodash'; -export interface ResourceOwnerPasswordStrategyFactory { - ( - options?: Oauth2ResourceOwnerPassword.StrategyOptionsWithRequestInterface, - verifierPassed?: VerifyFunction.ResourceOwnerPasswordFn, - ): Oauth2ResourceOwnerPassword.Strategy; -} +export type ResourceOwnerPasswordStrategyFactory = ( + options?: Oauth2ResourceOwnerPassword.StrategyOptionsWithRequestInterface, + verifierPassed?: VerifyFunction.ResourceOwnerPasswordFn, +) => Oauth2ResourceOwnerPassword.Strategy; export class ResourceOwnerPasswordStrategyFactoryProvider implements Provider diff --git a/src/strategies/passport/passport-resource-owner-password/resource-owner-verify.provider.ts b/src/strategies/passport/passport-resource-owner-password/resource-owner-verify.provider.ts index 1fde624..aaf5225 100644 --- a/src/strategies/passport/passport-resource-owner-password/resource-owner-verify.provider.ts +++ b/src/strategies/passport/passport-resource-owner-password/resource-owner-verify.provider.ts @@ -12,8 +12,6 @@ import {VerifyFunction} from '../../types'; export class ResourceOwnerVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.ResourceOwnerPasswordFn { return async (clientId, clientSecret, username, password) => { throw new HttpErrors.NotImplemented( diff --git a/src/strategies/user-auth-strategy.provider.ts b/src/strategies/user-auth-strategy.provider.ts index f8ceab9..2765550 100644 --- a/src/strategies/user-auth-strategy.provider.ts +++ b/src/strategies/user-auth-strategy.provider.ts @@ -313,7 +313,9 @@ export class AuthStrategyProvider implements Provider { return this.processSamlFactory(verifier); } default: - return Promise.reject(`The strategy ${name} is not available.`); + return Promise.reject( + new Error(`The strategy ${name} is not available.`), + ); } } } diff --git a/src/types.ts b/src/types.ts index 023cb82..f37198b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -42,9 +42,10 @@ export interface AuthenticationMetadata { * interface definition of a function which accepts a request * and returns an authenticated user */ -export interface AuthenticateFn { - (request: Request, response?: Response): Promise; -} +export type AuthenticateFn = ( + request: Request, + response?: Response, +) => Promise; export interface ClientAuthCode { clientId: string;