【问题标题】:Problem with authentication in REST WCFREST WCF 中的身份验证问题
【发布时间】:2011-10-18 17:33:18
【问题描述】:

我已经开发了 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 和身份验证,请任何人帮助我解决这个问题。

谢谢 阿伦。

【问题讨论】:

标签: wcf heroku


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-04-14
    • 2010-11-17
    • 1970-01-01
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    • 2011-11-27
    • 2012-03-06
    相关资源
    最近更新 更多