liamcurry/passport-steam

[QUESTION] Usage with NestJS and TypeScript

angelhdzdev opened this issue · 2 comments

A guide of usage with NestJS and TypeScript would be really nice.

I'm following NestJS's tutorial on how to use Passport,
but can't get my head around implementing the passport.authentication middleware
and setting up the PassportModule and SteamStrategy.

Thanks.

Take a look at https://github.com/nestjs/nest/blob/master/sample/19-auth-jwt/src/auth/strategies/jwt.strategy.ts, you can use this as a base, but use the Strategy provided by passport-steam.

https://docs.nestjs.com/security/authentication#implementing-passport-local has some more documentation around implementing strategies

Take a look at https://github.com/nestjs/nest/blob/master/sample/19-auth-jwt/src/auth/strategies/jwt.strategy.ts, you can use this as a base, but use the Strategy provided by passport-steam.

https://docs.nestjs.com/security/authentication#implementing-passport-local has some more documentation around implementing strategies

Thank you very much for your time and kindness.

At the end, I followed the tutorials 100%.
Everything was working as it should.
I implemented the Stream Strategy correctly.

The issue was, I didn't use the SteamAuthGuard in the /auth/steam/return route, where the navigation is redirected to after the initial Steam Login /auth/steam/login.

So, for anyone wanting to implement the Steam Strategy, remember to add the SteamAuthGuard in both routes.

Also, I needed to re-add the validate() method in the SteamStrategy class after I removed it thinking that implementing it in the first place was the cause of my issues.

And also, the SteamAuthGuard needs to implement the canActivate method, call the super.canActivate, and call request.login.

I finally got it working!!! Now req.user isn't undefined anymore and it's returning the Steam user details,
and the SessionSerializer class methods (serializeUser & deserializeUser) are working now.