【发布时间】:2020-09-16 12:34:00
【问题描述】:
我正在尝试制作一个网络应用程序,该应用程序使用我大学的 CAS 身份验证来登录用户。后端使用 Express 编写,目前在 localhost:5000 上运行。我使用cas-authentication 包为我处理身份验证。使用其 npm 页面中的示例代码:
var app = require('express')();
var session = require('express-session');
var CASAuthentication = require('cas-authentication');
// Set up an Express session, which is required for CASAuthentication.
app.use( session({
secret : 'super secret key',
resave : false,
saveUninitialized : true
}));
// Create a new instance of CASAuthentication.
var cas = new CASAuthentication({
cas_url : 'https://my-cas-host.com/cas',
service_url : 'https://my-service-host.com'
});
// Unauthenticated clients will be redirected to the CAS login and then back to
// this route once authenticated.
app.get( '/app', cas.bounce, function ( req, res ) {
res.send( '<html><body>Hello!</body></html>' );
});
// Unauthenticated clients will receive a 401 Unauthorized response instead of
// the JSON data.
app.get( '/api', cas.block, function ( req, res ) {
res.json( { success: true } );
});
// An example of accessing the CAS user session variable. This could be used to
// retrieve your own local user records based on authenticated CAS username.
app.get( '/api/user', cas.block, function ( req, res ) {
res.json( { cas_user: req.session[ cas.session_name ] } );
});
// Unauthenticated clients will be redirected to the CAS login and then to the
// provided "redirectTo" query parameter once authenticated.
app.get( '/authenticate', cas.bounce_redirect );
// This route will de-authenticate the client with the Express server and then
// redirect the client to the CAS logout page.
app.get( '/logout', cas.logout );
app.listen(5000);
我的问题是,如果我将我大学的 CAS 门户的 url 作为 cas_url 放在 CASAuthentication 对象中,那么我应该在 service_url 中放置什么?
我尝试将localhost:5000 放在那里,但是当我启动应用程序并转到localhost:5000/app 时,它会将我重定向到显示“应用程序未授权使用 CAS”的页面。取而代之的是,将我大学的 moodle 站点放在它的位置上不会出现此问题,并且会在身份验证后重定向到 moodle(我们大学的 Moodle 也使用 CAS)。
我知道这是一种防止恶意服务使用 CAS 的安全功能,但这是否意味着仍处于早期开发阶段的每个服务都必须向 CAS 注册? 或者是否有某种解决方法,我可以使用而无需与大学管理员交谈?
【问题讨论】:
标签: javascript node.js express authentication cas