我一直在尝试基于由 Sql Azure 提供身份验证的 Entity Framework 模型来实现 OData 服务。我在数据库中提供行/列访问。
我希望能够从 LinqPad、Excel 等中调用它作为安全服务。
我已经尝试了standard series 中定义的各种方案。但即使返回 401,Excel 或 LinqPad 都不会记忆起我输入的用户名和密码。
所以,我想我会让用户名/密码成为查询参数(通过 SSL)。但事实证明这也是非法的(OData 需要格式正确且没有查询参数的 URL)。
所以我想,为什么不使用 WebGet 在 URL 中嵌入用户名和密码,但我不能让它与 WCF 中的 OData 源格式一起使用:
<%@ ServiceHost Language="C#"Factory="System.Data.Services.DataServiceHostFactory, System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"Service="WebApplication5.OData"%>
public class OData : DataService< MyEntities >
{
public static void InitializeService(DataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
protected override MyEntities CreateDataSource()
{
// create the OData source with the user name and password here
}
}
有没有人真正让 OData 在用户名和密码被传递到源中的地方工作?
最佳答案
我没有使用用户名和密码,但我已经通过技术上相同的 API key 进行了身份验证。在这里查看我的答案:WPF and WCF Data Services Authenticate at Query level? - 我使用 HTTP header 进行身份验证:Args.OperationContext.RequestHeaders["APIKey"])
但您可以将其更改为 Args.OperationContext.QueryString["APIKey"])
(不确定 QueryString
是否是我头顶的属性)以允许传入 ?APIKey=blah
在网址中。
关于wcf - OData 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4180849/