Sergey Shishkin

on agile software development

CardSpace SDK: Creating Managed Cards, Part 2

Ok, instead of writing a long story I’ll just post two samples from the upcoming SDK pre-release:

The “Simplest” Information Card

In this sample you will be introduced to the Information Card API and the newtelligence.CardSpace.InformationCard class it provides.

To create a managed information card simply instantiate the InformationCard class using its default constructor, set the required properties and call one of the Save method’s overloads.

Source Code

    InformationCard card = new InformationCard();


    // Specify a certificate to sign the card


        StoreLocation.LocalMachine, StoreName.My,

        X509FindType.FindBySubjectName, "");


    // Set the card’s Id and the issuer

    card.CardId = new Uri("");

    card.Issuer = new Uri("");


    // Specify a security token service for the card

    TokenServiceReference sts = new TokenServiceReference();


        // The endpoint address of the STS

        new Uri(""),

        // The same certificate is used as an identity of the STS


        // The MetadataExchange endpoint of the STS (SSL is required)

        new Uri(""));

    // The STS uses a username-password authentication

    sts.UserCredential = new UsernamePasswordCredential();



    // Specify a type of security tokens supported by the card

    card.TokenTypes.Add(new Uri(


    // Specify a type of claims supported by the card

    card.ClaimTypes.Add(new ClaimType(




Working with Cards

This sample uses the code from the previous sample to create and save a simple managed card. Then a new instance of the InformationCard class is used to load a previously created card and change its properties. The sample code sets the name and specifies an image for the card as well as other properties. In addition it changes the Security Token Service to be used with the card, and the claims that the card supports. Finally, the card is saved to the file with the same name.

Source Code

    InformationCard card = new InformationCard();


    // Load an existing card



    // Change properties’ values


    card.CardName = "newtelligence";


    card.TimeExpires = card.TimeIssued.AddYears(1);

    card.RequireAppliesTo = true;

    card.PrivacyNotice = new Uri(


    card.PrivacyNoticeVersion = 3;


    // Token services



    TokenServiceReference sts = new TokenServiceReference();


        new Uri(""),


        new Uri(""));

    sts.UserCredential = new KerberosV5Credential();



    // Claims



    ClaimType claimName = new ClaimType(


    claimName.DisplayTag = "Last Name";

    claimName.Description = "Surname or family name of a subject";



    ClaimType claimCustom = new ClaimType(


    claimCustom.DisplayTag = "Custom Claim";

    claimCustom.Description = "This is a custom claim";



    // Save the card to the same file



Written by Sergey Shishkin

08.05.2007 at 09:46

Posted in Uncategorized

%d bloggers like this: