~dobey/githubuntu/trunk

« back to all changes in this revision

Viewing changes to account-plugin/Main.qml

  • Committer: Rodney Dawes
  • Date: 2014-03-03 14:49:12 UTC
  • Revision ID: dobey@wayofthemonkey.com-20140303144912-tp00uy4312bp8nx4
Import the account plug-in for Online Accounts.

Show diffs side-by-side

added added

removed removed

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