How we can get user inforamtion in controller method decoded from @Secourity decorator
surinder-enest opened this issue · comments
Surinder commented
@thiagobustamante Thanks for your Awesome work :)
Can you please help me to get the decoded user id
I am done with integration everything is working fine.
private configureAuthenticator() {
const JWT_SECRET: string = process.env.ENCRYPT_PWD;
const jwtConfig: StrategyOptions = {
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: Buffer.from(JWT_SECRET)
};
const strategy = new Strategy(jwtConfig, (payload: any, done: (err: any, user: any) => void) => {
done(null, payload);
});
const authenticator = new PassportAuthenticator(strategy, {
deserializeUser: (user: string) => JSON.parse(user),
serializeUser: (user: any) => {
return JSON.stringify(user);
}
});
Server.registerAuthenticator(authenticator);
Server.registerAuthenticator(authenticator, TOKEN_KEY.JWT_AUTH);
}
@Tags('Auth')
@Path("getCurrectUser")
@POST
@Security('*', TOKEN_KEY.JWT_AUTH)
public async getCurrectUser(): Promise<any> {
return "Working";
}
Here i need to get user id from the deserializeUser (decoded from the jwt) in the getCurrectUser method.
alfonsoal1983 commented
One way would be to collect the request header from the context and then deserialize the token user.
Inside the controller:
@context
private context: ServiceContext;
Inside the function
this.context.request
Surinder commented
thanks
…On Mon, Nov 11, 2019, 16:28 alfonsoal1983 ***@***.***> wrote:
One way would be to collect the request header from the context and then
deserialize the token user.
Inside the controller:
@context <https://github.com/context>
private context: ServiceContext;
Inside the function
this.context.request
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#110?email_source=notifications&email_token=AGGE2USZUACYAJ22UEOC3MTQTE3EZA5CNFSM4IWFP6MKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDWOGHI#issuecomment-552395549>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGGE2UQ4Q77SS6TTEDFYUYTQTE3EZANCNFSM4IWFP6MA>
.