Search code examples
c#.netwcfwcf-data-serviceswcf-security

Getting the IsAuthenticated status on WCF Data Services within the client


I have a wcf data service which authenticates the user with custom basic authentication. I used the tutorial on MSDN Blogs OData and Authentication – Part 6 – Custom Basic Authentication. So after authenticating the user against a database, the service sets

var principal = new GenericPrincipal( new GenericIdentity("user") );
HttpContext.Current.User = principal;

Within my service I can access the principals auth status via

HttpContext.Current.Request.IsAuthenticated

Is there also a chance to get the IsAuthenticated status on my WPF client?


Solution

  • Basic authentication is performed for every request. Your client doesn't keep any state related to authentication (except pre-authentication which skips 401 handshake). If your service requires authentication you know that you are authenticated if your call to WCF-Data Service succeeds. If you are not authenticated you will receive exception.