WL.getSession
Retrieves the current session object synchronously, if a session object exists for a Windows Store app using JavaScript or web app.
For situations in which performance is critical, such as page loads, use the asynchronous WL.getLoginStatus method instead.
Parameters
This function has no parameters.
Return value
Returns the current session as a session object instance. The session object contains the following properties.
Property |
Type |
Description |
||
---|---|---|---|---|
access_token |
string |
The user's access token. |
||
authentication_token |
string |
The authentication token. |
||
scope |
Array of string values |
A list of scopes that the app has requested and that the user has consented to.
|
||
expires_in |
number |
The amount of time remaining, in seconds, until the user's access token expires. Note This property is not available for Windows Store apps using JavaScript. |
||
expires |
number |
The exact time when the session will expire. This time is expressed in the number of seconds since 1 January, 1970. Note This property is not available for Windows Store apps using JavaScript. |
Example
The following example uses an event handler, onSessionChange, to handle the auth.sessionChange event. When called, onSessionChange calls WL.getSession to get the session object.
function onSessionChange() {
var session = WL.getSession();
if (session) {
document.getElementById("infoLabel").innerText =
"Something about the session changed.";
}
else {
document.getElementById("infoLabel").innerText =
"Signed out or session error.";
}
}
Requirements
Library |
Wl.js |