小编sdf*_*sdf的帖子

如何使passportjs google login oauth与JWT一起使用,而不是通过序列化/反序列化方法创建会话?

如果我添加创建会话的序列化/反序列化passportjs方法,下面的代码将完美运行。我正在努力创建 Json Web 令牌,而不是会话。任何教程、建议或清晰的示例将不胜感激。我使用 nodejs。

我了解 JWT 工作原理的优点/缺点和基本概述。我从以下来源了解到它。

  1. https://medium.com/@rahulgolwalkar/pros-and-cons-in-using-jwt-json-web-tokens-196ac6d41fb4
  2. https://scotch.io/tutorials/the-ins-and-outs-of-token-based-authentication
  3. https://scotch.io/tutorials/the-anatomy-of-a-json-web-token
  4. https://auth0.com/blog/cookies-vs-tokens-definitive-guide

/

没有 JWT 代码

var express = require("express"),
    path = require("path"),
    bodyParser = require("body-parser"),
    mysql = require("mysql"),
    connection = require("express-myconnection"),
    morgan = require("morgan"),
    app = express(),

    passport = require("passport"),
    GoogleStrategy = require("passport-google-oauth").OAuth2Strategy;


app.use(passport.initialize());

app.get("/", function(req, res) {
    res.sendFile(__dirname + "/public/main.html");
});


// #1
passport.use(
    new GoogleStrategy({
            clientID: "32434m",
            clientSecret: "23434",
            callbackURL: "http://localhost:3000/auth/google/callback"
        },
        function(accessToken, refreshToken, profile, done) {
            process.nextTick(function() {
                console.log("profile.id: " + profile.id);
                return done(null, profile.id); // …
Run Code Online (Sandbox Code Playgroud)

node.js jwt google-oauth passport.js passport-google-oauth

11
推荐指数
2
解决办法
6741
查看次数

app.all('*') VS app.use(function) 的区别?

app.all('*', function(req, res, next) { 
Run Code Online (Sandbox Code Playgroud)

对比

app.use(function (req, res, next) {
Run Code Online (Sandbox Code Playgroud)

有什么不同?不都接受对服务器的每个请求吗?

routes node.js express

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