1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-04 16:45:08 -05:00
kaiwa/public/js/oauthLogin.js
2014-03-07 12:07:45 -08:00

32 lines
1.0 KiB
JavaScript

var parts = window.location.hash.slice(1).split('&');
parts.forEach(function (value) {
if (value.substr(0, 12) === "access_token") {
var token = value.substr(13);
$.ajax({
type: 'get',
url: 'https://api.andbang.com/me',
dataType: 'json',
headers: {
'Authorization': 'Bearer ' + token
},
success: function (user) {
localStorage.config = JSON.stringify({
jid: user.username.toLowerCase() + "@otalk.im",
server: "otalk.im",
wsURL: "wss://otalk.im/xmpp-websocket",
transport: "websocket",
credentials: {
username: user.username.toLowerCase(),
password: token
}
});
window.location = '/';
},
error: function () {
window.location = '/logout';
}
});
}
});