Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unknown authentication strategy "bearer" when using servise with scope: Scope.REQUEST #2310

Closed
ondrej-janosik opened this issue May 30, 2019 · 3 comments
Labels
needs triage This issue has not been looked into

Comments

@ondrej-janosik
Copy link

Bug Report

Current behavior

When I change my AuthService with method getUserByToken to scoped I am getting an error:
[Nest] 713 - 05/30/2019, 3:38 PM Unknown authentication strategy "bearer" +4390ms
If I change it back to singleton everzthing works as excepted

Input Code

import { Injectable, Scope } from '@nestjs/common';

import { UserEntity } from 'src/entity/UserEntity';
import { Repository } from 'typeorm';

import { InjectRepository } from '@nestjs/typeorm';

@Injectable({
  // scope: Scope.REQUEST, // THIS IS THE LINE THAT CHANGE THE BEHAVIOUR
})
export class AuthService {
  constructor(
    @InjectRepository(UserEntity)
    private readonly userRepository: Repository<UserEntity>,
  ) {}

  public async getUserByToken(token: string): Promise<UserEntity> {
    const user = await this.userRepository.findOne({
      where: {
        token,
      },
      relations: ['role'],
    });

    return user;
  }
}

Expected behavior

It should work with different scoping

Environment


Nest version: 6.2.4
 
For Tooling issues:
- Node version: 10.15.0
- Platform:  Windows 
@ondrej-janosik ondrej-janosik added the needs triage This issue has not been looked into label May 30, 2019
@ondrej-janosik
Copy link
Author

I have just noticed a very similar issue (#1870) and it looks like this behavior is by design. Is there any documentation/example of how to implement authorization in a multitenant application?

@kamilmysliwiec
Copy link
Member

As you noticed, it's impossible to use passport for that. I'd rather recommend wiring up your own tailored auth mechanism (which should be fairly simple though). I'm not aware of any article at the moment unfortunately :(

@lock
Copy link

lock bot commented Nov 6, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

2 participants