1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import Ubuntu.OnlineAccounts.Plugin 1.0
OAuthMain {
creationComponent: OAuth {
authenticationParameters: {
"AuthPath": "login/oauth/authorize"
}
function completeCreation(reply) {
console.log("Access token: " + reply.AccessToken)
var http = new XMLHttpRequest()
var url = "https://www.github.com/user";
http.open("POST", url, true);
http.setRequestHeader("Authorization", "Bearer " + reply.AccessToken)
http.onreadystatechange = function() {
if (http.readyState === 4){
if (http.status == 200) {
console.log("ok")
console.log("response text: " + http.responseText)
var response = JSON.parse(http.responseText)
account.updateDisplayName(response.login)
account.synced.connect(finished)
account.sync()
} else {
console.log("error: " + http.status)
cancel()
}
}
};
http.send(null);
}
}
}
|