Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
Custom Authentication strategy in LoopBack4 not working

I am trying to follow https://loopback.io/doc/en/lb4/Implement-your-own-strategy.html and got so far with following steps:

Step 1: Created a Custom Strategy (auth/my-strategy.ts) based on following pattern

export class MyAuthenticationStrategy implements AuthenticationStrategy {
  name: string = 'my';
  /**
  * The 'authenticate' method takes in a given request and returns a user profile
  * which is an instance of 'UserProfile'.
  * (A user profile is a minimal subset of a user object)
  * If the user credentials are valid, this method should return a 'UserProfile' instance.
  * If the user credentials are invalid, this method should throw an error
  * If the user credentials are missing, this method should throw an error, or return ' undefined' 
  * and let the authentication action deal with it.
  *
  * @param request - Express request object
  */
  authenticate(request: Request): Promise<UserProfile | undefined> {
    // custom auth logic
    // throw error or return UserProfile
  };
}

Step 2: I have registered the strategy in application.ts

// Mount authentication system
this.component(AuthenticationComponent);
// Register Auth Strategy
registerAuthenticationStrategy(this, MyAuthenticationStrategy);

Step 3: Added following in my controller class

@authenticate('my')
export class XxxController { ... }

I am not sure what am I missing here as there is neither any error, nor my authenticate function working/executing.

I am not sure what this step does as explained here? Do I need to create an separate extension for my strategy? rather, I would prefer to keep this code (Authentication Strategy) within the main project, instead of creating a separate project for extension.

Please help. thanks,

Gagan

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda