Join LiveSide!
Sign In using: Name/Password OpenID
or Live ID: Sign In Live ID
0 out of 8,034 members
are online, & 30 guest(s).

Recent Comments

Log in or Join to leave a comment!

LiveSide on Mobile

Our latest posts and our favorite links,
all on your phone or mobile device
Visit m.LiveSide.net
Or go to www.LiveSide.net
on your mobile device and we'll redirect you!

Tweets We Like

Loading...

LiveSide Time

Redmond

Dallas (server)

London

Shanghai

Windows Live Calendar

PDC LA Nov 17-19

   www.microsoftpdc.com

Follow us on Facebook

    LiveSide.net
   
    Promote Your Page Too

  • LiveSide on the Windows Live Network
  • LiveSide on Facebook
  • LiveSide on Twitter
  • LiveSide RSS  
  • Windows Live Alerts
  •  
  • feedburner
  •  
LiveSide - Developer Blog

LiveFX + Windows Live ID Client SDK = Safer Program

Building an application that uses the LiveFX is easy. So is building an application that uses Windows Live ID. Using the Windows Live ID Client SDK also means that you’re not asking a user to supply your application with the username and password which means that the user can remain safe that they’re not just giving out their username and password for the program to with as he wishes. So if both sorts of programs are easy, is it easy to combine the two? Well, yes.

In Visual Studio, I created a quick Windows Form that looks like the following:

LiveFXWLIDClientVSForm

In the references, we need the following:

LiveFXClientSDKReferences

To start off with, let’s initialise the program:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsLive.Id.Client;
using Microsoft.LiveFX.Client;
using Microsoft.LiveFX.ResourceModel;

namespace LiveFXBrowser
{
    public partial class frmMain : Form
    {
        private const string baseUri = "https://user-ctp.windows.net/";
        private LiveOperatingEnvironment loe = new LiveOperatingEnvironment();
        private IdentityManager idmgr;
        private Identity id;

        public frmMain()
        {
            InitializeComponent();
            try
            {
                // Create an instance of the ID Manager for the WLID Client
                idmgr = IdentityManager.CreateInstance("ScottIsAFool;wlm@scottisafool.co.uk;LiveFX Browser", "LiveFX Browser");
                id = idmgr.CreateIdentity();                
            }
            catch
            {
                // TODO: Something
            }
        }

Then, let’s look at the code for when we click on the sign in button:

        private void llSignInSignOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
                if (!id.IsAuthenticated)
                {

                    // Load the WLID Sign in window
                    id.Authenticate();

                    if (id.IsAuthenticated)
                    {
                        // Create the Uri for the LiveFX
                        Uri uri = new Uri(baseUri);
                        // Get the authenticated token for the user for LiveFX
                        string token = id.GetTicket("user-ctp.windows.net", "MBI_SSL", true);
                        // Connect to the LiveFX
                        loe.Connect(token, AuthenticationTokenType.UserToken, uri, new LiveItemAccessOptions(true));

                        // Set the footer status and sign in text to indicate signed in.
                        tsStatusFooter.Text = "Signed in as: " + loe.Mesh.ProvisionedUser.Name + ".";
                        llSignInSignOut.Text = "Sign out";

                        Profile prof = loe.Profiles.Entries.Single(p => p.Resource.Title == "GeneralProfile");
                        var _messengerPSM = (GeneralProfile)prof.Resource.ProfileInfo;

                        txbxMessengerPSM.Text = _messengerPSM.PersonalStatusMessage;
                    }
                }
                else
                {
                    // Close the WLID session
                    id.CloseIdentityHandle();
                    tsStatusFooter.Text = "Not signed in";
                    llSignInSignOut.Text = "Sign in.";
                }
        }

As you can see, the code is similar from both previous projects. The comments in the code should be self explanatory.

The finished program and steps, look like the following:

LiveFXWLIDClientStep1

LiveFXWLIDClientStep2[4]

LiveFXWLIDClientStep3

And there you have it.

If you want to check this out, the source (and the built app) are available from my SkyDrive area.

Download

SL

Sign In Live ID using Live ID, Name/Password, or OpenID
or Join LiveSide to leave a comment!