使用带有sails-generate-auth的passport-steam [英] Using passport-steam with sails-generate-auth

查看:52
本文介绍了使用带有sails-generate-auth的passport-steam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 SailsJS 应用程序,我希望用户仅使用 Steam 身份验证登录.我使用 sails-generate-auth 来创建一些带有风帆路线的样板代码,但是我无法将 Passport-steam 插入其中.

I'm creating a SailsJS application, and I want users to log in only with Steam authentication. I used sails-generate-auth to create some boilerplate code with sails routes, but I'm having trouble plugging passport-steam into it.

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

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

报的错误是:

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)

我感觉这是由 SteamWebAPI 返回空响应引起的:{"response":{"players":[]}},这是由请求中的虚假 SteamID 引起的.违规行在护照蒸汽中:https://github.com/liamcurry/passport-steam/blob/master/lib/passport-steam/strategy.js#L53

I have a feeling that this is caused by SteamWebAPI returning an empty response: {"response":{"players":[]}}, which is caused by a bogus SteamID in the request. The offending line is here in passport-steam: https://github.com/liamcurry/passport-steam/blob/master/lib/passport-steam/strategy.js#L53

查看 getUserProfileidentifier 参数,它似乎是整个 Sails 请求范围.如果我将一个好的 Steam id 硬编码到该数组中,则会出现此错误:

Looking at identifier parameter to getUserProfile, it appears to be the entire Sails request scope. If I hardcode a good steam id into that 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)

我认为这是有道理的,因为 Steam 响应没有用户名或电子邮件,但这是个人资料:{"emails":[{}],"name":{}}

I think that makes sense since the steam response doesn't have a username nor email, but this is the profile: {"emails":[{}],"name":{}}

这是我的护照配置:

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 I'm missing, or I need to write a ton of custom handling. Is my configuration correct?

推荐答案

这是由 npm 中的过时源代码引起的.即使是最新的 0.1.4 版本,代码也不正确.用 strategy.jsrel="nofollow">最新版本 将修复此错误.

This is caused by out-of-date source code in npm. Even with the latest 0.1.4 version, the code is not correct. Replacing strategy.js in passport-steam with the latest version will fix this error.

此外,在api\services\passport.js 中,需要在passport.connect() 中添加一些自定义处理.profile 没有 username,但有 id(用户 steamid)和 displayName.这些可用于设置用户模型属性,例如

Also, in api\services\passport.js, a little custom handling in passport.connect() needs to be added. The profile does not have a username, but has an id (user steamid) and displayName. These can be used to set the user model properties, e.g.

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

这是解决问题的票证:https://github.com/liamcurry/passport-steam/issues/10

这篇关于使用带有sails-generate-auth的passport-steam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆