Tag: 基本authentication

Passport-SAML:读取用户信息

还是小菜一碟! 我正在构build一个Node应用程序,并且我已经设置了各种所需的端点。 我的项目的一个要求是使用SAML机制进行身份validation。 我在我的应用程序中使用passport-SAML进行身份validation。 到目前为止,我已经能够设置和使用SAML策略,我的应用程序可以调用idp入口点,并从Idp接收回应。 我无法理解我们如何访问由idp返回的用户信息,以便我可以使用SAML返回的用户信息来创build和维护会话。 const saml = require('passport-saml'); module.exports = function (passport, config) { passport.serializeUser(function (user, done) { done(null, user); }); passport.deserializeUser(function (user, done) { done(null, user); }); var samlStrategyOptions = new saml.Strategy( { // URL that goes from the Identity Provider -> Service Provider callbackUrl: config.passport.saml.callback_url, // path: config.passport.saml.path, // URL that […]

CORS问题从React应用程序>节点服务器>redirect到Google OAuth2身份validation发出AJAX请求

嗨,我一直在敲我的头研究这个过去2天没有运气。 这是我从React应用程序@localhost:3000尝试使用Google Oauth2 Passport策略进行身份validation时遇到的错误。 我运行一个单独的应用程序与本地主机上的节点/快递服务器:3001。 XMLHttpRequest无法加载http:localhost:3001 / api / auth / google / login。 从“http:localhost:3001 / api / auth / google / login”redirect到“https:accounts.google.com/o/oauth2/v2/auth?response_type = code&redirect_uri = http%3A%2F%2Flocalhost%3A3001%2Fapi %2Fauth%2Fgoogle%2Fcallback&scope = https%3A%2F%2Fmail.google.com&client_id = ***。apps.googleusercontent.com'has been blocked by CORS policy:No'Access-Control-Allow-Origin'header is present on请求的资源。 原因'http:localhost:3000'因此不被允许访问。 createError.js:16 未被捕获(承诺)错误:在XMLHttpRequest.handleError的createError(createError.js:16)处的networking错误(xhr.js:87) 这是在我的客户端使用的代码尝试从我的组件之一login: //button <div> <button className="btn btn-danger" onClick={props.googleAuth}> Login With Google </button> </div> […]

如何检查用户是否具有数据库查询权限?

比方说,我有一个网站,汽车经销商pipe理他们的汽车库存。 每个汽车经销商都有自己的company_id ,他们的员工使用staff_id员工账户。 当工作人员在页面http://sellcarsfaster.com/inventory/car/jdksf9843他们应该看到他们公司的车ID为jdksf9843 。 如果他们复制这个url并将其发送给同事,那么其他员工应该可以查看该车。 但是,如果url发送给非职员,则该用户不能查看该车辆。 汽车应该只能通过那个汽车经销商的工作人员进入。 再进一步,我怎样才能检查各种可能的数据库查询的权限与各种关系的各种资产? 如下所示: http://sellcarsfaster.com/inventory/car/jdksf9843/tires/93sl9843 http://sellcarsfaster.com/insurance/2djlasd8 http://sellcarsfaster.com/history/event/8o4jsdfj 在这种应用程序中检查查看权限是否有最佳做法? 后端应该做些什么? 我将不得不做计算繁重的数据库查询进行身份validation吗? 我必须为每个数据库查询编写自定义身份validationfunction吗? 基于staff_id或company_id身份validation安全吗? 如果有人能指出我正确的方向,将不胜感激! PS我目前在我的后端有JSON Web Token身份validation,但是并不妨碍不同公司的员工只使用url来看别人的库存。 使用NodeJS和Postgres与AWS Cognito进行用户authentication

尝试在节点中实现JWT身份validation。 在受保护的路线上获得未经授权

我正在尝试实施JWT身份validation。 /login和/注册工作正常,他们返回身份validation令牌,但是当我尝试GET /秘密头'授权'='JWT token_received',它返回一个string'未经授权',我可以看到从JWTStrategy没有日志logging。 请让我知道我要去哪里错了。 var opts = {} opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken(); opts.secretOrKey = "very_secret" passport.use(new JwtStrategy(opts, function(payload, next){ console.log("payload received" + payload); User.findById(payload.id, function(err, user){ console.log("user found:" + user); if(err){ return next(err, false) } else if(user){ return next(null, user) } else{ return next(null, false) } }); } )); app.use(passport.initialize()); app.post("/login", function(req, res){ var email […]

使用Firebase身份validation和Express身份validation社交login?

我对Firebase颇为陌生,对Express也稍微有点新,而且我很难尝试使用Firebase提供的身份validationstream程。 我有这个路由,但每次我点击触发路由的button,我得到这个错误This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled. This operation is not supported in the environment this application is running on. "location.protocol" must be http, https or chrome-extension and web storage must be enabled. 我很确定networking存储已启用,但我很不确定如何修复location.protocol 。 […]

如何让我的deserializeUserfunction在护照login后不断运行?

我用我的用户身份validation有一些麻烦。 我可以login,注册和注销,您可以从客户端认为一切都很好。 但是,我的反序列化用户函数被重复调用。 每秒几十次。 我最初并没有注意到,但是如果你login了足够长的时间,应用程序真的变慢了。 我似乎无法弄清楚。 任何帮助将不胜感激。 另外,我试过在user.js文件的末尾运行client.end(),但是这并没有解决问题。 我想知道这是不是一个交叉来源的问题。 -UPDATE – 我不怀疑这是一个CORS问题,因为我刚刚尝试从服务器端口上的静态HTML文件login,问题依然存在。 *在与服务器不同的端口上运行的前端进行响应。 Node,Express和Postgres在服务器端。 app.js const express = require('express'), app = express(), bodyParser = require('body-parser'), cookieParser = require('cookie-parser'), expressValidator = require('express-validator'), passport = require('passport'), session = require('express-session'); require('dotenv').config(); let port = process.env.PORT || 5000; app.use((req, res, next) => { res.header('Access-Control-Allow-Credentials', true); res.header('Access-Control-Allow-Origin', 'http://localhost:3000'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); […]

在不同情况下使用Passport.js更改并保存redirect

即时通讯编写一个网站使用快递和通行证进行身份validation(和mongodb作为数据库),我知道我如何可以authentication用户,以及如何限制某些页面,所以只有login的用户可以访问它们。 但我有一个问题,我无法find答案的任何地方: 如果用户尝试访问受限制的网页,并且通知用户未使用req.isAuthenticated()login,则会将用户redirect到login页面,然后当用户login时将用户redirect到他们的个人档案页面。 通常这很好,但在这种情况下,用户试图去到另一个不是个人资料页面的受限制页面。 当他/她尝试login时,如何将用户redirect到configuration文件页面,但当他/她尝试访问受限制的页面时,请求他/她login,然后将其redirect到他/她的页面试图访问?

Nodemailer不断拒绝无效login身份validation(不使用Gmail)

我现在正在绕过这个最奇怪的问题。 我正在使用nodemailer和postfix发送电子邮件。 以下代码不起作用,给我以下错误: Error: Invalid login: 503 5.5.1 Error: authentication not enabled let transporter = nodemailer.createTransport({ host: 'mydomain.com', port: 465, secure: false, // true for 465, false for other ports auth: { user: 'no-reply', // user pass: 'a-hundred-percent-the-right-password' // password } }); 但更奇怪的是(更接近吓人),没有指定任何凭据的相同代码工作正常! (但当然电子邮件正在进入垃圾邮件)。 有没有人知道我可以做错什么?

Firebase child.once在auth.signInWithEmailAndPasswordcallback中超时不一致

我有一个简单的nodejs服务,在AWS EC2(ubuntu)中运行firebase。 我所要做的就是使用Firebase身份validationlogin用户,并在成功login时返回用户信息(附加信息)。 问题是,从用户对象获取用户信息的调用正在超时。 并非所有的时间,这是不一致的,而且总是当我第一次尝试在早上(或几个小时的空闲服务器)。 我从卷发中注意到的,是一天中的第一个要求,花费很长时间才能返回大约30多秒。 (使用免费的Firebase) 你能帮我确定我做错了什么吗? 我该如何解决这个问题? find下面的代码: const auth = firebase.auth(); const users = firebase.database().ref('users'); const db = firebase.database(); /* ..a lot of code in between.. */ let login = function(requestParam, callback) { console.log('userhandler.login called ' + new Date() + ' ' + requestParam.email) auth.signInWithEmailAndPassword(requestParam.email, requestParam.password).catch((error)=>{ console.log("error while signInWithEmailAndPassword " + error); […]

将令牌传递给我的Angular 4应用程序的优雅方式是什么?

我有以下实现: 前端 :localhost:4200(这是Angular应用程序) 后端 :localhost:3000(这是我的REST API在Node.js&Express上运行) – 步骤1.在Angular应用程序中,用户点击一个链接,将其redirect到我的REST API(localhost:3000 / auth / steam)。 第2步。我的REST API将他redirect到他login的OpenID Provider(Steam)。 第3步。成功login后,OpenID Provider将用户redirect到用户数据和我的后端服务器。 我的后端服务器将这些数据保存在数据库中,并创build一个包含用户数据的JWT(JSON Web令牌)。 第4步。将用户与令牌一起redirect到前端… 这是我不知道什么是一个优雅的方式来做到这一点的部分。 我想传递的标记作为URL参数(?标记= …),但这将是有点不安全,因为该标记将在URL中可见。 有没有更好的方法呢? 谢谢 :)