Using passport pair with sails-generate-auth

I am creating a SailsJS application and I want users to log in with Steam authentication only. I used sails-generate-auth

to create a template code with sails, but I am having trouble connecting the passport pair.

https://github.com/kasperisager/sails-generate-auth

https://github.com/liamcurry/passport-steam

Reported error:

C:\Users\Joe\testProject\node_modules\passport-steam\lib\passport-steam\strategy.js:67
            id: result.response.players[0].steamid,
                                          ^
TypeError: Cannot read property 'steamid' of undefined
    at steamapi.getPlayerSummaries.callback (C:\Users\Joe\testProject\node_modules\passport-steam\lib\passport-steam\strategy.js:67:43)
    at IncomingMessage.<anonymous> (C:\Users\Joe\testProject\node_modules\passport-steam\node_modules\steam-web\lib\steam.js:218:7)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:944:16
    at process._tickDomainCallback (node.js:486:13)

      

I have a feeling this is because SteamWebAPI is returning an empty response: {"response":{"players":[]}}

which is caused by a bogus password in the request. The offensive line is in the passport here: https://github.com/liamcurry/passport-steam/blob/master/lib/passport-steam/strategy.js#L53

Looking at the identifier

before parameter getUserProfile

, it is represented by the entire Sails request scope. If I hardcode a good password ID into this array, I get this error:

C:\Users\Joe\testProject\api\services\passport.js:98
    return next(new Error('Neither a username nor email was available'));
           ^
TypeError: undefined is not a function
    at Authenticator.passport.connect (C:\Users\Joe\testProject\api\services\passport.js:98:12)
    at module.exports (C:\Users\Joe\testProject\api\services\protocols\openid.js:24:12)
    at steamapi.getPlayerSummaries.callback (C:\Users\Joe\testProject\node_modules\passport-steam\lib\passport-steam\strategy.js:72:11)
    at IncomingMessage.<anonymous> (C:\Users\Joe\testProject\node_modules\passport-steam\node_modules\steam-web\lib\steam.js:218:7)
    at IncomingMessage.emit (events.js:117:20)
    at _stream_readable.js:944:16
    at process._tickDomainCallback (node.js:486:13)

      

I think this makes sense since the couple's answer doesn't have a username or email, but this is a profile: {"emails":[{}],"name":{}}

This is my passport config:

steam: {
    name: 'Steam',
    protocol: 'openid',
    strategy: require('passport-steam').Strategy,
    options: {
      returnURL: 'http://localhost:1337/auth/steam/callback',
      realm: 'http://localhost:1337/',
      apiKey:'STEAM-API-KEY-REMOVED'
      }
    }
  }

      

Not sure if there is something simple that I am missing, or if I need to write a ton of custom processing. Is my configuration correct?

+3


source to share


1 answer


This is caused by outdated source code in npm. Even with the latest version 0.1.4, the code is wrong. Replacing strategy.js

the passport with the latest version will fix this error.

Also, api\services\passport.js

you need to add a little custom processing to passport.connect()

. profile

doesn't have username

, but has id

(user spoof) and displayName

. They can be used to set properties of the user model, for example



//steam auth
if (profile.hasOwnProperty('displayName')) { 
  user.username = profile.displayName; 
}

      

Here is the ticket where the issue was resolved: https://github.com/liamcurry/passport-steam/issues/10

+1


source







All Articles