Print Page | Close Window

ODATA and LoginManager

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3085
Printed Date: 13-May-2026 at 8:27am


Topic: ODATA and LoginManager
Posted By: antalakas
Subject: ODATA and LoginManager
Date Posted: 07-Nov-2011 at 2:01pm
Hello,

I am building an application that implements IEntityLoginManager to provide custom User/Role management.
I need to add an ODATA service. When i try to get an entity with my odata client, i get an IdeaBlade.EntityModel.LoginException, with message : No credentials supplied.

I agree that this is true. How can i add credentials using ODATA?

Andreas


-------------
Andreas Ntalakas



Replies:
Posted By: DenisK
Date Posted: 08-Nov-2011 at 10:29am
Hi Andreas

In general, to secure OData service we can use Forms Authentication ( http://msdn.microsoft.com/en-us/data/gg192996 - http://msdn.microsoft.com/en-us/data/gg192996 ) or Basic Authentication ( http://msdn.microsoft.com/en-us/data/gg192997 - http://msdn.microsoft.com/en-us/data/gg192997 ) where the credentials are passed in the Authorization header of a client request. The credentials in turn will be passed to the IEntityLoginManager.

Hope this helps.


Posted By: Chrizy
Date Posted: 21-Feb-2012 at 4:53am
Hi,
Do you have any code examples showing ODATA being used with a custom Login Manager and Basic Authentication?

I'm not currently even getting the No credentials error when viewing via the browser.
getting "The server encountered an error processing the request. See server logs for more details." and cant see any error logged.

Thanks
Chris


Posted By: Thomas
Date Posted: 21-Feb-2012 at 11:57pm
I would be also interested in such an example using ODATA.


Posted By: DenisK
Date Posted: 22-Feb-2012 at 12:27pm
Hi Chrizy and Thomas,

We currently don't have such samples but I've submitted a feature request to provide it in the future.

Chrizy, if you can provide me with your DebugLog.xml that DevForce generates, I can try and help you with the server error.


Posted By: Chrizy
Date Posted: 28-Feb-2012 at 2:06am
uploads/1374/DebugLog.zip - uploads/1374/DebugLog.zip

Debug file attached.

Thanks
Chris


Posted By: DenisK
Date Posted: 28-Feb-2012 at 6:20pm
The DebugLog doesn't record anything of significance either. Would you mind zipping up your project, upload it somewhere and let me know where to get it? You can PM me if you prefer. Thanks.


Posted By: DenisK
Date Posted: 29-Feb-2012 at 8:21pm
Hi Chris,

Thanks for the project. Here's what's happening.

You've added some custom properties on the Group and PropertyToSaleOrLet entities that are non-serializable types. You have to add them to the IgnorePropertiesAttribute like below.

  [IgnoreProperties(@"EntityAspect", @"TypeID")]
  public partial class Group : IbEm.Entity {..........}

  [IgnoreProperties(@"EntityAspect", @"PriceQualifierIDenum")]
  public partial class PropertyToSaleOrLet : IbEm.Entity {......}

For the time being, you can hook into the code generation for IgnorePropertiesAttribute by overriding the default T4 template. A feature request has been submitted for this to be supported without messing with the code generation.

See  http://www.ideablade.com/forum/forum_posts.asp?TID=2578&title=odata-and-ignoreproperties-attribute - http://www.ideablade.com/forum/forum_posts.asp?TID=2578&title=odata-and- - ignoreproperties-attribute  for my response to another customer with the same issue.


Posted By: Chrizy
Date Posted: 07-Mar-2012 at 1:44am

Thanks that fixed the error, I have set up a test client to the pass basic authentication header, but when my custom login manager gets called the credentials are null. I've tried creating a BasicAuthenticationModule which creates an instance of the EnityManager and calls the Login method, and also putting the service in a separate folder and setting IIS to use Basic Authentication. In my test environment I'm not using https could this be the problem?

Thanks
Chris



Posted By: DenisK
Date Posted: 07-Mar-2012 at 5:08pm
Hi Chris,

Could you zip up and send me your sample project again so I can take a look? Again, you can use PM if you prefer. Thanks.


Posted By: DenisK
Date Posted: 08-Mar-2012 at 5:18pm
Hi Chris,

Thanks for the sample.

In your custom LoginManager, you have to get the Authorization header, decode the credential and create your own LoginCredential.

public IPrincipal Login(ILoginCredential credential, EntityManager entityManager) {
      
      string authHeader = HttpContext.Current.Request.Headers["Authorization"];
      var creds = ParseAuthHeader(authHeader);
      credential = new LoginCredential(creds[0], creds[1], "");
      if (credential == null) {
         throw new LoginException(LoginExceptionType.NoCredentials, "No credentials supplied");
      }
      
}


Posted By: Chrizy
Date Posted: 12-Mar-2012 at 3:17pm
Hi,
That worked, thanks for the quick response.

Chris



Print Page | Close Window