这将是一个相当广泛的问题,因为我被困在了真正开始的地方。我正在尝试使用Passport向SmartThings进行身份验证。在这里查看SmartThings文档:http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/tutorial-part2.htm
SmartThings不会返回任何用户信息,只返回一个身份验证令牌,然后您可以使用该令牌调用SmartThings实例来控制环境。
我目前正在尝试使用OAuth2策略,但是这需要返回一个用户配置文件来序列化用户,在本例中为空。
我试图实现的是让某人使用SmartThings授权,并将他们的令牌存储在会话中,以便可以提取他们的数据。
从长远来看,我会将它分配给我的应用程序的本地用户帐户,但是现在,我只想让上面的工作正常进行。
有没有人知道我是怎么做到最好的。我有点纠结于此..也许使用OAuth2策略不是正确的方法?我目前有这个:
var passport = require('passport');
var OAuth2Strategy = require('passport-oauth2').Strategy;
var verifyHandler = function(req, token, refreshToken, profile, done){
return done(token)
}
passport.serializeUser(function(user, done) {
done(null, user.id);
});
module.exports.http = {
customMiddleware: function(app) {
passport.use(new OAuth2Strategy({
authorizationURL: 'https://graph.api.smartthings.com/oauth/authorize',
tokenURL: 'https://graph.api.smartthings.com/oauth/token',
clientID: '123',
clientSecret: 'abc',
callbackURL: 'http://localhost:1337/auth/smartthings/callback',
skipUserProfile: true,
passReqToCallback: true
}, verifyHandler));
app.use(passport.initialize());
app.use(passport.session());
}
}发布于 2016-06-28 20:41:30
我认为您想要在身份验证过程中这样做:
使用passport的会话生成授权码和strategy
local SmartThings‘s session中的令牌对应用程序中的用户进行身份验证
之后,您可以在会话中使用token向SmartThings的API发出请求
https://stackoverflow.com/questions/38074551
复制相似问题