views:

55

answers:

1

Hello,

I would like to add simple authentication to Data Services, for now only to restrict access for particular applications by simple token.

I don't need Domain Authentication or Forms authentication.

I read a lot about authentication here:

http://franssenden.wordpress.com/2010/06/14/custom-security-odata-service-wcf-data-services/

http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/06/03/10482.aspx

http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/01/15/10119.aspx

http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/01/10/10100.aspx

Unfortunately it all demands a loooot of work. Most of all creating custom IHttpModule. There should be more simple solution.

I know that when I create object context on the client (WPF) I can add Credentials.

Uri uri = new Uri("http://localhost/myapp/odata.svc");

MyEntities ent= new MyEntities (uri);
ent.Credentials = new NetworkCredential("token", "zx5as9vxc5sa9h0vb6523cv56");

But where can I read them (without implementation of custom IHttpModule)?

I thought that I can use something in class that is implementation of Data Service for example:

protected override void OnStartProcessingRequest(ProcessRequestArgs args)
{
 string cred = args.OperationContext.AbsoluteRequestUri.UserInfo;
}

I'm not familiar with UserInfo but description for it stands "Gets the user name, password, ...)

So I have two main questions:

  1. Where can I read Credentials included by typing ent.Credentials = new NetworkCredential("token", "zx5as9vxc5sa9h0vb6523cv56");

  2. Where can I (if I can) set UserInfo on the client app and use it in OnStartProcessingRequest method.

Regards, Daniel Skowroński

+1  A: 

There's a series of post about authentication and WCF Data Services (which is the .NET implementation of the OData protocol): http://blogs.msdn.com/b/astoriateam/archive/tags/authentication/

You should be able to find lot more information there (including code samples).

Vitek Karas MSFT
Thanks, I used http://blogs.msdn.com/b/astoriateam/archive/2010/07/21/odata-and-authentication-part-6-custom-basic-authentication.aspx to create authentication functionality. I did it without creating custom custom HttpModule, simply SSL + client evnt ctx.SendingRequest +=new EventHandler<SendingRequestEventArgs>(OnSendingRequest); + server side in OData Service event protected override void OnStartProcessingRequest(ProcessRequestArgs args)
Daniel

related questions