简体   繁体   English

如何使用NodeJS + Passport在OAuth流程中保留子域?

[英]How to preserve subdomain during OAuth flow with NodeJS + Passport?

I have many sub-domains and need to preserve the correct sub-domain for the authentication request. 我有许多子域,需要为身份验证请求保留正确的子域。 My OAuth provider allows me to add a custom field 'state' to the authorize which I get back in the response to my callback function. 我的OAuth提供程序允许我向自定义字段添加“状态”到授权中,然后在对回调函数的响应中返回该自定义字段。

I need to set the 'state' parameter to the sub-domain from the referrer header in the original request. 我需要在原始请求的引荐来源标头中将“ state”参数设置为子域。 However, I do not have access to the request object in the code below. 但是,我无权访问以下代码中的请求对象。 How do I make the value of state parameter dynamic based on request headers? 如何根据请求标头使状态参数的值动态化?

appSecure.get('/oauth/authorize', passport.authenticate('forcedotcom', { state: 'test' }));

Wrap the passport call: 包裹护照电话:

function dynamicStateAuth(req, res, next) {
  passport.authenticate('forcedotcom', { state: req.foo })(req, res, next)
}

appSecure.get('/oauth/authorize', dynamicStateAuth);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM