Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OData Authentication

I have been trying to implement an OData service based upon an entity framework model where the authentication is provided by Sql Azure. I provide row/column access within the database.

I want to be able to call this from LinqPad, Excel, etc. as a secure service.

I have tried the various schemes defined in the standard series but even though returning 401, neither Excel or LinqPad recall with the user name and password I've entered.

So, I thought I'd make the user name/password a query parameter (over SSL). But it turns out that's illegal as well (OData requires a well formed URL with no query parameters).

So then I thought, why not use WebGet to embed the user name and password in the URL but I can't get that to work with the OData source format in WCF:

<%@ 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
}
}

Has anyone actually got OData to work where the user name and password are passed into the source?

like image 752
jsh_ec Avatar asked Sep 24 '26 04:09

jsh_ec


1 Answers

I've not used a username and password per-say but I have authenticated by an API key which is technically the same. See my answer here: WPF and WCF Data Services Authenticate at Query level? - I use HTTP headers to authenticate: Args.OperationContext.RequestHeaders["APIKey"]) but you can change this to Args.OperationContext.QueryString["APIKey"]) (not sure if QueryString is a property of the top of my head) to allow passing in ?APIKey=blah in the URL.

like image 82
eth0 Avatar answered Sep 28 '26 10:09

eth0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!