nebular: Adding Multiple OAuth2 Strategies Not working
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```
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 2
- Comments: 18 (3 by maintainers)
any update on the fix or documentation update?
Right, one more step and it should be fine as a workaround:
Yes, it works correctly @nnixaa Thanks!
@nnixaa I did not get it, guys. Where exactly should I add each portion of code?
Hey @nnixaa could you solve it? I have the same problem when trying to do it with more than one NbOAuth2AuthStrategy.
Error:
Following screenshots are from the debug which comes from the file: auth.service.js > this.strategies…