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)
Public Function Authenticate As Boolean
public bool Authenticate ()
public:
bool Authenticate ()
public boolean Authenticate ()
public function Authenticate () : boolean
Return Value
true if the user was successfully authenticated; otherwise, false. The default is false.
| Exception type | Condition |
|---|
| WLLogOnException |
For more information about the conditions under which the WLLogOnException is thrown, see ErrorString.
|
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.
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.
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();
}
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
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