- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在使用 Express 和 Passport OpenID Google 策略,我想在每个身份验证请求上设置 returnURL,以便能够返回到启动该身份验证的页面。
情况是我有带有 Node.js 后端的 HTML5 幻灯片应用程序(以及社交内容和编辑器以及门户和扩展... https://github.com/bubersson/humla),我希望能够在某些幻灯片上登录用户(通过幻灯片menu...) 但我希望他能轻松回到同一张幻灯片。
所以我需要这样的东西?
app.get('/auth/google', function(req,res) {
var cust = "http://localhost:1338/"+req.params.xxx;
passport.authenticate('google', returnURL:cust, function ...
}
我已阅读 Passport 的指南,但仍然不知道该怎么做。我知道这不安全,但我还能怎么做呢?
或者我怎样才能让应用程序返回到启动登录的页面?或者有没有办法使用 AJAX 进行 OpenID 身份验证(并且仍然可以使用 Passport )?
最佳答案
我已经为我的应用程序 Twitter 身份验证解决了这个问题,我确信 GoogleStrategy 非常相似。试试这个的变体:
假设您已经像这样定义了来自身份验证服务的回调路由(来自 Passport 指南):
app.get('/auth/twitter/callback',
passport.authenticate('twitter', {
successRedirect: authenticationRedirect(req, '/account')
, failureRedirect: '/'
})
);
只需将该 block 更改为:
app.get('/auth/twitter/callback', function(req, res, next){
passport.authenticate('twitter', function(err, user, info){
// This is the default destination upon successful login.
var redirectUrl = '/account';
if (err) { return next(err); }
if (!user) { return res.redirect('/'); }
// If we have previously stored a redirectUrl, use that,
// otherwise, use the default.
if (req.session.redirectUrl) {
redirectUrl = req.session.redirectUrl;
req.session.redirectUrl = null;
}
req.logIn(user, function(err){
if (err) { return next(err); }
});
res.redirect(redirectUrl);
})(req, res, next);
});
现在,为经过身份验证的路由定义中间件,以将原始 URL 存储在 session 中,如下所示:
ensureAuthenticated = function (req, res, next) {
if (req.isAuthenticated()) { return next(); }
// If the user is not authenticated, then we will start the authentication
// process. Before we do, let's store this originally requested URL in the
// session so we know where to return the user later.
req.session.redirectUrl = req.url;
// Resume normal authentication...
logger.info('User is not authenticated.');
req.flash("warn", "You must be logged-in to do that.");
res.redirect('/');
}
有效!
关于node.js - Node.js Passport 的 Google 策略上的自定义 returnUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9885711/
我正在开发“ASP.NET MVC 4”应用程序。我正在使用/学习 SimpleMembershipProvider 并尝试坚持 VS2012 使用 Internet 模板 创建的默认逻辑(如果我没记
我在 web.config 中使用 Forms 身份验证,当我将我的页面重定向到某些特定页面时,returnUrl 会自动附加并且系统重定向到登录页面。无论用户是否登录,都应打开这些特定页面。 当我在
我想使用多次参数“returnUrl”来检索 url 中的一些参数。 示例: HTTPS://force.com?positionId=a0w0X000007HjBuQAK&lang=fr&media
我已经实现了我的登录页面并且它工作正常,但我无法从包含原始请求 URL 的 ReturnUrl 查询字符串参数中读取。 例如,从该页面成功登录时: http://whatever/Login.aspx
我已经实现了我的登录页面并且它工作正常,但我无法从包含原始请求 URL 的 ReturnUrl 查询字符串参数中读取。 例如,从该页面成功登录时: http://whatever/Login.aspx
我正在尝试使用 AdaptivePayments 通过我的网站将资金从一个用户发送到另一个用户,这样我就可以检查他们是否真的完成了付款。付款成功,但它们没有返回到我的网站,所以我无法跟踪付款。 我正在
我正在尝试使用 PayPal PHP SDK 将 paypal 整合到我的网站中。一切似乎都在工作,除了在成功或失败之后返回的 url 既不包括我定义的参数也不包括 paypal 返回的参数,例如 p
总结:我想使用 returnUrl 作为交易已被 PayPal 接受的证明。 我正在实现一个基于 PayPal 的非常基本的购买工作流程。 一切正常,用户点击支付,用户转到 PayPal,PayPal
我对在用户登录的页面上使用 paypal 有疑问 是用php 如果 paypal 重定向回该页面,您如何才能让用户仍然有权访问该页面。 我读到一些关于使用 PDT 将 session_id 赋予自定义
如何在 returnUrl 中指示页面上的位置? returnUrl= HttpContext.Current.Request.RawUrl 最佳答案 您可以在 url 中包含某种类型的标签,然后
大家好,我在 main.php 配置文件中有这段代码: 'components' => array( '[.........]', 'user'=>array( //
我们正在构建一个使用 ACS 的应用程序。我们的使用场景如下: 用户通过电子邮件收到类似 https://our.application.com/?requestId=123456 的网址并点击它 用
当用户单击我的站点中需要身份验证的链接时,浏览器将重定向到登录页面。登录页面包含一个 returnUrl 查询字符串参数。问题是,如果用户使用 OpenID 进行身份验证,提供程序会将用户重定向回登录
我有一个域 http://abc.com和一个子域 http://sub.abc.com .我正在通过共享表单例份验证 cookie 在两个站点之间实现单点登录。这是通过让两个站点共享 machine
我正在通过 returnUrl = Request.Url对于 Controller 操作,问题是当我在重定向之前使用以下代码检查它时,由于 IsLocalUrl() 而失败。称呼。为什么? if (
我正在使用 ASP.NET 成员资格和表单例份验证,在重定向到 returnURL 之前我想验证它。对于那些不熟悉工作流程的人来说,基本上如果您请求一个需要您进行身份验证的页面,您将被重定向到登录页面
我已经使用 Visual Studio 使用 servicestack 实现了一个网络服务。从 vs 调试器运行服务工作得很好。我刚刚尝试使用 XSP4 将它部署到 debian 机器上。该服务使用日
我有一个使用 AngularJS 的 SPA。我刚刚添加了安全/身份验证,除了 returnUrl 登录后重定向外,一切似乎都运行良好。存在于查询字符串中。 我的应用程序中有代码,如果没有用户通过身份
这可能是一个简单的问题,但我正在努力处理查询字符串中的 returnurl。我知道如何将查询字符串中的 returnurl 调用到 Response.Redirect 但我不确定如何将 returnu
我将返回网址作为查询字符串参数发送,如下所示 http://localhost:50316/TripNestFinal/Login.aspx?ReturnUrl=~/Account/AccountSe
我是一名优秀的程序员,十分优秀!