how can we have auth middleware to authorized each an every request #7170
Replies: 5 comments
-
Hey @shendkardevesh. Also some of the strategies let you specify header fields to get credentials from on each request. For example: import { Strategy as JWTStrategy, ExtractJwt } from 'passport-jwt';
export class HttpAuthStrategyProvider implements Provider<Strategy | undefined> {
constructor(
@inject(RestBindings.Http.REQUEST) private request: Request,
// ... DEDUCTED
) {
this.verifyBasic = this.verifyBasic.bind(this);
}
value(): ValueOrPromise<Strategy | undefined> {
if (!this.metadata) {
return undefined;
}
const name = this.metadata.strategy;
if (name === 'JWTStrategy') {
return new JWTStrategy({
secretOrKey: this.configuration.secrets.jwtSecret,
jwtFromRequest: ExtractJwt.fromHeader('SOME_HEADER_NAME') // Here extract from headers
}, this.verifyCallback);
} else {
return Promise.reject(`Strategy ${name} is not defined`);
}
}
// .... DEDUCTED
} |
Beta Was this translation helpful? Give feedback.
-
Thanks @osmanmesutozcan , i was trying to achieve the above JWTStrategy stuff few days back and was stuck. |
Beta Was this translation helpful? Give feedback.
-
Discussion with @raymondfeng @jannyHou @emonddr: A few pointers:
|
Beta Was this translation helpful? Give feedback.
-
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
Beta Was this translation helpful? Give feedback.
-
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
Beta Was this translation helpful? Give feedback.
-
in current example of authentication verify function username and password is pass as an arguments but for every request it wou't be the case and how can we access header data in auth-strategy.provider.
Beta Was this translation helpful? Give feedback.
All reactions