OData Authentication

I am trying to implement an OData service based on an entity framework model where authentication is provided by Azure Sql. I provide access to a row / column in the database.

I want this to be able to be called from LinqPad, Excel, etc. as a safe service.

I tried various schemes defined in the standard series, but even when returning 401, neither Excel nor LinqPad remembers the username and password I entered.

So, I thought I would make the username / password a request parameter (via SSL). But it turns out that this is illegal (OData requires a well-formed URL without request parameters).

So, I thought: why not use WebGet to embed the username and password in the URL, but I cannot get this to work with the original OData 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 really got OData to work where the username and password are passed into the source code?

+3
source share
2 answers

, API, . . : WPF WCF ? - HTTP- : Args.OperationContext.RequestHeaders["APIKey"]), Args.OperationContext.QueryString["APIKey"]) ( , QueryString ), ?APIKey=blah URL.

+1

OData Silverlight #, Uri (Url) , , :

ServiceReference1.NAV nav = ServiceReference1.NAV( Uri ( "HTTP:...../OData/Company ( 'company_name')/" ));

nav.Credentials = System.Net.NetworkCredential( "", "", "" );

0

Source: https://habr.com/ru/post/1774851/


All Articles