Published
Thursday, August 09, 2007 4:57 AM
by
mtaulty
Mostly for "fun", I wanted to have a go at launching the CardSpace Identity Selector from managed code inside of a Silverlight application rather than from HTML.
I ended up with something like this;
That rectangle at the top left is my "CardSpaceButtonControl" which simply takes an ImageSource to display and a set of RequiredClaims and will then fire an event when someone clicks on it and that event contains the token that we got back from CardSpace.
So, usage is something like;
<Canvas x:Name="parentCanvas"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="Page_Loaded"
x:Class="SilverlightProject14.Page;assembly=ClientBin/SilverlightProject14.dll"
Width="640"
Height="480"
Background="Silver"
xmlns:ctl="clr-namespace:SilverlightProject14;assembly=ClientBin/SilverlightProject14.dll"
>
<ctl:CardSpaceButtonControl
x:Name="csControl"
ContainingHtmlElement="PlaceHolder"
ImageSource="icard.png"
Canvas.Left="20"
Canvas.Top="20"
Width="150"
Height="100"
RequiredClaims="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier"
CardSpaceTokenAvailable="OnCardSpaceTokenAvailable"
/>
<Canvas Background="White" Canvas.Top="130" Canvas.Left="20" Width="600" Height="340">
<Canvas.Clip>
<RectangleGeometry Rect="0, 0, 600, 340"/>
</Canvas.Clip>
<TextBlock x:Name="tokenTxt" TextWrapping="WrapWithOverflow" Width="600" Height="340"/>
</Canvas>
</Canvas>
and then when that event OnCardSpaceTokenAvailable fires, I just do;
void OnCardSpaceTokenAvailable(object sender, CardSpaceTokenEventArgs args)
{
tokenTxt.Text = args.CardSpaceToken;
}
So, after going through the identity selector dialog we end up with something like;
with the token which I could then perhaps send somewhere. I'm not sure that this is a particularly useful thing to be able to do :-) but it was something that I was playing with from the point of view of manipulating the HTML DOM from some managed code.
The code project is here - it's a bit hacky and lacks exception handling but you might do something with it if you wanted to. You'd need to host it over HTTPS and provide it with an image that it can use for display purposes.