Merge lp:~mardy/account-plugins/microsoft-graph into lp:~gary-wzl77/account-plugins/onedrive_provider

Proposed by Alberto Mardegan
Status: Merged
Merged at revision: 181
Proposed branch: lp:~mardy/account-plugins/microsoft-graph
Merge into: lp:~gary-wzl77/account-plugins/onedrive_provider
Diff against target: 50 lines (+9/-8)
2 files modified
data/providers/microsoft.provider.in.in (+1/-1)
qml/microsoft/Main.qml (+8/-7)
To merge this branch: bzr merge lp:~mardy/account-plugins/microsoft-graph
Reviewer Review Type Date Requested Status
Gary.Wang Approve
Review via email: mp+309933@code.launchpad.net

Description of the change

Use the microsoft graph API to get the display name

This change allows us to retrieve the user email, with a fallback to the user display name.

The Graph API to get the user info is documented here:
https://graph.microsoft.io/en-us/docs/api-reference/v1.0/resources/users

OneDrive is also accessible via the graph API (it looks like the endpoints and parameters are the same, just the base address is different), as documented here:
https://graph.microsoft.io/en-us/docs/api-reference/v1.0/resources/onedrive

To post a comment you must log in.
Revision history for this message
Gary.Wang (gary-wzl77) wrote :

Thanks mardy for this change.
However, I can't manage to login with my account anymore with this change.
I'd say access token is obtained, but error occurs when retrieving the uesr email address by using graph API.

Here is the log:
...
qml: Loading changed
qml: Loading changed
qml: Loading changed
[1104/062626:ERROR:PlatformKeyboardEvent.cpp(84)] Not implemented reached in static bool blink::PlatformKeyboardEvent::currentCapsLockState()
[1104/062628:ERROR:PlatformKeyboardEvent.cpp(84)] Not implemented reached in static bool blink::PlatformKeyboardEvent::currentCapsLockState()
[1104/062631:ERROR:PlatformKeyboardEvent.cpp(84)] Not implemented reached in static bool blink::PlatformKeyboardEvent::currentCapsLockState()
qml: Loading changed
qml: Loading changed
qml: Loading changed
qml: Loading changed
qml: Loading changed
qml: Authenticated; getting cookies
QObject::disconnect: Unexpected null parameter
qml: Request destroyed!
qml: error: 401
qml: response text: {^M
  "error": {^M
    "code": "InvalidAuthenticationToken",^M
    "message": "CompactToken parsing failed with error code: -2147184118",^M
    "innerError": {^M
      "request-id": "fd40b8ca-ca3c-4bfc-84bf-58ba8b6ef0a1",^M
      "date": "2016-11-04T06:27:10"^M
    }^M
  }^M
}

review: Needs Fixing
Revision history for this message
Gary.Wang (gary-wzl77) wrote :

I re-tested the account plugin and found that I didn't change the Scope settings, which resulted in login failure.
Also with this plugin, access token is only available by using Microsoft graph API. So I compared all the APIs of onedrive I used in scope and storage provider
   https://dev.onedrive.com
with graph API
   https://graph.microsoft.io/en-us/docs/api-reference/v1.0/api/item_createuploadsession#best-practices)
Basically, these two sets of APIs are quite similar. With some parameters changed, I can easily migrate onedrive API to graph API.
So there's no much efforts for this transition.
Thanks for this. Mardy

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/providers/microsoft.provider.in.in'
2--- data/providers/microsoft.provider.in.in 2016-10-26 11:47:38 +0000
3+++ data/providers/microsoft.provider.in.in 2016-11-03 11:10:49 +0000
4@@ -17,7 +17,7 @@
5 <setting name="RedirectUri">https://login.live.com/oauth20_desktop.srf</setting>
6 <setting name="ResponseType">token</setting>
7 <setting name="ClientId">@MICROSOFT_CLIENT_ID@</setting>
8- <setting type="as" name="Scope">['onedrive.readwrite onedrive.appfolder']</setting>
9+ <setting type="as" name="Scope">['User.Read', 'Files.ReadWrite']</setting>
10 <setting type="b" name="DisableStateParameter">true</setting>
11 </group>
12 </group>
13
14=== modified file 'qml/microsoft/Main.qml'
15--- qml/microsoft/Main.qml 2016-11-02 08:34:54 +0000
16+++ qml/microsoft/Main.qml 2016-11-03 11:10:49 +0000
17@@ -2,25 +2,26 @@
18
19 OAuthMain {
20 creationComponent: OAuth {
21- function getUserName(reply) {
22+ function getUserName(reply, callback) {
23 var http = new XMLHttpRequest();
24- var url = "https://api.onedrive.com/v1.0/drive";
25+ var url = "https://graph.microsoft.com/v1.0/me";
26 http.open("GET", url, true);
27 http.setRequestHeader("Authorization", "bearer " + reply.AccessToken);
28 http.onreadystatechange = function() {
29 if (http.readyState === 4) {
30 if (http.status === 200) {
31+ console.log("response text: " + http.responseText);
32 var response = JSON.parse(http.responseText);
33- account.updateDisplayName(response.owner.user.displayName +
34- " ( id: " + response.owner.user.id + ")");
35- account.synced.connect(finished);
36- account.sync();
37+ callback(response.userPrincipalName ? response.userPrincipalName : response.displayName);
38 } else {
39+ console.log("error: " + http.status);
40+ console.log("response text: " + http.responseText);
41 cancel();
42 }
43 }
44 };
45 http.send(null);
46+ return true;
47 }
48- }
49+ }
50 }

Subscribers

People subscribed via source and target branches

to all changes: