Can we dynamically load Windows Live messenger? Yes, we can (despite what the docs say)
One of the attributes of the <msgr:app> tag is based on the hash of appid, secret key and dum dum dum the timestamp. Yes this last one means that it has a lifetime, 45 mins i think. So you can't just server this as a static page, or cache your pages or add 304 headers, without breaking something.
On high trafficked sites, not having flexibility to optimise is a big step backwards...
Fortunatly some of my colleagues had come up with a solution which i've bundled into a demo to feed your appetite.
Demo
Try out the demo here http://sandbox.knarly.com/winlive/loader.html
Code (loader.html)
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get Started with the Windows Live Messenger Web Toolkit - Dynamic Loading</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js"></script>
<script type="text/javascript" src="http://www.wlmessenger.net/api/3.5/loader.js"></script>
<script type="text/javascript">
//<[CDATA[
// trigger load library
function loadLibrary(){
// Get the App Tag attributes from token.php?attr
$.getJSON( "./token.php?attr", function(json) {
// Attach the namespace to the <html> tag
$('html').attr( "xmlns:msgr","http://messenger.live.com/2009/ui-tags" );
// Load the Microsoft Loader
Microsoft.Live.Core.Loader.load(['messenger.ui.styles.core', 'messenger.ui'], function(){
// build the apptag
var tag = Microsoft.Live.Messenger.UI.Tags.TagsFactory.createTag('app',json);
document.body.appendChild(tag);
Microsoft.Live.Messenger.UI.Tags.TagsFactory.refresh(tag);
// create the bar
var tag = Microsoft.Live.Messenger.UI.Tags.TagsFactory.createTag('bar');
document.body.appendChild(tag);
Microsoft.Live.Messenger.UI.Tags.TagsFactory.refresh(tag);
});
} );
}
//]]>
</script>
</head>
<body>
<h1>Lazy Load the Core Libraries</h1><button onclick="loadLibrary()">Load libraries</button>
</body>
</html>Code (token.php)
<?php
/**
*
* This script it a dynamic tool used for communicating with a static page.
* It enables us to take the creation of the application-verifier-token to a URL to be interacted with via a REST method.
*
* ?token - Sets the DELEGATION TOKEN cookie
* ?attr - Return attributes of <msgr:app> tag in JSON
*
* @author Andrew Dodson
*
* SETUP
* ------------
* 1. Obtain an application ID from https://live.azure.com/Cloud/Provisioning/Services.aspx?ProjectId=0
* (More info about App ID at - http://msdn.microsoft.com/en-us/library/bb676626.aspx)
* 2. Place Application ID (appid) and Secret in $settings below
*/
$settings = array(
'appid' => 'appid-goes-here',
'secret' => 'secret-goes-here'
);
/**
* IS THIS PAGE ACTING AS A DELEGATION ASSIGNMENT?
* Typically this would be located at a completely seperate pathname defined by aforementioned "token-url"
*/
if(isset($_GET['token'])){
/**
* Process Consent Token which has been defined by the embeded script
* To create the Delegation token to ... (missing description)
*/
parse_str($_COOKIE['msgr-consent-token'], $parsedToken );
// Process this token... this is the confusing part
$token = base64_decode($parsedToken['eact']);
$cryptkey = substr( hash('sha256', 'ENCRYPTION' . $settings['secret'], true), 0, 16);
parse_str(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $cryptkey, substr($token, 16), MCRYPT_MODE_CBC, substr($token, 0, 16)),$parsedToken);
/**
* Set delegation token
*/
setrawcookie('msgr-delegation-token', $parsedToken['delt'], 0, '/');
// Return the delegation token
print $parsedToken['delt'];
exit(0);
} if(isset($_GET['attr']) ){
print json_encode((object)array(
// REQUIRED
// ---------------------
'privacy-url' => $_SERVER['SCRIPT_NAME'].'?privacy', // e.g. "Privacy.html"
'token-url' => $_SERVER['SCRIPT_NAME'].'?token', // "refreshMesengerToken.php"
'channel-url' => $_SERVER['SCRIPT_NAME'].'?channel', // e.g. "Channel.html"
// Encrypt's the secret key
'application-verifier-token' => urlencode(( $token = ( 'appid=' . $settings['appid'] . '&ts=' . time() ) )
. '&sig=' . urlencode(base64_encode(hash_hmac("sha256",$token,
substr(
hash('sha256', 'SIGNATURE' . $settings['secret'], true),
0,
16),
true)
))),
// OPTIONAL
// ------------------------
'application-name' =>"Knarly Sandbox with Windows Live Login"
));
}
?>Comments
QdAfOEShyr
Now that's sbltue! Great to hear from you.
Created 07/08/11
gYPBggBDdFzSPKI
I am ttolaly wowed and prepared to take the next step now.
Created 08/08/11
LYYqYAkxy
JSAjBM sdyrgsbbjlsm
Created 08/08/11
sBrauaEmfQTkb
Z96jAA jhmzxdnbqgmt
Created 09/08/11
fbbtTRSyRP
edz9ma , [url=http://ajqhlzkgybgv.com/]ajqhlzkgybgv[/url], [link=http://cucuuadosgby.com/]cucuuadosgby[/link], http://gnqzlxezqtdr.com/
Created 09/08/11
rqOwAusr
nzoQfr xbwroycpdkal
Created 10/08/11
GcsOJVRDWjnBjPC
Iby4mv dcsankquisai
Created 11/08/11
CthfjMtffECovVmLLU
Kd6X64 , [url=http://vzrzzqyuigqh.com/]vzrzzqyuigqh[/url], [link=http://swehvohfsvdr.com/]swehvohfsvdr[/link], http://ebbnwpdkcvqv.com/
Created 14/08/11
uoswNCJMimamUy
9l8two , [url=http://kjzqbyurpjgk.com/]kjzqbyurpjgk[/url], [link=http://hwqcwyegqnag.com/]hwqcwyegqnag[/link], http://slfosblnkegy.com/
Created 16/08/11
