【问题标题】:Getting the authenticated user, authed by Apache Basic Auth under Mono and ServiceStack获取经过身份验证的用户,由 Mono 和 ServiceStack 下的 Apache Basic Auth 进行身份验证
【发布时间】:2013-09-22 10:55:00
【问题描述】:

我在 C#/Mono 的 Apache2 下使用 ServiceStack 运行 Rest-Service。 Apache-Server 正在使用 SSL 和带有 htpasswd 文件的 BasicAuthentication。

如果我访问我的 Rest-Service,我会得到 apache 的 auth-Request,这很好。验证我的 RestService 后访问。现在我的问题是:我如何才能获得请求服务并对其进行身份验证的用户(apache-session 用户)? 我已经尝试获取 Environment-Variables,但没有获得所需的信息。

据我所知,ServiceStack 的内置身份验证需要我自己实现身份验证。但是我想使用apache的认证。

有人知道解决办法吗?

问候 每天

附: 以下是我的 Apache 站点配置的 Mono 和 SSL 相关部分:

   SSLEngine on
   SSLCertificateFile    /etc/apache2/ssl/apache.pem
   SSLCertificateKeyFile /etc/apache2/ssl/apache.key
   SSLOptions StrictRequire +StdEnvVars
   SSLProtocol all -SSLv2

   MonoServerPath wcs.service.de "/usr/bin/mod-mono-server4"
   MonoDebug wcs.service.de true
   MonoSetEnv wcs.service.de  MONO_IOMAP=all
   MonoAutoApplication  disabled
   MonoApplications wcs.service.de "/:/var/www/wcs"

【问题讨论】:

  • 我找到了解决办法!它由 ServiceStack RequestFilter、原始 ASP.net 请求和参数“REMOTE_USER”组成。明天将发布更详细的解决方案;)

标签: c# apache rest mono servicestack


【解决方案1】:

比发音稍晚,但这是问题的答案。

在您的 ServiceStack 服务中,您将 RequestDTO 作为参数。请参阅此链接:

https://github.com/ServiceStack/ServiceStack/wiki/Access-HTTP-specific-features-in-services

在服务点下,您可以看到我的意思。您不需要我在上面的回答中建议的 RequestFilter 。但是..你有这个Servicestack的IHttpRequest。在此对象上,您可以获得 OriginalRequest。这是原始的 ASP.net-Request。您必须将结果转换为 HttpRequest (ASP.net)。

var orgRequest = (HttpRequest)request.OriginalRequest;

在这个新铸造的对象上,您有一个可访问的字段 Param。您现在可以获得包含我需要的 SSL 用户的 REMOTE_USER 参数。

var sslUser = orgRequest.Param["REMOTE_USER"];

我希望这可以帮助遇到同样问题的人。

每天的问候

【讨论】:

    猜你喜欢
    • 2014-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-11
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    相关资源
    最近更新 更多