- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将状态参数发送到 Oauth,然后在回调中捕获它们,但我无法使其工作。那么passportjs支持这样的功能吗?
我的想法是将 id 作为状态参数发送到 Oauth,然后根据发送回我的应用程序的状态参数中的 id 进行回调,我想做一个正确的重定向。
在我启用的 Twitter 策略中
passReqToCallback: true,
state: true
app.get('/auth/twitter/:gameId/:url',
function(req, res){
try {
var json = JSON.stringify({gameId: req.params.gameId, url: req.params.url});
var encodedValues = base64url(json);
console.log('encodedValues:'+encodedValues)
passport.authenticate('twitter', {state:encodedValues})
}catch (e){
console.log(e);
}
}
);
app.get('/auth/twitter/callback', passport.authenticate('twitter', function(req, res, next) {
try{
//get the state params from the res uri/body
//decode the state params
//redirect depending on the state.gameId
}catch(e){
console.log('twitter exception:'+e);
}}));
最佳答案
使用 oAuth 2.0,您不必为此依赖任何类型的 session 。您在 /auth/twitter/:gameId/:url
上通过状态的方式路线,您将能够使用 req.query.state
访问回调中的状态.
万一其他人遇到问题,当尝试通过 oAuth 进程传递应用程序状态时,这就是我在我的 Node-app 中解决它的方法:
由于我想将用户重定向到不同的位置,根据用户在进入身份验证屏幕之前来自的位置,我构建了不同的路由来访问身份验证屏幕,并根据命中的路由传递不同的状态。像这样:
router.get('/google/io', passport.authenticate('google', {
scope: ['email', 'profile'],
state: 'io'
}));
router.get('/google/de', passport.authenticate('google', {
scope: ['email', 'profile'],
state: 'de'
}));
因此,如果我的用户使用 .io 域访问来自我的页面的身份验证屏幕,则我的状态参数将携带值“io”,如果用户访问来自我页面的 .de 版本的身份验证屏幕,则状态参数将携带“de”的值。成功验证后,我可以从
req.query.state
中提取值,并将它们重定向回
mypage.de
或
mypage.io
关于node.js - 从passportjs中的OAuth回调中获取状态参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29534351/
我只想在还有用户后链接twitter帐户。 首先我有一个这样的 router.js // GET Registration Page router.get('/signup', function(re
已经与这个问题搏斗了 2 天了 :) 希望得到一些帮助。 我正在尝试使用passportjs+sqlite+sequelize构建快速身份验证, 1)当我将路由放在 app.use(passport.
我试图找出我的身份验证代码中的错误所在,该代码在每次尝试登录时都会创建一个无限循环。我认为它在我的代码的本地策略 passport.use('local', new LocalStrategy 部分内
我正在尝试使用 Passport js 实现本地身份验证并在 express 中进行 sequalize。我遇到的问题是成功回调永远不会在成功认证时触发。日志显示用户已找到,但用户对象从未登录到请求回
我正在使用 passportjs 进行用户身份验证。在官方指南中,唯一展示的用户案例是认证后的重定向操作: app.post('/login', passport.authenticate('lo
我有一个订购单,用户需要先注册才能订购,所以我可以创建一个帐户然后像这样处理订单。 router.post('/project/new', passport.authenticate('local-s
因此,我使用关系和 PassportJS 在我的 Node 应用程序中对用户进行身份验证。我找不到有关 Passport 本地策略中第一个参数的作用的信息。这个对象是否为用户提供了一个存储在MySQL
我做错了什么?它总是重定向到失败页面,但我无法调试。 // passport var passport = require('passport'), LocalStrategy = requi
我有一个应用程序使用与 Passport 捆绑在一起的所有 oAuth 身份验证,但我正在使用外部服务来创建我的数据库/用户。 如果我这样做: passport.use('local-signup',
使用passportjs进行身份验证。当用户注册时,我希望出现一条消息,让他们知道他们现在可以使用自己的帐户登录。截至目前,注册还会将它们记录下来,这会导致我的通知关闭: “您现在可以注册” “您已经
我正在使用 Passportjs 进行 Facebook 身份验证。这是我的 Facebook 策略: passport.use(new FacebookStrategy({ clie
我正在使用 express 和 passport 构建一个 rest api 后端,我的 localStrategy 似乎没有按要求被调用。 我的应用程序的入口点如下所示: app.js var fs
我是 javascript 和 Node 的新手。我按照 passportJS 的指南进行操作,但收到错误消息“找不到本地策略”。我不知道为什么。我的代码,此时基本上取自网站。 var express
下面是我的代码 restify = require("restify") passport = require("passport") GoogleStrategy = require("passpo
所以我正在处理提供的信息 here添加 Google 将重定向到用户在重定向到 google 之前所在页面的功能。我目前使用的是最新版本的 Express、PassportJS 和 Google oa
我的问题与PassportJS - Using multiple passports within Express application有关话题。 因此,只要我已经有两个单独的 Passport 实
我将 sequelize.js 用于我的数据存储,并将 github 策略与 passport.js 一起使用。我的代码是: app.use(passport.initialize()); app.u
尝试使用passport-JWT实现登录。注册和登录都工作正常, token 在登录时生成并发送到客户端,客户端存储并返回它。 登录身份验证请求到达应用程序后没有任何反应..帮助? :) 智威汤逊战略
这个问题已经有答案了: Understanding Passportjs Custom Callback (3 个回答) 已关闭 6 年前。 我无法理解 Passport.js 的自定义回调发生了什么
我正在玩弄 Passport ,并以这种方式配置我的 Twitter 登录: passport.use(new TwitterStrategy({ consumerKey: '*****',
我是一名优秀的程序员,十分优秀!