passport raven
1.0.0
Raven(剑桥大学)护照认证模块。
这使您可以对剑桥大学的学生进行身份验证。
它适用于当前和过去的学生和教职员工。
npm install passport passport-raven
请参阅test/server.js
var RavenStrategy = require ( 'passport-raven' ) ;
passport . use ( new RavenStrategy ( {
desc : 'My Raven Application' ,
msg : 'we need to check you are a current student' ,
// use demonstration raven server in development
debug : process . env . NODE_ENV !== 'production'
} , function ( crsid , params , callback ) {
// You can skip this check if you want to support ex students and staff as well
if ( params . isCurrent ) {
callback ( null , { id : crsid } ) ;
} else {
callback ( new Error ( 'My Raven application is only for current students and staff' ) ) ;
}
} ) ) ;
选项:
desc
(String) - 将在 raven 登录页面上显示的网站描述msg
(字符串)- 请求身份验证的原因的描述iact
(布尔值)- 设置为true
可以强制用户输入用户名和密码,即使他们已经登录。设置为false
则仅在无需用户交互即可完成的情况下登录。默认为null
。audience
(字符串)- 身份验证请求网站的完全限定域名。passReqToCallback
(Boolean) - 如果设置,请求对象将作为验证函数的第一个参数提供。因此,验证回调可以使用请求的状态来进行进一步的处理。 passport . use ( new RavenStrategy ( {
desc : 'My Raven Application' ,
msg : 'we need to check you are a current student' ,
// use demonstration raven server in development
debug : process . env . NODE_ENV !== 'production' ,
passReqToCallback : true
} , function ( req , crsid , params , callback ) {
// this function could be defined elsewhere eg in a Sails app services protocol
... .
}
} ) ;
`
参数:
params 包含从服务器返回的所有信息,这里有两个示例:
目前的学生/教职员工:
{ ver: '3',
status: '200',
msg: '',
issue: '20141007T144208Z',
id: '1412692928-14998-17',
url: 'http://localhost:3000/login',
principal: 'test0001',
ptags: 'current',
auth: 'pwd',
sso: '',
life: '36000',
params: '',
kid: '901',
sig: 'qEK1GusOfnfh6D8BkmTi2iIsEXLmrfOd2TMEXStedOgaDXF7BQnN1nQvD8mudXhLO-rDLhp3JetrAded1XNeNaJPwdU5ZNIf5bJrvln2iqwbY280B4nGusvcOQjDoD1UJQ-J3hEpTDe7miDzGwSB-7zvdkpzt56qPgmUIIYHWs4_',
isCurrent: true }
过去的学生/教职员工:
{ ver: '3',
status: '200',
msg: '',
issue: '20141007T144128Z',
id: '1412692886-14816-35',
url: 'http://localhost:3000/login',
principal: 'test0450',
ptags: '',
auth: '',
sso: 'pwd',
life: '35960',
params: '',
kid: '901',
sig: 'otTWl-KZbXbRUMLjwpkoiT.nu8J7GnoHu6V8JzXjAu.XPGBBxRAJXEzCEQfc05jcoFmGWdHWPLjmJgNgom2vnltCu-CZOlAd9105v-k.9.dZQJAc65ugIlHDvPPT2icXiT1zo9.wzkCA.5vwLeUrhA8oKAa-6cuxbbzkwH-.Cc8_',
isCurrent: false }
app . get ( '/auth/raven' , passport . authenticate ( 'raven' ) , function ( req , res ) {
// Successful authentication, redirect home.
res . redirect ( '/' ) ;
} ) ;
麻省理工学院