【问题标题】:Authenticating a dummy service with CAS authentication in node在节点中使用 CAS 身份验证对虚拟服务进行身份验证
【发布时间】: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


    【解决方案1】:

    来自CAS documentation:

    当在您的 CAS 服务注册表中找不到请求的应用程序/服务 url 时,您可能会遇到此错误。当向 CAS 登录端点提交身份验证请求时,目标应用程序将显示为 url 参数,该参数将根据 CAS 服务注册表进行检查,以确定是否允许应用程序使用 CAS。如果未找到该 url,将显示此消息。由于注册表中的服务定义可以通过 url 模式定义,因此完全有可能注册表中服务定义的模式配置错误,并且不会成功匹配请求的应用程序 url。

    所以,

    这是否意味着所有仍处于早期开发阶段的服务都必须向 CAS 注册?

    是的。如果你想使用别人的系统,无论如何都需要他们的许可。

    或者是否有某种解决方法,我可以使用而无需与大学管理员交谈?

    没有解决方法。但是,您可以设置自己的 CAS 服务器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 1970-01-01
      • 2017-03-11
      • 1970-01-01
      • 2011-08-29
      • 2013-08-20
      相关资源
      最近更新 更多