Identity.Authenticate Method ()

Authenticates a user by displaying a Sign In dialog box.

Namespace: Microsoft.WindowsLive.Id.Client
Assembly: Microsoft.WindowsLive.Id.Client (in microsoft.windowslive.id.client.dll)
Syntax

VisualBasicDeclaration
Public Function Authenticate As Boolean
CSharp
public bool Authenticate ()
ManagedCPlusPlus
public:
bool Authenticate ()
JSharp
public boolean Authenticate ()
JScript
public function Authenticate () : boolean

Return Value

true if the user was successfully authenticated; otherwise, false. The default is false.
Exceptions

Exception typeCondition
WLLogOnException

For more information about the conditions under which the WLLogOnException is thrown, see ErrorString.

Remarks

Use Authenticate to authenticate a user using the Sign In dialog box (shown below). Authenticate displays the modal Sign In dialog box for users to enter their Windows Live ID.

Bb404839.9f9a6caf-1e88-413e-a988-a6656a700e5d(en-us,MSDN.10).gif

Upon successful authentication, IsAuthenticated returns true and many of the other methods and properties of the Identity object are initialized for use.

If a user has stored his or her credentials on the computer and you want to implement automatic sign-in for the default user of your application, use the Authenticate method instead. For more information, see Implementing Automatic Sign-in.


Example

The following example shows how to use Authenticate to authenticate a user with the Sign In dialog box in response to a button click. The oId variable represents an instance of the Identity class. For more information, see Implementing Authentication.

        //Event handler for Sign-In/Sign-Out button clicks.
        private void buttonSignInOrOut_Click(object sender, EventArgs e)
        {
            //Check to see if the user is not currently authenticated.
            if (!oID.IsAuthenticated)
            {
                try
                {
                    //Try to authenticate the user by showing the Sign-In dialog window.
                    if (oID.Authenticate())
                    {
                        currentUserName = oID.UserName;
                    }
                    else
                    {
                        MessageBox.Show("Authentication failed");
                    }
                }
                catch (WLLogOnException wlex)
                {
                    //Check to see if FlowUrl is defined.
                    if (wlex.FlowUrl != null)
                    {
                        //If FlowUrl is defined, direct user to the web page to correct the error.
                        MessageBox.Show(wlex.ErrorString + "Please go to " + wlex.FlowUrl.AbsoluteUri + "to correct the condition that caused the error");
                    }
                    else
                    {
                        //If FlowUrl is not defined, simply display the ErrorString.
                        MessageBox.Show(wlex.ErrorString);
                    }
                }
            }
            else
            {
                //If user is authenticated, they intended to Sign-Out. Try signing the user out.
                try
                {
                    oID.CloseIdentityHandle();
                    currentUserName = "";
                }
                catch (WLLogOnException wlex)
                {
                    //Check to see if FlowUrl is defined.
                    if (wlex.FlowUrl != null)
                    {
                        //If FlowUrl is defined, direct user to the web page to correct the error.
                        MessageBox.Show(wlex.ErrorString + "Please go to " + wlex.FlowUrl.AbsoluteUri + "to correct the condition that caused the error");
                    }
                    else
                    {
                        //If FlowUrl is not defined, simply display the ErrorString.
                        MessageBox.Show(wlex.ErrorString);
                    }
                }
            }
            UpdateDisplay();
        }
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Development Platforms

Windows Vista, Windows XP Professional with Service Pack 2 (SP2)

Target Platforms

Windows Vista, Windows XP Professional with SP2, Windows XP Home Edition with SP2
See Also

Page view tracker