From 5b68b5a3a8b8a8b24d6912de7892bd2dcd11c925 Mon Sep 17 00:00:00 2001 From: arpit1503khanna Date: Fri, 4 Aug 2023 17:13:41 +0530 Subject: [PATCH 1/3] fix(chore): resolving sonar smells to improve quality gate resolving sonar smells to improve quality gate GH-142 --- .../SAML/saml-strategy-factory-provider.ts | 7 +- src/strategies/SAML/saml-verify.provider.ts | 4 - .../apple-auth-strategy-factory-provider.ts | 2 +- .../apple-auth-verify.provider.ts | 2 - .../azuread-auth-strategy-factory-provider.ts | 129 +++++++++--------- .../bearer-strategy-factory-provider.ts | 117 ++++++++-------- ...ient-password-strategy-factory-provider.ts | 48 +++---- .../client-password-strategy.ts | 22 ++- ...ient-password-strategy-factory-provider.ts | 51 ++++--- .../cognito-auth-strategy-factory-provider.ts | 14 +- ...facebook-auth-strategy-factory-provider.ts | 14 +- .../google-auth-strategy-factory-provider.ts | 14 +- .../insta-auth-strategy-factory-provider.ts | 14 +- .../keycloak-strategy-factory-provider.ts | 12 +- ...ocal-password-strategy-factory-provider.ts | 125 ++++++++--------- .../passport/passport-otp/otp-auth.ts | 12 +- .../otp-strategy-factory.provider.ts | 34 ++--- .../oauth2-resource-owner-password-grant.ts | 52 ++++--- ...esource-owner-strategy-factory-provider.ts | 118 ++++++++-------- src/strategies/types/types.ts | 39 +++--- src/strategy-adapter.ts | 4 +- 21 files changed, 405 insertions(+), 429 deletions(-) diff --git a/src/strategies/SAML/saml-strategy-factory-provider.ts b/src/strategies/SAML/saml-strategy-factory-provider.ts index 6f6d3f6..a1443b8 100644 --- a/src/strategies/SAML/saml-strategy-factory-provider.ts +++ b/src/strategies/SAML/saml-strategy-factory-provider.ts @@ -14,9 +14,10 @@ import { import {AuthErrorKeys} from '../../error-keys'; import {Strategies} from '../../keys'; import {VerifyFunction} from '../../types'; -export interface SamlStrategyFactory { - (options: SamlConfig, verifierPassed?: VerifyFunction.SamlFn): Strategy; -} +export type SamlStrategyFactory = ( + options: SamlConfig, + verifierPassed?: VerifyFunction.SamlFn, +) => Strategy; export class SamlStrategyFactoryProvider implements Provider diff --git a/src/strategies/SAML/saml-verify.provider.ts b/src/strategies/SAML/saml-verify.provider.ts index 48baf7d..64559a9 100644 --- a/src/strategies/SAML/saml-verify.provider.ts +++ b/src/strategies/SAML/saml-verify.provider.ts @@ -12,10 +12,6 @@ import {VerifyFunction} from '../../types'; * It will just throw an error saying Not Implemented */ export class SamlVerifyProvider implements Provider { - constructor() { - //This is intentional - } - value(): VerifyFunction.SamlFn { return async ( profile: SamlStrategy.Profile, 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 30997b6..73ef292 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 @@ -40,7 +40,7 @@ export class AppleAuthStrategyFactoryProvider ): Strategy { const verifyFn = verifierPassed ?? this.verifierAppleAuth; let strategy; - if (options && options.passReqToCallback === true) { + if (options?.passReqToCallback === true) { strategy = new Strategy( options, diff --git a/src/strategies/passport/passport-apple-oauth2/apple-auth-verify.provider.ts b/src/strategies/passport/passport-apple-oauth2/apple-auth-verify.provider.ts index 8deadb8..e8b0439 100644 --- a/src/strategies/passport/passport-apple-oauth2/apple-auth-verify.provider.ts +++ b/src/strategies/passport/passport-apple-oauth2/apple-auth-verify.provider.ts @@ -10,8 +10,6 @@ import {VerifyFunction} from '../../types'; export class AppleAuthVerifyProvider implements Provider { - constructor() {} - value(): VerifyFunction.AppleAuthFn { return async ( accessToken: string, diff --git a/src/strategies/passport/passport-azure-ad/azuread-auth-strategy-factory-provider.ts b/src/strategies/passport/passport-azure-ad/azuread-auth-strategy-factory-provider.ts index d655697..3771ea3 100644 --- a/src/strategies/passport/passport-azure-ad/azuread-auth-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-azure-ad/azuread-auth-strategy-factory-provider.ts @@ -12,12 +12,10 @@ import { IOIDCStrategyOptionWithoutRequest, } from 'passport-azure-ad'; -export interface AzureADAuthStrategyFactory { - ( - options: IOIDCStrategyOptionWithoutRequest | IOIDCStrategyOptionWithRequest, - verifierPassed?: VerifyFunction.AzureADAuthFn, - ): OIDCStrategy; -} +export type AzureADAuthStrategyFactory = ( + options: IOIDCStrategyOptionWithoutRequest | IOIDCStrategyOptionWithRequest, + verifierPassed?: VerifyFunction.AzureADAuthFn, +) => OIDCStrategy; export class AzureADAuthStrategyFactoryProvider implements Provider @@ -31,6 +29,61 @@ export class AzureADAuthStrategyFactoryProvider return (options, verifier) => this.getAzureADAuthStrategyVerifier(options, verifier); } + createCallbackWithReq(verifyFn: VerifyFunction.AzureADAuthFn) { + return async ( + req: Request, + iss: string, + sub: string, + profile: IProfile, + accessToken: string, + refreshToken: string, + done: VerifyCallback, + ) => { + if (!profile.oid) { + return done(new Error('No oid found'), null); + } + + try { + const user = await verifyFn( + accessToken, + refreshToken, + profile, + done, + req, + ); + if (!user) { + throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials); + } + done(null, user); + } catch (err) { + done(err); + } + }; + } + createCallbackWithoutReq(verifyFn: VerifyFunction.AzureADAuthFn) { + return async ( + iss: string, + sub: string, + profile: IProfile, + accessToken: string, + refreshToken: string, + done: VerifyCallback, + ) => { + if (!profile.oid) { + return done(new Error('No oid found'), null); + } + + try { + const user = await verifyFn(accessToken, refreshToken, profile, done); + if (!user) { + throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials); + } + done(null, user); + } catch (err) { + done(err); + } + }; + } getAzureADAuthStrategyVerifier( options: IOIDCStrategyOptionWithoutRequest | IOIDCStrategyOptionWithRequest, @@ -40,74 +93,14 @@ export class AzureADAuthStrategyFactoryProvider if (options && options.passReqToCallback === true) { return new OIDCStrategy( options, - // eslint-disable-next-line @typescript-eslint/no-misused-promises - async ( - req: Request, - iss: string, - sub: string, - profile: IProfile, - accessToken: string, - refreshToken: string, - done: VerifyCallback, - ) => { - if (!profile.oid) { - return done(new Error('No oid found'), null); - } - - try { - const user = await verifyFn( - accessToken, - refreshToken, - profile, - done, - req, - ); - if (!user) { - throw new HttpErrors.Unauthorized( - AuthErrorKeys.InvalidCredentials, - ); - } - done(null, user); - } catch (err) { - done(err); - } - }, + this.createCallbackWithReq(verifyFn), ); } else if (options && options.passReqToCallback === false) { return new OIDCStrategy( options, - // eslint-disable-next-line @typescript-eslint/no-misused-promises - async ( - iss: string, - sub: string, - profile: IProfile, - accessToken: string, - refreshToken: string, - done: VerifyCallback, - ) => { - if (!profile.oid) { - return done(new Error('No oid found'), null); - } - - try { - const user = await verifyFn( - accessToken, - refreshToken, - profile, - done, - ); - if (!user) { - throw new HttpErrors.Unauthorized( - AuthErrorKeys.InvalidCredentials, - ); - } - done(null, user); - } catch (err) { - done(err); - } - }, + this.createCallbackWithoutReq(verifyFn), ); } else { throw new Error('Invalid value for passReqToCallback'); diff --git a/src/strategies/passport/passport-bearer/bearer-strategy-factory-provider.ts b/src/strategies/passport/passport-bearer/bearer-strategy-factory-provider.ts index b861b50..46d0f44 100644 --- a/src/strategies/passport/passport-bearer/bearer-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-bearer/bearer-strategy-factory-provider.ts @@ -9,12 +9,10 @@ import {Strategies} from '../../keys'; import {VerifyFunction} from '../../types'; import {isEmpty} from 'lodash'; -export interface BearerStrategyFactory { - ( - options?: PassportBearer.IStrategyOptions, - verifierPassed?: VerifyFunction.BearerFn, - ): PassportBearer.Strategy; -} +export type BearerStrategyFactory = ( + options?: PassportBearer.IStrategyOptions, + verifierPassed?: VerifyFunction.BearerFn, +) => PassportBearer.Strategy; export class BearerStrategyFactoryProvider implements Provider @@ -29,6 +27,61 @@ export class BearerStrategyFactoryProvider this.getBearerStrategyVerifier(options, verifier); } + getBearerStrategyVerifierWithRequest(verifyFn: VerifyFunction.BearerFn) { + return async ( + req: Request, + token: string, + cb: (err: Error | null, user?: IAuthUser | false) => void, + ) => { + try { + const user = await verifyFn(token, req); + if (!user) { + throw new HttpErrors.Unauthorized(AuthErrorKeys.TokenInvalid); + } + cb(null, user); + } catch (err) { + cb(err); + } + }; + } + + getBearerStrategyVerifierWithoutRequest(verifyFn: VerifyFunction.BearerFn) { + return async ( + token: string, + cb: (err: Error | null, user?: IAuthUser | false) => void, + ) => { + try { + const user = await verifyFn(token); + if (!user) { + throw new HttpErrors.Unauthorized(AuthErrorKeys.TokenInvalid); + } + cb(null, user); + } catch (err) { + cb(err); + } + }; + } + getBearerStrategyVerifierDefault( + verifyFn: VerifyFunction.BearerFn, + ): PassportBearer.Strategy { + return new PassportBearer.Strategy( + // eslint-disable-next-line @typescript-eslint/no-misused-promises + async ( + token: string, + cb: (err: Error | null, user?: IAuthUser | false) => void, + ) => { + try { + const user = await verifyFn(token); + if (!user) { + throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials); + } + cb(null, user); + } catch (err) { + cb(err); + } + }, + ); + } getBearerStrategyVerifier( options?: PassportBearer.IStrategyOptions, verifierPassed?: VerifyFunction.BearerFn, @@ -38,62 +91,16 @@ export class BearerStrategyFactoryProvider return new PassportBearer.Strategy( options, // eslint-disable-next-line @typescript-eslint/no-misused-promises - async ( - req: Request, - token: string, - cb: (err: Error | null, user?: IAuthUser | false) => void, - ) => { - try { - const user = await verifyFn(token, req); - if (!user) { - throw new HttpErrors.Unauthorized(AuthErrorKeys.TokenInvalid); - } - cb(null, user); - } catch (err) { - cb(err); - } - }, + this.getBearerStrategyVerifierWithRequest(verifyFn), ); } else if (!!options && !isEmpty(options)) { return new PassportBearer.Strategy( options, - // eslint-disable-next-line @typescript-eslint/no-misused-promises - async ( - token: string, - cb: (err: Error | null, user?: IAuthUser | false) => void, - ) => { - try { - const user = await verifyFn(token); - if (!user) { - throw new HttpErrors.Unauthorized(AuthErrorKeys.TokenInvalid); - } - cb(null, user); - } catch (err) { - cb(err); - } - }, + this.getBearerStrategyVerifierWithoutRequest(verifyFn), ); } else { - return new PassportBearer.Strategy( - // eslint-disable-next-line @typescript-eslint/no-misused-promises - async ( - token: string, - cb: (err: Error | null, user?: IAuthUser | false) => void, - ) => { - try { - const user = await verifyFn(token); - if (!user) { - throw new HttpErrors.Unauthorized( - AuthErrorKeys.InvalidCredentials, - ); - } - cb(null, user); - } catch (err) { - cb(err); - } - }, - ); + return this.getBearerStrategyVerifierDefault(verifyFn); } } } diff --git a/src/strategies/passport/passport-client-password/client-password-strategy-factory-provider.ts b/src/strategies/passport/passport-client-password/client-password-strategy-factory-provider.ts index ec0708b..0392fc9 100644 --- a/src/strategies/passport/passport-client-password/client-password-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-client-password/client-password-strategy-factory-provider.ts @@ -10,12 +10,10 @@ import {IAuthClient} from '../../../types'; import {Strategies} from '../../keys'; import {VerifyFunction} from '../../types'; -export interface ClientPasswordStrategyFactory { - ( - options?: ClientPasswordStrategy.StrategyOptionsWithRequestInterface, - verifierPassed?: VerifyFunction.OauthClientPasswordFn, - ): ClientPasswordStrategy.Strategy; -} +export type ClientPasswordStrategyFactory = ( + options?: ClientPasswordStrategy.StrategyOptionsWithRequestInterface, + verifierPassed?: VerifyFunction.OauthClientPasswordFn, +) => ClientPasswordStrategy.Strategy; export class ClientPasswordStrategyFactoryProvider implements Provider @@ -49,36 +47,38 @@ export class ClientPasswordStrategyFactoryProvider const verifyFn = verifierPassed ?? this.verifier; if (options?.passReqToCallback) { return new ClientPasswordStrategy.Strategy( - async ( + ( clientId: string, clientSecret: string | undefined, cb: (err: Error | null, client?: IAuthClient | null) => void, req: Request | undefined, - ) => { //NOSONAR - try { - const client = await verifyFn(clientId, clientSecret, req); - this.clientPasswordVerifierHelper(client, clientSecret); - cb(null, client); - } catch (err) { - cb(err); - } + ) => { + verifyFn(clientId, clientSecret, req) + .then((client) => { + this.clientPasswordVerifierHelper(client, clientSecret); + cb(null, client); + }) + .catch((err) => { + cb(err); + }); }, options, ); } else { return new ClientPasswordStrategy.Strategy( - async ( + ( clientId: string, clientSecret: string | undefined, cb: (err: Error | null, client?: IAuthClient | null) => void, - ) => { //NOSONAR - try { - const client = await verifyFn(clientId, clientSecret); - this.clientPasswordVerifierHelper(client, clientSecret); - cb(null, client); - } catch (err) { - cb(err); - } + ) => { + verifyFn(clientId, clientSecret) + .then((client) => { + this.clientPasswordVerifierHelper(client, clientSecret); + cb(null, client); + }) + .catch((err) => { + cb(err); + }); }, ); } diff --git a/src/strategies/passport/passport-client-password/client-password-strategy.ts b/src/strategies/passport/passport-client-password/client-password-strategy.ts index 76ce956..72c75e9 100644 --- a/src/strategies/passport/passport-client-password/client-password-strategy.ts +++ b/src/strategies/passport/passport-client-password/client-password-strategy.ts @@ -12,18 +12,16 @@ export interface StrategyOptionsWithRequestInterface { passReqToCallback: boolean; } -export interface VerifyFunctionWithRequest { - ( - clientId: string, - clientSecret: string | undefined, - done: ( - error: Error | null, - client?: IAuthSecureClient | IAuthClient | null, - info?: Object | undefined, - ) => void, - req?: express.Request, - ): void; -} +export type VerifyFunctionWithRequest = ( + clientId: string, + clientSecret: string | undefined, + done: ( + error: Error | null, + client?: IAuthSecureClient | IAuthClient | null, + info?: Object | undefined, + ) => void, + req?: express.Request, +) => void; export class Strategy extends passport.Strategy { constructor( diff --git a/src/strategies/passport/passport-client-password/secure-client-password-strategy-factory-provider.ts b/src/strategies/passport/passport-client-password/secure-client-password-strategy-factory-provider.ts index 9d5aca3..8516f39 100644 --- a/src/strategies/passport/passport-client-password/secure-client-password-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-client-password/secure-client-password-strategy-factory-provider.ts @@ -9,12 +9,10 @@ import {ClientType, IAuthSecureClient} from '../../../types'; import {Strategies} from '../../keys'; import {VerifyFunction} from '../../types'; -export interface SecureClientPasswordStrategyFactory { - ( - options?: ClientPasswordStrategy.StrategyOptionsWithRequestInterface, - verifierPassed?: VerifyFunction.OauthSecureClientPasswordFn, - ): ClientPasswordStrategy.Strategy; -} +export type SecureClientPasswordStrategyFactory = ( + options?: ClientPasswordStrategy.StrategyOptionsWithRequestInterface, + verifierPassed?: VerifyFunction.OauthSecureClientPasswordFn, +) => ClientPasswordStrategy.Strategy; export class SecureClientPasswordStrategyFactoryProvider implements Provider @@ -52,39 +50,38 @@ export class SecureClientPasswordStrategyFactoryProvider const verifyFn = verifierPassed ?? this.verifier; if (options?.passReqToCallback) { return new ClientPasswordStrategy.Strategy( - async ( + ( clientId: string, clientSecret: string | undefined, cb: (err: Error | null, client?: IAuthSecureClient | null) => void, req: Request | undefined, - ) => { //NOSONAR - try { - const client = await verifyFn(clientId, clientSecret, req); - this.secureClientPasswordVerifierHelper(client, clientSecret); - - cb(null, client); - } catch (err) { - cb(err); - } + ) => { + verifyFn(clientId, clientSecret, req) + .then((client) => { + this.secureClientPasswordVerifierHelper(client, clientSecret); + cb(null, client); + }) + .catch((err) => { + cb(err); + }); }, options, ); } else { return new ClientPasswordStrategy.Strategy( - async ( + ( clientId: string, clientSecret: string | undefined, cb: (err: Error | null, client?: IAuthSecureClient | null) => void, - ) => {// NOSONAR - try { - const client = await verifyFn(clientId, clientSecret); - - this.secureClientPasswordVerifierHelper(client, clientSecret); - - cb(null, client); - } catch (err) { - cb(err); - } + ) => { + verifyFn(clientId, clientSecret) + .then((client) => { + this.secureClientPasswordVerifierHelper(client, clientSecret); + cb(null, client); + }) + .catch((err) => { + cb(err); + }); }, ); } diff --git a/src/strategies/passport/passport-cognito-oauth2/cognito-auth-strategy-factory-provider.ts b/src/strategies/passport/passport-cognito-oauth2/cognito-auth-strategy-factory-provider.ts index 7cd4ae7..a076d2b 100644 --- a/src/strategies/passport/passport-cognito-oauth2/cognito-auth-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-cognito-oauth2/cognito-auth-strategy-factory-provider.ts @@ -7,12 +7,10 @@ import {Cognito, VerifyFunction} from '../../types'; const CognitoStrategy = require('passport-cognito-oauth2'); -export interface CognitoAuthStrategyFactory { - ( - options: Cognito.StrategyOptions, - verifierPassed?: VerifyFunction.CognitoAuthFn, - ): typeof CognitoStrategy; -} +export type CognitoAuthStrategyFactory = ( + options: Cognito.StrategyOptions, + verifierPassed?: VerifyFunction.CognitoAuthFn, +) => typeof CognitoStrategy; export class CognitoStrategyFactoryProvider implements Provider @@ -33,7 +31,7 @@ export class CognitoStrategyFactoryProvider ): typeof CognitoStrategy { const verifyFn = verifierPassed ?? this.verifierCognito; let strategy; - if (options && options.passReqToCallback === true) { + if (options?.passReqToCallback === true) { strategy = new CognitoStrategy( options, @@ -100,6 +98,8 @@ export class CognitoStrategyFactoryProvider } else if (process.env['HTTPS_PROXY']) { httpsProxyAgent = new HttpsProxyAgent(process.env['HTTPS_PROXY']); strategy._oauth2.setAgent(httpsProxyAgent); + } else { + //this is intentional } } } 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 1118119..a9917cc 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 @@ -16,12 +16,10 @@ interface ExtendedStrategyOption extends StrategyOption { passReqToCallback?: false; } -export interface FacebookAuthStrategyFactory { - ( - options: ExtendedStrategyOption | StrategyOptionWithRequest, - verifierPassed?: VerifyFunction.FacebookAuthFn, - ): Strategy; -} +export type FacebookAuthStrategyFactory = ( + options: ExtendedStrategyOption | StrategyOptionWithRequest, + verifierPassed?: VerifyFunction.FacebookAuthFn, +) => Strategy; export class FacebookAuthStrategyFactoryProvider implements Provider @@ -42,7 +40,7 @@ export class FacebookAuthStrategyFactoryProvider ): Strategy { const verifyFn = verifierPassed ?? this.verifierFacebookAuth; let strategy; - if (options && options.passReqToCallback === true) { + if (options?.passReqToCallback === true) { strategy = new Strategy( options, // eslint-disable-next-line @typescript-eslint/no-misused-promises @@ -111,6 +109,8 @@ export class FacebookAuthStrategyFactoryProvider } else if (process.env['HTTPS_PROXY']) { httpsProxyAgent = new HttpsProxyAgent(process.env['HTTPS_PROXY']); strategy._oauth2.setAgent(httpsProxyAgent); + } else { + //this is intentional } } } 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 2004c92..1c176c5 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 @@ -13,12 +13,10 @@ import {AuthErrorKeys} from '../../../error-keys'; import {Strategies} from '../../keys'; import {VerifyFunction} from '../../types'; -export interface GoogleAuthStrategyFactory { - ( - options?: StrategyOptions | StrategyOptionsWithRequest, - verifierPassed?: VerifyFunction.GoogleAuthFn, - ): Strategy; -} +export type GoogleAuthStrategyFactory = ( + options: StrategyOptions | StrategyOptionsWithRequest, + verifierPassed?: VerifyFunction.GoogleAuthFn, +) => Strategy; export class GoogleAuthStrategyFactoryProvider implements Provider @@ -39,7 +37,7 @@ export class GoogleAuthStrategyFactoryProvider ): Strategy { const verifyFn = verifierPassed ?? this.verifierGoogleAuth; let strategy; - if (options && options.passReqToCallback === true) { + if (options?.passReqToCallback === true) { strategy = new Strategy( options, @@ -109,6 +107,8 @@ export class GoogleAuthStrategyFactoryProvider } else if (process.env['HTTPS_PROXY']) { httpsProxyAgent = new HttpsProxyAgent(process.env['HTTPS_PROXY']); strategy._oauth2.setAgent(httpsProxyAgent); + } else { + //this is intentional } } } 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 5322f47..804f372 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 @@ -12,12 +12,10 @@ import {AuthErrorKeys} from '../../../error-keys'; import {Strategies} from '../../keys'; import {VerifyCallback, VerifyFunction} from '../../types'; -export interface InstagramAuthStrategyFactory { - ( - options: StrategyOption | StrategyOptionWithRequest, - verifierPassed?: VerifyFunction.InstagramAuthFn, - ): Strategy; -} +export type InstagramAuthStrategyFactory = ( + options: StrategyOption | StrategyOptionWithRequest, + verifierPassed?: VerifyFunction.InstagramAuthFn, +) => Strategy; export class InstagramAuthStrategyFactoryProvider implements Provider @@ -38,7 +36,7 @@ export class InstagramAuthStrategyFactoryProvider ): Strategy { const verifyFn = verifierPassed ?? this.verifierInstagramAuth; let strategy; - if (options && options.passReqToCallback === true) { + if (options?.passReqToCallback === true) { strategy = new Strategy( options, // eslint-disable-next-line @typescript-eslint/no-misused-promises @@ -107,6 +105,8 @@ export class InstagramAuthStrategyFactoryProvider } else if (process.env['HTTPS_PROXY']) { httpsProxyAgent = new HttpsProxyAgent(process.env['HTTPS_PROXY']); strategy._oauth2.setAgent(httpsProxyAgent); + } else { + //this is intentional } } } diff --git a/src/strategies/passport/passport-keycloak/keycloak-strategy-factory-provider.ts b/src/strategies/passport/passport-keycloak/keycloak-strategy-factory-provider.ts index 210e37a..ae87b10 100644 --- a/src/strategies/passport/passport-keycloak/keycloak-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-keycloak/keycloak-strategy-factory-provider.ts @@ -8,12 +8,10 @@ import {Keycloak, VerifyFunction} from '../../types'; export const KeycloakStrategy = require('@exlinc/keycloak-passport'); -export interface KeycloakStrategyFactory { - ( - options: Keycloak.StrategyOptions, - verifierPassed?: VerifyFunction.KeycloakAuthFn, - ): typeof KeycloakStrategy; -} +export type KeycloakStrategyFactory = ( + options: Keycloak.StrategyOptions, + verifierPassed?: VerifyFunction.KeycloakAuthFn, +) => typeof KeycloakStrategy; export class KeycloakStrategyFactoryProvider implements Provider @@ -127,6 +125,8 @@ export class KeycloakStrategyFactoryProvider } else if (process.env['HTTPS_PROXY']) { httpsProxyAgent = new HttpsProxyAgent(process.env['HTTPS_PROXY']); strategy._oauth2.setAgent(httpsProxyAgent); + } else { + //this is intentional } } } diff --git a/src/strategies/passport/passport-local/local-password-strategy-factory-provider.ts b/src/strategies/passport/passport-local/local-password-strategy-factory-provider.ts index b1fc661..e9f8ca8 100644 --- a/src/strategies/passport/passport-local/local-password-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-local/local-password-strategy-factory-provider.ts @@ -9,14 +9,12 @@ import {Strategies} from '../../keys'; import {VerifyFunction} from '../../types'; import {isEmpty} from 'lodash'; -export interface LocalPasswordStrategyFactory { - ( - options?: - | PassportLocal.IStrategyOptions - | PassportLocal.IStrategyOptionsWithRequest, - verifierPassed?: VerifyFunction.LocalPasswordFn, - ): PassportLocal.Strategy; -} +export type LocalPasswordStrategyFactory = ( + options?: + | PassportLocal.IStrategyOptions + | PassportLocal.IStrategyOptionsWithRequest, + verifierPassed?: VerifyFunction.LocalPasswordFn, +) => PassportLocal.Strategy; export class LocalPasswordStrategyFactoryProvider implements Provider @@ -30,7 +28,60 @@ export class LocalPasswordStrategyFactoryProvider return (options, verifier) => this.getLocalStrategyVerifier(options, verifier); } - + getLocalStrategyWithRequest(verifyFn: VerifyFunction.LocalPasswordFn) { + return async ( + req: Request, + username: string, + password: string, + cb: (err: Error | null, user?: IAuthUser | false) => void, + ) => { + try { + const user = await verifyFn(username, password, req); + if (!user) { + throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials); + } + cb(null, user); + } catch (err) { + cb(err); + } + }; + } + getLocalStrategyWithoutRequest(verifyFn: VerifyFunction.LocalPasswordFn) { + return async ( + username: string, + password: string, + cb: (err: Error | null, user?: IAuthUser | false) => void, + ) => { + try { + const user = await verifyFn(username, password); + if (!user) { + throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials); + } + cb(null, user); + } catch (err) { + cb(err); + } + }; + } + getLocalStrategyVerifierUndefinedRequest( + verifyFn: VerifyFunction.LocalPasswordFn, + ) { + return async ( + username: string, + password: string, + cb: (err: Error | null, user?: IAuthUser | false) => void, + ) => { + try { + const user = await verifyFn(username, password, undefined); + if (!user) { + throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials); + } + cb(null, user); + } catch (err) { + cb(err); + } + }; + } getLocalStrategyVerifier( options?: | PassportLocal.IStrategyOptions @@ -38,71 +89,23 @@ export class LocalPasswordStrategyFactoryProvider verifierPassed?: VerifyFunction.LocalPasswordFn, ): PassportLocal.Strategy { const verifyFn = verifierPassed ?? this.verifierLocal; + if (options?.passReqToCallback) { return new PassportLocal.Strategy( options, // eslint-disable-next-line @typescript-eslint/no-misused-promises - async ( - req: Request, - username: string, - password: string, - cb: (err: Error | null, user?: IAuthUser | false) => void, - ) => { - try { - const user = await verifyFn(username, password, req); - if (!user) { - throw new HttpErrors.Unauthorized( - AuthErrorKeys.InvalidCredentials, - ); - } - cb(null, user); - } catch (err) { - cb(err); - } - }, + this.getLocalStrategyWithRequest(verifyFn), ); } else if (!!options && !isEmpty(options)) { return new PassportLocal.Strategy( options, // eslint-disable-next-line @typescript-eslint/no-misused-promises - async ( - username: string, - password: string, - cb: (err: Error | null, user?: IAuthUser | false) => void, - ) => { - try { - const user = await verifyFn(username, password); - if (!user) { - throw new HttpErrors.Unauthorized( - AuthErrorKeys.InvalidCredentials, - ); - } - cb(null, user); - } catch (err) { - cb(err); - } - }, + this.getLocalStrategyWithoutRequest(verifyFn), ); } else { return new PassportLocal.Strategy( // eslint-disable-next-line @typescript-eslint/no-misused-promises - async ( - username: string, - password: string, - cb: (err: Error | null, user?: IAuthUser | false) => void, - ) => { - try { - const user = await verifyFn(username, password, undefined); - if (!user) { - throw new HttpErrors.Unauthorized( - AuthErrorKeys.InvalidCredentials, - ); - } - cb(null, user); - } catch (err) { - cb(err); - } - }, + this.getLocalStrategyVerifierUndefinedRequest(verifyFn), ); } } diff --git a/src/strategies/passport/passport-otp/otp-auth.ts b/src/strategies/passport/passport-otp/otp-auth.ts index bf16465..be45726 100644 --- a/src/strategies/passport/passport-otp/otp-auth.ts +++ b/src/strategies/passport/passport-otp/otp-auth.ts @@ -2,13 +2,11 @@ import * as passport from 'passport'; export namespace Otp { - export interface VerifyFunction { - ( - key: string, - otp: string, - done: (error: any, user?: any, info?: any) => void, - ): void; - } + export type VerifyFunction = ( + key: string, + otp: string, + done: (error: any, user?: any, info?: any) => void, + ) => void; export interface StrategyOptions { key?: string; diff --git a/src/strategies/passport/passport-otp/otp-strategy-factory.provider.ts b/src/strategies/passport/passport-otp/otp-strategy-factory.provider.ts index f37b1a4..b43d315 100644 --- a/src/strategies/passport/passport-otp/otp-strategy-factory.provider.ts +++ b/src/strategies/passport/passport-otp/otp-strategy-factory.provider.ts @@ -5,12 +5,10 @@ import {Strategies} from '../../keys'; import {VerifyFunction} from '../../types'; import {Otp} from './otp-auth'; -export interface PassportOtpStrategyFactory { - ( - options: Otp.StrategyOptions, - verifierPassed?: VerifyFunction.OtpAuthFn, - ): Otp.Strategy; -} +export type PassportOtpStrategyFactory = ( + options: Otp.StrategyOptions, + verifierPassed?: VerifyFunction.OtpAuthFn, +) => Otp.Strategy; export class PassportOtpStrategyFactoryProvider implements Provider @@ -32,17 +30,19 @@ export class PassportOtpStrategyFactoryProvider const verifyFn = verifierPassed ?? this.verifierOtp; return new Otp.Strategy( options, - // eslint-disable-next-line @typescript-eslint/no-misused-promises - async (key: string, otp: string, cb: Otp.VerifyCallback) => { - try { - const user = await verifyFn(key, otp); - if (!user) { - throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials); - } - cb(null, user); - } catch (err) { - cb(err); - } + (key: string, otp: string, cb: Otp.VerifyCallback) => { + verifyFn(key, otp) + .then((user) => { + if (!user) { + throw new HttpErrors.Unauthorized( + AuthErrorKeys.InvalidCredentials, + ); + } + cb(null, user); + }) + .catch((err) => { + cb(err); + }); }, ); } diff --git a/src/strategies/passport/passport-resource-owner-password/oauth2-resource-owner-password-grant.ts b/src/strategies/passport/passport-resource-owner-password/oauth2-resource-owner-password-grant.ts index e658bfd..9bf7372 100644 --- a/src/strategies/passport/passport-resource-owner-password/oauth2-resource-owner-password-grant.ts +++ b/src/strategies/passport/passport-resource-owner-password/oauth2-resource-owner-password-grant.ts @@ -7,34 +7,30 @@ export namespace Oauth2ResourceOwnerPassword { passReqToCallback: boolean; } - export interface VerifyFunctionWithRequest { - ( - req: Request, - clientId: string, - clientSecret: string, - username: string, - password: string, - done: ( - error: Error | null, - client?: IAuthClient | false, - info?: IAuthUser | false, - ) => void, - ): void; - } + export type VerifyFunctionWithRequest = ( + req: Request, + clientId: string, + clientSecret: string, + username: string, + password: string, + done: ( + error: Error | null, + client?: IAuthClient | false, + info?: IAuthUser | false, + ) => void, + ) => void; - export interface VerifyFunction { - ( - clientId: string, - clientSecret: string, - username: string, - password: string, - done: ( - error: Error | null, - client?: IAuthClient | false, - info?: IAuthUser | false, - ) => void, - ): void; - } + export type VerifyFunction = ( + clientId: string, + clientSecret: string, + username: string, + password: string, + done: ( + error: Error | null, + client?: IAuthClient | false, + info?: IAuthUser | false, + ) => void, + ) => void; export class Strategy extends passport.Strategy { constructor(verify: VerifyFunction); @@ -65,8 +61,6 @@ export namespace Oauth2ResourceOwnerPassword { authenticate(req: Request, options?: {}): void { if ( - /* eslint-disable @typescript-eslint/prefer-optional-chain */ - !req.body || !req.body?.['client_id'] || !req.body?.['username'] || !req.body?.['password'] 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 eaeae1c..2873027 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 @@ -33,73 +33,71 @@ export class ResourceOwnerPasswordStrategyFactoryProvider verifierPassed?: VerifyFunction.ResourceOwnerPasswordFn, ): Oauth2ResourceOwnerPassword.Strategy { const verifyFn = verifierPassed ?? this.verifierResourceOwner; + if (options?.passReqToCallback) { return new Oauth2ResourceOwnerPassword.Strategy( options, - // eslint-disable-next-line @typescript-eslint/no-misused-promises - async ( - req: Request, - clientId: string, - clientSecret: string, - username: string, - password: string, - cb: ( - err: Error | null, - client?: IAuthClient | false, - user?: IAuthUser | false, - ) => void, - ) => { - try { - const userInfo = await verifyFn( - clientId, - clientSecret, - username, - password, - req, - ); - if (!userInfo || isEmpty(userInfo)) { - throw new HttpErrors.Unauthorized( - AuthErrorKeys.InvalidCredentials, - ); - } - cb(null, userInfo.client, userInfo.user); - } catch (err) { - cb(err); - } - }, + this.getResourceOwnerStrategyWithRequest(verifyFn), ); } else { return new Oauth2ResourceOwnerPassword.Strategy( - // eslint-disable-next-line @typescript-eslint/no-misused-promises - async ( - clientId: string, - clientSecret: string, - username: string, - password: string, - cb: ( - err: Error | null, - client?: IAuthClient | false, - user?: IAuthUser | false, - ) => void, - ) => { - try { - const userInfo = await verifyFn( - clientId, - clientSecret, - username, - password, - ); - if (!userInfo || isEmpty(userInfo)) { - throw new HttpErrors.Unauthorized( - AuthErrorKeys.InvalidCredentials, - ); - } - cb(null, userInfo.client, userInfo.user); - } catch (err) { - cb(err); - } - }, + this.getResourceOwnerStrategyWithoutRequest(verifyFn), ); } } + + getResourceOwnerStrategyWithRequest( + verifyFn: VerifyFunction.ResourceOwnerPasswordFn, + ) { + return ( + req: Request, + clientId: string, + clientSecret: string, + username: string, + password: string, + cb: ( + err: Error | null, + client?: IAuthClient | false, + user?: IAuthUser | false, + ) => void, + ) => { + verifyFn(clientId, clientSecret, username, password, req) + .then((userInfo) => { + if (!userInfo || isEmpty(userInfo)) { + throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials); + } + cb(null, userInfo.client, userInfo.user); + }) + .catch((err) => { + cb(err); + }); + }; + } + + getResourceOwnerStrategyWithoutRequest( + verifyFn: VerifyFunction.ResourceOwnerPasswordFn, + ) { + return ( + clientId: string, + clientSecret: string, + username: string, + password: string, + cb: ( + err: Error | null, + client?: IAuthClient | false, + user?: IAuthUser | false, + ) => void, + ) => { + verifyFn(clientId, clientSecret, username, password) + .then((userInfo) => { + if (!userInfo || isEmpty(userInfo)) { + throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials); + } + cb(null, userInfo.client, userInfo.user); + }) + .catch((err) => { + cb(err); + }); + }; + } } diff --git a/src/strategies/types/types.ts b/src/strategies/types/types.ts index 878160f..7cc38f9 100644 --- a/src/strategies/types/types.ts +++ b/src/strategies/types/types.ts @@ -41,28 +41,24 @@ export namespace VerifyFunction { (token: string, req?: Request): Promise; } - export interface ResourceOwnerPasswordFn { - ( - clientId: string, - clientSecret: string, - username: string, - password: string, - req?: Request, - ): Promise<{client: T; user: S} | null>; - } + export type ResourceOwnerPasswordFn = ( + clientId: string, + clientSecret: string, + username: string, + password: string, + req?: Request, + ) => Promise<{client: T; user: S} | null>; - export interface SecureResourceOwnerPasswordFn< + export type SecureResourceOwnerPasswordFn< T = IAuthSecureClient, S = IAuthUser, - > { - ( - clientId: string, - clientSecret: string, - username: string, - password: string, - req?: Request, - ): Promise<{client: T; user: S} | null>; - } + > = ( + clientId: string, + clientSecret: string, + username: string, + password: string, + req?: Request, + ) => Promise<{client: T; user: S} | null>; export interface GoogleAuthFn extends GenericAuthFn { ( @@ -143,8 +139,5 @@ export namespace VerifyFunction { ): Promise; } // eslint-disable-next-line @typescript-eslint/no-explicit-any - export interface GenericAuthFn { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (...params: any): Promise; - } + export type GenericAuthFn = (...params: any) => Promise; } diff --git a/src/strategy-adapter.ts b/src/strategy-adapter.ts index 2356750..6810a95 100644 --- a/src/strategy-adapter.ts +++ b/src/strategy-adapter.ts @@ -58,10 +58,10 @@ export class StrategyAdapter { strategy.error = (error: string) => { reject(new HttpErrors.Unauthorized(error)); }; - + const REDIRECT_URL = 302; strategy.redirect = (url: string) => { if (response) { - response.redirect(302, url); + response.redirect(REDIRECT_URL, url); } resolve(); }; From 052acc7671ef9ec76b3f5a429b9514aa781e607f Mon Sep 17 00:00:00 2001 From: arpit1503khanna Date: Tue, 8 Aug 2023 13:57:35 +0530 Subject: [PATCH 2/3] fix(chore): changed the name of a function changed the name of a function GH-142 --- package-lock.json | 4 ++-- .../local-password-strategy-factory-provider.ts | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index a487d33..57cca1d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "loopback4-authentication", - "version": "10.0.0", + "version": "9.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "loopback4-authentication", - "version": "10.0.0", + "version": "9.0.1", "license": "MIT", "dependencies": { "@loopback/context": "^6.1.3", diff --git a/src/strategies/passport/passport-local/local-password-strategy-factory-provider.ts b/src/strategies/passport/passport-local/local-password-strategy-factory-provider.ts index e9f8ca8..1247e86 100644 --- a/src/strategies/passport/passport-local/local-password-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-local/local-password-strategy-factory-provider.ts @@ -63,9 +63,7 @@ export class LocalPasswordStrategyFactoryProvider } }; } - getLocalStrategyVerifierUndefinedRequest( - verifyFn: VerifyFunction.LocalPasswordFn, - ) { + getDefaultLocalStrategy(verifyFn: VerifyFunction.LocalPasswordFn) { return async ( username: string, password: string, @@ -105,7 +103,7 @@ export class LocalPasswordStrategyFactoryProvider } else { return new PassportLocal.Strategy( // eslint-disable-next-line @typescript-eslint/no-misused-promises - this.getLocalStrategyVerifierUndefinedRequest(verifyFn), + this.getDefaultLocalStrategy(verifyFn), ); } } From a48577c1a2038598c38754b85ac0ebf7b0819488 Mon Sep 17 00:00:00 2001 From: arpit1503khanna Date: Wed, 9 Aug 2023 13:38:45 +0530 Subject: [PATCH 3/3] fix(chore): fixed the parentheses sonar issues fixed the parentheses sonar issues GH-142 --- .prettierrc | 3 ++- src/providers/client-authentication.provider.ts | 2 +- src/release_notes/post-processing.js | 12 ++++++------ src/release_notes/release-notes.js | 2 +- .../client-password-strategy-factory-provider.ts | 8 ++++---- ...cure-client-password-strategy-factory-provider.ts | 8 ++++---- .../passport-otp/otp-strategy-factory.provider.ts | 4 ++-- .../resource-owner-strategy-factory-provider.ts | 8 ++++---- src/strategies/types/types.ts | 2 +- vendor/passport-apple/src/strategy.js | 4 ++-- vendor/passport-apple/src/token.js | 4 ++-- 11 files changed, 29 insertions(+), 28 deletions(-) diff --git a/.prettierrc b/.prettierrc index f58b81d..2e48c76 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,5 +2,6 @@ "bracketSpacing": false, "singleQuote": true, "printWidth": 80, - "trailingComma": "all" + "trailingComma": "all", + "arrowParens": "avoid" } diff --git a/src/providers/client-authentication.provider.ts b/src/providers/client-authentication.provider.ts index 7e6f7fb..a78f808 100644 --- a/src/providers/client-authentication.provider.ts +++ b/src/providers/client-authentication.provider.ts @@ -18,7 +18,7 @@ export class ClientAuthenticateActionProvider ) {} value(): AuthenticateFn { - return (request) => this.action(request); + return request => this.action(request); } async action(request: Request): Promise { diff --git a/src/release_notes/post-processing.js b/src/release_notes/post-processing.js index deefd64..efa8475 100644 --- a/src/release_notes/post-processing.js +++ b/src/release_notes/post-processing.js @@ -10,17 +10,17 @@ module.exports = async function (data, callback) { const commitTitle = commit.title; commit.title = commitTitle.substring(0, commitTitle.indexOf('#') - 1); - commit.messageLines = commit.messageLines.filter((message) => { + commit.messageLines = commit.messageLines.filter(message => { if (message.indexOf('efs/remotes/origin') === -1) return message; }); - commit.messageLines.forEach((message) => { + commit.messageLines.forEach(message => { commit.issueno = message.includes('GH-') ? message.replace('GH-', '').trim() : null; }); - const issueDesc = await getIssueDesc(commit.issueno).then((res) => { + const issueDesc = await getIssueDesc(commit.issueno).then(res => { return res; }); commit.issueTitle = issueDesc; @@ -48,9 +48,9 @@ function getIssueDesc(issueNo) { `https://github.com/sourcefuse/loopback4-authentication/issues/${encodeURIComponent( issueNo, )}`, - (res) => { + res => { res.setEncoding('utf8'); - res.on('data', (chunk) => { + res.on('data', chunk => { result = result + chunk; }); res.on('end', () => { @@ -69,7 +69,7 @@ function getIssueDesc(issueNo) { }); }, ); - req.on('error', (e) => { + req.on('error', e => { reject(e); }); req.end(); diff --git a/src/release_notes/release-notes.js b/src/release_notes/release-notes.js index 0296146..e573f93 100644 --- a/src/release_notes/release-notes.js +++ b/src/release_notes/release-notes.js @@ -53,7 +53,7 @@ async function addAndCommit() { await git.push('origin', 'master'); } -generateReleaseNotes().catch((ex) => { +generateReleaseNotes().catch(ex => { console.error(ex); process.exit(1); }); diff --git a/src/strategies/passport/passport-client-password/client-password-strategy-factory-provider.ts b/src/strategies/passport/passport-client-password/client-password-strategy-factory-provider.ts index 0392fc9..d6bfe1a 100644 --- a/src/strategies/passport/passport-client-password/client-password-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-client-password/client-password-strategy-factory-provider.ts @@ -54,11 +54,11 @@ export class ClientPasswordStrategyFactoryProvider req: Request | undefined, ) => { verifyFn(clientId, clientSecret, req) - .then((client) => { + .then(client => { this.clientPasswordVerifierHelper(client, clientSecret); cb(null, client); }) - .catch((err) => { + .catch(err => { cb(err); }); }, @@ -72,11 +72,11 @@ export class ClientPasswordStrategyFactoryProvider cb: (err: Error | null, client?: IAuthClient | null) => void, ) => { verifyFn(clientId, clientSecret) - .then((client) => { + .then(client => { this.clientPasswordVerifierHelper(client, clientSecret); cb(null, client); }) - .catch((err) => { + .catch(err => { cb(err); }); }, diff --git a/src/strategies/passport/passport-client-password/secure-client-password-strategy-factory-provider.ts b/src/strategies/passport/passport-client-password/secure-client-password-strategy-factory-provider.ts index 8516f39..595db81 100644 --- a/src/strategies/passport/passport-client-password/secure-client-password-strategy-factory-provider.ts +++ b/src/strategies/passport/passport-client-password/secure-client-password-strategy-factory-provider.ts @@ -57,11 +57,11 @@ export class SecureClientPasswordStrategyFactoryProvider req: Request | undefined, ) => { verifyFn(clientId, clientSecret, req) - .then((client) => { + .then(client => { this.secureClientPasswordVerifierHelper(client, clientSecret); cb(null, client); }) - .catch((err) => { + .catch(err => { cb(err); }); }, @@ -75,11 +75,11 @@ export class SecureClientPasswordStrategyFactoryProvider cb: (err: Error | null, client?: IAuthSecureClient | null) => void, ) => { verifyFn(clientId, clientSecret) - .then((client) => { + .then(client => { this.secureClientPasswordVerifierHelper(client, clientSecret); cb(null, client); }) - .catch((err) => { + .catch(err => { cb(err); }); }, diff --git a/src/strategies/passport/passport-otp/otp-strategy-factory.provider.ts b/src/strategies/passport/passport-otp/otp-strategy-factory.provider.ts index b43d315..12bf5ee 100644 --- a/src/strategies/passport/passport-otp/otp-strategy-factory.provider.ts +++ b/src/strategies/passport/passport-otp/otp-strategy-factory.provider.ts @@ -32,7 +32,7 @@ export class PassportOtpStrategyFactoryProvider options, (key: string, otp: string, cb: Otp.VerifyCallback) => { verifyFn(key, otp) - .then((user) => { + .then(user => { if (!user) { throw new HttpErrors.Unauthorized( AuthErrorKeys.InvalidCredentials, @@ -40,7 +40,7 @@ export class PassportOtpStrategyFactoryProvider } cb(null, user); }) - .catch((err) => { + .catch(err => { cb(err); }); }, 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 2873027..c06d832 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 @@ -62,13 +62,13 @@ export class ResourceOwnerPasswordStrategyFactoryProvider ) => void, ) => { verifyFn(clientId, clientSecret, username, password, req) - .then((userInfo) => { + .then(userInfo => { if (!userInfo || isEmpty(userInfo)) { throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials); } cb(null, userInfo.client, userInfo.user); }) - .catch((err) => { + .catch(err => { cb(err); }); }; @@ -89,13 +89,13 @@ export class ResourceOwnerPasswordStrategyFactoryProvider ) => void, ) => { verifyFn(clientId, clientSecret, username, password) - .then((userInfo) => { + .then(userInfo => { if (!userInfo || isEmpty(userInfo)) { throw new HttpErrors.Unauthorized(AuthErrorKeys.InvalidCredentials); } cb(null, userInfo.client, userInfo.user); }) - .catch((err) => { + .catch(err => { cb(err); }); }; diff --git a/src/strategies/types/types.ts b/src/strategies/types/types.ts index 7cc38f9..9c7ed81 100644 --- a/src/strategies/types/types.ts +++ b/src/strategies/types/types.ts @@ -139,5 +139,5 @@ export namespace VerifyFunction { ): Promise; } // eslint-disable-next-line @typescript-eslint/no-explicit-any - export type GenericAuthFn = (...params: any) => Promise; + export type GenericAuthFn = (...params: any) => Promise; // NOSONAR } diff --git a/vendor/passport-apple/src/strategy.js b/vendor/passport-apple/src/strategy.js index c9bcfea..f632e31 100644 --- a/vendor/passport-apple/src/strategy.js +++ b/vendor/passport-apple/src/strategy.js @@ -77,7 +77,7 @@ function Strategy(options, verify) { // Generate the client_secret using the library _tokenGenerator .generate() - .then((client_secret) => { + .then(client_secret => { params = params || {}; const codeParam = params.grant_type === 'refresh_token' ? 'refresh_token' : 'code'; @@ -107,7 +107,7 @@ function Strategy(options, verify) { }, ); }) - .catch((error) => { + .catch(error => { callback(error); }); }; diff --git a/vendor/passport-apple/src/token.js b/vendor/passport-apple/src/token.js index dec729a..46ff691 100644 --- a/vendor/passport-apple/src/token.js +++ b/vendor/passport-apple/src/token.js @@ -88,10 +88,10 @@ class AppleClientSecret { exp, this._config.key_id, ) - .then((token) => { + .then(token => { resolve(token); }) - .catch((err) => { + .catch(err => { reject(err); }); });