小编And*_* T.的帖子

将护照 openID-stategy 与 JWT 相结合

我在尝试使用 openID ( passport-steam )对passport.js 进行身份验证时遇到问题,然后使用令牌(JWT) 而不是会话。

我当前的代码如下所示:

app.post('/auth/steam', passport.authenticate('steam'));

app.get('/auth/steam/return',
  passport.authenticate('steam', { failureRedirect: '/', session: false }),
  function(req, res) {
    var token = jwt.encode({ useridentifier: req.user.identifier}, tokenSecret);

    res.redirect('/');
  });
Run Code Online (Sandbox Code Playgroud)

但是,我遇到的问题是:我应该如何将令牌传送回客户端?由于是从 Steam 站点返回后运行的 GET 请求,我无法简单回复

res.json(token)
Run Code Online (Sandbox Code Playgroud)

就像我看到人们将本地策略与 JWT 一起使用一样。

我设法想出的唯一解决方案涉及使用包含令牌的会话(例如连接闪存),并在他被重定向到“/”后通过 REST API 将其与客户端通信,但使用 JWT 的全部意义是为了避免使用会话,不是吗?

authentication node.js express jwt passport.js

4
推荐指数
1
解决办法
1737
查看次数

将包含Arc的self移到新线程中时,为什么会出现“不满足同步”的错误?

我有一个结构,该结构包含一个,Arc<Receiver<f32>>并且我试图添加一个方法,该方法获取的所有权self,并将所有权移至新线程并启动它。但是,我得到了错误

error[E0277]: the trait bound `std::sync::mpsc::Receiver<f32>: std::marker::Sync` is not satisfied
  --> src/main.rs:19:9
   |
19 |         thread::spawn(move || {
   |         ^^^^^^^^^^^^^ `std::sync::mpsc::Receiver<f32>` cannot be shared between threads safely
   |
   = help: the trait `std::marker::Sync` is not implemented for `std::sync::mpsc::Receiver<f32>`
   = note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Arc<std::sync::mpsc::Receiver<f32>>`
   = note: required because it appears within the type `Foo`
   = note: required because it appears within the type `[closure@src/main.rs:19:23: 22:10 self:Foo]`
   = note: …
Run Code Online (Sandbox Code Playgroud)

multithreading rust

3
推荐指数
1
解决办法
343
查看次数

返回引用时的std :: vector :: emplace_back错误(C++ 17)

我一直试图追踪一个错误超过10个小时,到现在为止我开始认为这个错误不在我身边.但是,我觉得可能是我只是忘记或误解了某些东西.

我有一个类型为std :: vector的类成员,名为temp_materials,在构造函数内部(当temp_materials仍为空时),此代码运行:

    Material &stonewallbug = temp_materials.emplace_back(resource_lib.get_shader("DeferredGeometryShader"));
    stonewallbug.set_texture("texture_diffuse1", resource_lib.get_texture("StonewallDiffuse"));
    stonewallbug.set_texture("texture_specular1", resource_lib.get_texture("StonewallSpecular"));

    Material &containerbug = temp_materials.emplace_back(resource_lib.get_shader("DeferredGeometryShader"));
    containerbug.set_texture("texture_diffuse1", resource_lib.get_texture("ContainerDiffuse"));
    containerbug.set_texture("texture_specular1", resource_lib.get_texture("ContainerSpecular"));

    Material stonewall1 = temp_materials[0];
    Material container1 = temp_materials[1];

    Material stonewall2 = stonewallbug;
    Material container2 = containerbug;
Run Code Online (Sandbox Code Playgroud)

如果在复制过程中没有出错,那么stonewall1的内容应该等于stonewall2,容器1到容器2应该是正确的吗?

但是,然后我将所有这些插入到一个简单的向量中,其内容将在稍后呈现:

    // Using temp_materials[0]
    auto stonewall1node = SceneNode(stonewall1, resource_lib.get_mesh("Cube"));
    stonewall1node.set_transform(glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f)));
    m_scene_list.push_back(stonewall1node);

    // Using temp_materials[1]
    auto container1node = SceneNode(container1, resource_lib.get_mesh("Cube"));
    container1node.set_transform(glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 1.0f)));
    m_scene_list.push_back(container1node);

    // Using stonewallbug
    auto stonewall2node = SceneNode(stonewall2, resource_lib.get_mesh("Cube"));
    stonewall2node.set_transform(glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 1.0f, 0.0f)));
    m_scene_list.push_back(stonewall2node);

    // Using containerbug …
Run Code Online (Sandbox Code Playgroud)

c++ debugging g++ c++17

2
推荐指数
1
解决办法
384
查看次数