Anybody tried to use WInRT's WebAuthenticationBroker for Authentication with CSLA, How would that work?
WebAuthenticationBroker runs on the client, and it seems that CSLA like to have it on the server.
Any ideas ?
You should be able to put the RunLocal attribute on your identity class's DataPortal_Fetch method to force it to run locally, and then invoke the client component.
I tried that and then changed my mind and tried to do the same as in the code that comes with the data-portal book, so basically I authenticate with the WebAuthenticationBroker and I send the token to the backend so I can get the username using
CustomPrincipal.BeginLogin(auth.AuthenticationType, token, (ex) =>
...
I have both CustomIdentity and CustomPrincipal in both my .Net4.5 and WinRT using the same namespace and assembly name
I've configured my web.config on the server to use IAuthorizeDataPortal
<appSettings>
<add key="CslaAuthentication" value="Windows"/>
<add key="CslaAuthorizationProvider" value="DealerliveLib.AuthorizeDataPortal, DealerliveLib"/>
</appSettings>
But it is never called
That's my webconfig configuration for WinRT - Mobile portal
<service behaviorConfiguration="WcfPortalBehavior" name="Csla.Server.Hosts.Mobile.WcfPortal">
<endpoint address="" binding="basicHttpBinding" contract="Csla.Server.Hosts.Mobile.IWcfPortal" bindingConfiguration="basicHttpBinding_IWcfPortal">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
I also have a MobilePortal.svc
<% @ServiceHost Service="Csla.Server.Hosts.Mobile.WcfPortal" %>
I'm sure it has to do with configuration but for the life of me, I can't tell what it is.
Thanks
Where should I look? what do you think happen here
Because the broker needs to run on the client, you should mark the DataPortal_Fetch method in your custom identity class with the RunLocal attribute. This will make that code run locally, without going across the data portal to the app server.
Instead of using the broker I'm using (like Silverlight) a username password that I'm trying to verify on the server, so I configured the website / WCF so it is the same as the Silverlight example in the data portal book 04-DataPortal-110504\Authentication\Custom (described above) now it does not seem to be configured right as the IAuthorizedDataPortal does not get called.
I'm using Windows 8, IIS8 VS2012, CSLA 4.5.10 from NuGet
It seems to be configured right, but for some reason IAuthorizedDataPortal does not get fired?
Does the data portal call succeed? If so, is the 'server-side' code running on the client?
If it doesn't succeed, what is the exception stack trace?
Here is the flow
On the client i'm calling
CustomPrincipal.BeginLogin(userName, password, (ex) =>
{
dialog = null;
if (ex != null)
{
dialog = new MessageDialog(ex.ToString(), "Error");
dialog.ShowAsync();
}
if (Csla.ApplicationContext.AuthenticationType == "Windows")
{
Csla.ApplicationContext.ClientContext["Username"] = Csla.ApplicationContext.User.Identity.Name;
}
});
Sill on the client but in the CustomPrincipal
public static void BeginLogin(string username, string password, Action<Exception> completed)
{
CustomIdentity.GetCustomIdentity(username, password, (o, e) =>
{
if (e.Error != null)
Logout();
else
Csla.ApplicationContext.User = new CustomPrincipal(e.Object);
completed(e.Error);
});
Again on the client
public static void GetCustomIdentity(string username, string password, EventHandler<DataPortalResult<CustomIdentity>> callback)
{
DataPortal.BeginFetch<CustomIdentity>(new UsernameCriteria(username, password), callback);
}}
No surprise here, placing a breakpoint on DataPortal.BeginFetch
It stops there , then it completes without errors
completed(e.Error); in GetCustomIdentity has no error
I'm also monitoring WCF and it does sent the Fetch command over
Related Activity Name Receive bytes on connection http://localhost:44896/DealerliveMobilePortal.svc'.
Related Activity Name Process action 'http://ws.lhotka.net/WcfDataPortal/IWcfPortal/Fetch'.
Related Activity Name Execute 'Csla.Server.Hosts.Mobile.IWcfPortal.Fetch'.
It stops there, and I receive NO error, I'm puzzled
Thanks for the help
Can you add a breakpoint in the callback for GetCustomIdentity? If there is no error then that code should execute and you can examine the value of e to see what it contains.
There is no error, and e contains
e = {Csla.DataPortalResult<xxxxx.CustomIdentity>}
e.Object = xxxx.CustomIdentity
xxx.CustomIdentity.AuthenticationType = "Custom"
xxx.CustomIdentity.IsAuthenticated = "False"
...
e.UserState = null
The "server side" code was never executed...
It sounds like the fetch operation is running then, because you get back a valid object.
Are you certain the server-side code _isn't_ actually running and just failing to authenticate the user?
Well, I've put break point and they don't break and second I did hard code the isAuthenticated = true and the name of the user as a test. it returns false and null ...
Also when i first start my App shouldn't the AuthorizeDataPortal be fired if setup properly?
It is true that every data portal call to the server should invoke the IAuthorizeDataPortal provider, yes.
However, I frequently have issues (especially with WinRT clients) where my server-side breakpoints are ignored. I wonder if that's what is happening here?
Even so, I would have my hard coded values in the CustomIdentity, and they are not there, that's why i'm thinking it is configuration, something I forgot to do, i'm new to CSLA so that's a possibility.
I agree that something odd is happening :)
At the same time, some code somewhere is initializing the business object, or you couldn't get one back from the data portal.
You don't have RunLocal on your DataPortal_Fetch method now right? And your identity class inherits from CslaIdentityBase?
well well, you are right about the breakpoint it does not stop, that sucks, I can now prove that it works , thanks for your insight , the problem was related to an async/await call I was doing in DataPortal_Fetch, as soon as I removed it, it worked.
Now if I can prove that the AuthorizeDataPortal is really being called i'll be all set. thanks again
and maybe we should talk to someone about that breakpoint not working using WinRT and CSLA debugging will be hard :-(
Do you have an idea why it does not break to a break point on the server side? It is reallllly annoying.
thanks
Rocky
I found a way to enable debugging of the Server side of a Windows store app using CSLA.
First step is to start the web site project
Second is to right-click on the Windows Store App project click Debug - Start new instance
I tried it several times and I can debug both the WinRT app and the backend successfully.
Hope that help others
Thanks
You can then probably just setup multiple start up projects, then you can just hit F5.
Interesting, how do you set that up?
Copyright (c) Marimer LLC