Last active
September 30, 2015 07:37
-
-
Save asw101/1745370 to your computer and use it in GitHub Desktop.
LINQPad + Windows Live Messenger XMPP + agsXMPP Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// see: http://solutionevangelist.com/post/25602 | |
static string client_id = ""; | |
static string client_secret = ""; | |
static string Server = "messenger.live.com"; | |
static string Token; | |
static string GetToken() | |
{ | |
if(String.IsNullOrEmpty(Token)) | |
{ | |
var oauth_uri = "https://oauth.live.com/authorize?client_id={0}&scope=wl.messenger&response_type=token&display=touch&redirect_uri={1}"; | |
var redirect_uri = "http://oauth.live.com/desktop"; | |
var client_id = ; | |
System.Diagnostics.Process.Start(String.Format(oauth_uri, client_id, redirect_uri)); | |
Token = Util.ReadLine("redirect_uri:"); | |
} | |
return System.Web.HttpUtility.ParseQueryString(Token.Replace("http://oauth.live.com/desktop#", "")).Get("access_token"); | |
} | |
static agsXMPP.protocol.sasl.Auth Auth() | |
{ | |
var auth = new agsXMPP.protocol.sasl.Auth(); | |
auth.Attributes.Add("mechanism", "X-MESSENGER-OAUTH2"); | |
auth.Value = GetToken(); | |
return auth; | |
} | |
static void Main() | |
{ | |
Token = GetToken(); | |
var xmppCon = new XmppClientConnection(); | |
xmppCon.Server = Server; | |
xmppCon.OnSaslStart += delegate(object sender, agsXMPP.sasl.SaslEventArgs args){ xmppCon.Send(Auth()); }; | |
// for debugging | |
xmppCon.OnReadXml += delegate(object s, string xml){ xml.Dump("read"); }; | |
xmppCon.OnWriteXml += delegate(object s, string xml){ xml.Dump("write"); }; | |
// the remainder is from the agsXMPP sample code ... | |
xmppCon.UseStartTLS = true; | |
xmppCon.AutoAgents = false; | |
xmppCon.AutoPresence = true; | |
xmppCon.AutoRoster = true; | |
xmppCon.AutoResolveConnectServer = true; | |
xmppCon.OnRosterStart += new ObjectHandler(xmppCon_OnRosterStart); | |
xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem); | |
xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd); | |
xmppCon.OnPresence += new PresenceHandler(xmppCon_OnPresence); | |
xmppCon.OnMessage += new MessageHandler(xmppCon_OnMessage); | |
xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin); | |
xmppCon.Open(); | |
Console.ReadLine(); | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment