REST WCF 中的身份验证问题

发布于 2024-11-30 10:37:44 字数 1736 浏览 0 评论 0原文

我已经开发了 REST WCF 并在 web.config 中设置了以下方式的绑定

<bindings>
  <webHttpBinding>
    <binding name="secureBasic">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>

<serviceBehaviors>
    <behavior name="ServiceBehaviour" >
      <serviceCredentials>
        <userNameAuthentication customUserNamePasswordValidatorType="RestService.CustomUsernamePasswordValidator, RestService"
                            userNamePasswordValidationMode="Custom" />
      </serviceCredentials>
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>

  </serviceBehaviors>

在 CustomUsernamePasswordValidator.cs 文件中,我通过以下方式对用户进行了身份验证

namespace RestService
{
public class CustomUsernamePasswordValidator : UserNamePasswordValidator
{
    public override void Validate(string userName, string password)
    {
        if (!AuthenticateUser(userName, password))
            throw new SecurityTokenValidationException("Invalid Username or Password");
    }

    private bool AuthenticateUser(string userName, string password)
    {
        if (userName == "myaddon" && password == "mypassword")
        {
            return true;
        }
        else
            return false;
    }
}
}

现在的问题是,当我从同一个项目使用此服务时,它运行良好,但对为什么要进行此调用感到困惑验证不会发生?

另外,当我从 ruby​​ commnad propmpt 测试我的heroku清单插件文件时,它给了我错误 认证失败!!我认为这是我的 REST WCF 应用程序的问题。

如果有人非常了解 WCF 和身份验证,请任何人都可以帮助我解决这个问题。

谢谢 阿伦.

I have developed REST WCF and set binding following way in web.config

<bindings>
  <webHttpBinding>
    <binding name="secureBasic">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>

<serviceBehaviors>
    <behavior name="ServiceBehaviour" >
      <serviceCredentials>
        <userNameAuthentication customUserNamePasswordValidatorType="RestService.CustomUsernamePasswordValidator, RestService"
                            userNamePasswordValidationMode="Custom" />
      </serviceCredentials>
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>

  </serviceBehaviors>

And in CustomUsernamePasswordValidator.cs file i have authenticate user by following way

namespace RestService
{
public class CustomUsernamePasswordValidator : UserNamePasswordValidator
{
    public override void Validate(string userName, string password)
    {
        if (!AuthenticateUser(userName, password))
            throw new SecurityTokenValidationException("Invalid Username or Password");
    }

    private bool AuthenticateUser(string userName, string password)
    {
        if (userName == "myaddon" && password == "mypassword")
        {
            return true;
        }
        else
            return false;
    }
}
}

Now problem is that it is running nice when i will use this service from same project but confused that why this call would not occurred for validation?

Also when i test my heroku manifest addon file from ruby commnad propmpt it give me error of
Failed Authentication !! I think this is issue of my REST WCF Application.

Please anyone can help me to solve this issue if anyone know very well about WCF and authentication.

Thanks
Arun.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月苍老的讽刺 2024-12-07 10:37:44

最后,我直接使用 WebOperationContext 处理自定义身份验证并跳过 Web.Config 设置。

Finally i have handle custom authentication using WebOperationContext directly and skip the Web.Config settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文