Sergey Shishkin

on agile software development

Archive for May 2007

CardSpace SDK “CTP1”

The first Community Technology Preview of the SDK is available for download.

Call to Action
  1. Download the SDK
  2. Play with the samples in it
  3. Give me your feedback!
  4. Be prepared for the “CTP2”

Written by Sergey Shishkin

08.05.2007 at 18:59

Posted in Uncategorized

CardSpace SDK: Creating Managed Cards, Part 3

One more sample from the upcoming SDK:


Using the Configuration

To simplify the process of the creation of information cards and to increase the maintenance capabilities of applications the Information Card API provides support for the .NET Configuration. The <cardSpace> configuration section and the <newCard> configuration element can be used to predefine the information card’s properties in the application configuration file. The call to the static InformationCard.Create method will return then a new information card based on the predefined values.

Source Code

App.config

    <cardSpace>

        <newCard

            language ="en-US"

            cardId ="http://cardspace.newtelligence.com/cards/"

            cardVersion ="2"

            cardName ="newtelligence"

            cardImage ="card.png"

            issuer ="http://cardspace.newtelligence.com/ip"

            timeExpires ="2008-01-01"

            requireAppliesTo ="false"

            >

            <tokenServices>

                <add

                    uri ="http://cardspace.newtelligence.com/sts"

                    mex ="https://cardspace.newtelligence.com/sts/mex"

                    >

                    <identity

                        storeLocation ="LocalMachine"

                        storeName ="My"

                        findType ="FindBySubjectName"

                        findValue ="http://www.fabrikam.com"

                        />

                    <usernamePasswordCredential />

                </add>

            </tokenServices>

            <claimTypes>

                <add

                    id ="http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname"

                    displayTag ="Last Name"

                    description ="Surname or family name of a subject"

                    />

                <add

                    id ="http://cardspace.newtelligence.com/claims/custom"

                    displayTag ="Custom Claim"

                    description ="This is a custom claim"

                    />

            </claimTypes>

            <tokenTypes>

                <add type ="urn:oasis:names:tc:SAML:1.0:assertion" />

            </tokenTypes>

            <privacyNotice

                location ="http://cardspace.newtelligence.com/ip/privacy"

                version ="3"

                />

            <signingCertificate

                storeLocation ="LocalMachine"

                storeName ="My"

                findType ="FindBySubjectName"

                findValue ="http://www.fabrikam.com"

                />

        </newCard>

    </cardSpace>

Program.cs

    // Create a new card using config settings

    InformationCard card = InformationCard.Create();

 

    // Set the actual CardId based on the config settings

    card.CardId = new Uri(card.CardId, "1");

 

    // Set the Username property for the UserCredential object

    TokenServiceReference service = card.TokenServices[0];

    UsernamePasswordCredential credential =

        (UsernamePasswordCredential)service.UserCredential;

    credential.Username = "bob";

 

    card.Save("card.crd");

Written by Sergey Shishkin

08.05.2007 at 09:51

Posted in Uncategorized

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

    card.SetSigningCertificate(

        StoreLocation.LocalMachine, StoreName.My,

        X509FindType.FindBySubjectName, "www.fabrikam.com");

 

    // Set the card’s Id and the issuer

    card.CardId = new Uri("http://cardspace.newtelligence.com/cards/1&quot;);

    card.Issuer = new Uri("http://cardspace.newtelligence.com/ip&quot;);

 

    // Specify a security token service for the card

    TokenServiceReference sts = new TokenServiceReference();

    sts.SetEndpointReference(

        // The endpoint address of the STS

        new Uri("http://cardspace.newtelligence.com/sts&quot;),

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

        card.SigningCertificate,

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

        new Uri("https://cardspace.newtelligence.com/sts/mex&quot;));

    // The STS uses a username-password authentication

    sts.UserCredential = new UsernamePasswordCredential();

    card.TokenServices.Add(sts);

 

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

    card.TokenTypes.Add(new Uri(

        "urn:oasis:names:tc:SAML:1.0:assertion"));

    // Specify a type of claims supported by the card

    card.ClaimTypes.Add(new ClaimType(

        "http://cardspace.newtelligence.com/claims/custom-claim&quot;));

 

    card.Save("card.crd");


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

    card.Load("card.crd");

 

    // Change properties’ values

    card.CardVersion++;

    card.CardName = "newtelligence";

    card.SetImageFromFile("card.png");

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

    card.RequireAppliesTo = true;

    card.PrivacyNotice = new Uri(

        "http://cardspace.newtelligence.com/ip/privacy&quot;);

    card.PrivacyNoticeVersion = 3;

 

    // Token services

    card.TokenServices.Clear();

 

    TokenServiceReference sts = new TokenServiceReference();

    sts.SetEndpointReference(

        new Uri("http://cardspace.newtelligence.com/sts/kerberos&quot;),

        card.SigningCertificate,

        new Uri("https://cardspace.newtelligence.com/sts/mex&quot;));

    sts.UserCredential = new KerberosV5Credential();

    card.TokenServices.Add(sts);

 

    // Claims

    card.ClaimTypes.Clear();

 

    ClaimType claimName = new ClaimType(

        "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname&quot;);

    claimName.DisplayTag = "Last Name";

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

    card.ClaimTypes.Add(claimName);

 

    ClaimType claimCustom = new ClaimType(

        "http://cardspace.newtelligence.com/claims/custom&quot;);

    claimCustom.DisplayTag = "Custom Claim";

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

    card.ClaimTypes.Add(claimCustom);

 

    // Save the card to the same file

    card.Save("card.crd");

Written by Sergey Shishkin

08.05.2007 at 09:46

Posted in Uncategorized