Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant connect passport-steam with nest js #101

Open
ipirm opened this issue Sep 19, 2020 · 1 comment
Open

Cant connect passport-steam with nest js #101

ipirm opened this issue Sep 19, 2020 · 1 comment

Comments

@ipirm
Copy link

ipirm commented Sep 19, 2020

Hi, i am trying to use your package for making steam auth in my Nest JS project
After 3-5 days working, i wasnt able to find any decision

I am not getting any error, but also i am not able to force my app to redirect to steam auth page, my code places here
https://github.com/ipirm/steam-nest

I folowed your example and changed my /src/main.ts and /src/auth/auth.controller.ts , but it is not working now

My STEAM_API_KEY is work, i used it in your example to make it work

My main.ts file:

import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';

import { join } from 'path';
import { AppModule } from './app.module';
import * as session from 'express-session'
const SteamStrategy = require('passport-steam').Strategy;
import * as passport from "passport";

passport.serializeUser(function(user, done) {
done(null, user);
});

passport.deserializeUser(function(obj, done) {
done(null, obj);
});

passport.use(new SteamStrategy({
returnURL: 'http://localhost:3000/auth/steam/return',
realm: 'http://localhost:3000/',
apiKey: 'D30D8318F7565B58C561E689F2210B87'
},
function(identifier, profile, done) {
// asynchronous verification, for effect...
process.nextTick(function () {
// To keep the example simple, the user's Steam profile is returned to
// represent the logged-in user. In a typical application, you would want
// to associate the Steam account with a user record in your database,
// and return that user instead.
profile.identifier = identifier;
return done(null, profile);
})}));

async function bootstrap() {
const app = await NestFactory.create(
AppModule,
);

app.use(session({
    secret: 'your secret',
    name: 'name of session id',
    resave: true,
    saveUninitialized: true}));

// Initialize Passport! Also use passport.session() middleware, to support
// persistent login sessions (recommended).
app.use(passport.initialize());
app.use(passport.session());

app.useStaticAssets(join(__dirname, '..', 'public'));
app.setBaseViewsDir(join(__dirname, '..', 'views'));
app.setViewEngine('hbs');

await app.listen(3000);
}
bootstrap();

And my controller:

import {Controller, Get,Res} from '@nestjs/common';
import * as passport from 'passport'

@controller('auth')

export class AuthController {
constructor() {}

@Get('/steam')
root(@Res() res) {
    passport.authenticate('steam', {failureRedirect: '/'})
    return 'I am here'
}

@Get('/steam/return')
getItems(@Res() res) {
    passport.authenticate('steam', {failureRedirect: '/'})
    return 'I am not here'
}

}

Maybe you can help me 😇

@Paranoid-AF
Copy link

Paranoid-AF commented Oct 5, 2020

Please note that passport.authenticate() is a middleware factory, which generates a middleware for Express.

Since NestJS is based on Express by default, you could make use of it with NestJS, but not in this way.
Try this answer here on StackOverflow.

Hopefully this would work for you ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants