首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Passport & SmartThings

Passport & SmartThings
EN

Stack Overflow用户
提问于 2016-06-28 19:08:04
回答 1查看 233关注 0票数 0

这将是一个相当广泛的问题,因为我被困在了真正开始的地方。我正在尝试使用Passport向SmartThings进行身份验证。在这里查看SmartThings文档:http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/tutorial-part2.htm

SmartThings不会返回任何用户信息,只返回一个身份验证令牌,然后您可以使用该令牌调用SmartThings实例来控制环境。

我目前正在尝试使用OAuth2策略,但是这需要返回一个用户配置文件来序列化用户,在本例中为空。

我试图实现的是让某人使用SmartThings授权,并将他们的令牌存储在会话中,以便可以提取他们的数据。

从长远来看,我会将它分配给我的应用程序的本地用户帐户,但是现在,我只想让上面的工作正常进行。

有没有人知道我是怎么做到最好的。我有点纠结于此..也许使用OAuth2策略不是正确的方法?我目前有这个:

代码语言:javascript
复制
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());
  }
}
EN

回答 1

Stack Overflow用户

发布于 2016-06-28 20:41:30

我认为您想要在身份验证过程中这样做:

使用passport的会话生成授权码和strategy

  • Manually - guide here

  • Save
  1. local SmartThings‘s session

中的令牌对应用程序中的用户进行身份验证

之后,您可以在会话中使用token向SmartThings的API发出请求

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38074551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档