question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding Multiple OAuth2 Strategies Not working

See original GitHub issue

I implemented more than one strategy like this:

strategies: [
          NbPasswordAuthStrategy.setup({
            name: 'xxx',
            baseEndpoint: '/api/',
            login: {
              endpoint: 'login/xxx',
              method: 'post'
            },
            token: {
              class: NbAuthJWTToken,
              key: 'data.token'
            },
            errors: {
              key: 'error.message'
            },
          }),
          NbPasswordAuthStrategy.setup({
            name: 'yyy',
            baseEndpoint: '/api/',
            login: {
              endpoint: 'login',
              method: 'post'
            },
            register: {
              endpoint: 'register',
              method: 'post'
            },
            token: {
              class: NbAuthJWTToken,
              key: 'data.token'
            },
            errors: {
              key: 'error.message'
            }
          }),

But when trying to use xxx strategy, it always returns “There is no Auth Strategy registered under ‘xxx’ name” error:

this.authService.authenticate('xxx', params)
          .subscribe((result: NbAuthResult) => { 

Was trying to debug by adding log build result of auth.service.js:

function (strategyName) {
        console.log('Strategies: ', this.strategies);
        var found = this.strategies.find(function (strategy) { return strategy.getName() === strategyName; });
        if (!found) {
            throw new TypeError("There is no Auth Strategy registered under '" + strategyName + "' name");
        }
        return found;
    };

But in the result the strategies does not have ‘name’ field:

(2) [NbPasswordAuthStrategy, NbPasswordAuthStrategy]
0
:
NbPasswordAuthStrategy
defaultOptions
:
NbPasswordAuthStrategyOptions {baseEndpoint: "/api/auth/", login: {…}, register: {…}, requestPass: {…}, resetPass: {…}, …}
http
:
HttpClient {handler: HttpInterceptingHandler}
options
:
{baseEndpoint: "/api/", login: {…}, register: {…}, requestPass: {…}, resetPass: {…}, …}
route
:
ActivatedRoute {url: BehaviorSubject, params: BehaviorSubject, queryParams: BehaviorSubject, fragment: BehaviorSubject, data: BehaviorSubject, …}
__proto__
:
NbAuthStrategy
1
:
NbPasswordAuthStrategy```

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:18 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
abdullah2993commented, Jan 5, 2020

any update on the fix or documentation update?

6reactions
nnixaacommented, Feb 18, 2019

Right, one more step and it should be fine as a workaround:


@Injectable()
export class NbGoogleOAuth2Strategy extends NbOAuth2AuthStrategy {
  static setup(options: NbOAuth2AuthStrategyOptions): [NbAuthStrategyClass, NbOAuth2AuthStrategyOptions] {
    return [NbGoogleOAuth2Strategy, options]; // HERE we make sure our strategy reutrn correct class reference
  }
}

@Injectable()
export class NbFacebookOAuth2Strategy extends NbOAuth2AuthStrategy {
  static setup(options: NbOAuth2AuthStrategyOptions): [NbAuthStrategyClass, NbOAuth2AuthStrategyOptions] {
    return [NbFacebookOAuth2Strategy, options]; // HERE we make sure our strategy reutrn correct class reference
  }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Complete Guide to Multi-Provider OAuth 2 Authorization in ...
Learn how to build an OAuth2 authorization using multiple social providers with cross-sync and multiple logged-in accounts using Nodejs and ...
Read more >
OAuth 2 Access Token Usage Strategies for Multiple ...
When an application consumes a variety of different APIs, often all endpoints require an OAuth 2 access token issued from a common Identity ......
Read more >
How can I use multiple Oauth2 SSO Servers on a single ...
I'd like to give users the option to login to a Spring Boot web application using their Google or Facebook account. I checked...
Read more >
Authorization Errors | Device Access - Google Developers
Use this guide to troubleshoot the most common errors during this process. Troubleshooting. To learn more about Google OAuth, see Using OAuth ...
Read more >
Firebase Authentication
Firebase Authentication lets you add an end-to-end identity solution to your app for ... With some additional code, you'll be able to add...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found