| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Declare an OAuth2 class to handle retrieval/storage of an OAuth2 token. | 5 // Declare an OAuth2 class to handle retrieval/storage of an OAuth2 token. |
| 6 // | 6 // |
| 7 // Ideally, this should implement the OAuth2 PostMessage flow to avoid needing | 7 // Ideally, this should implement the OAuth2 PostMessage flow to avoid needing |
| 8 // to copy and paste a code, but that does not support extension URL schemes | 8 // to copy and paste a code, but that does not support extension URL schemes |
| 9 // quite yet. Instead, we currently use the native app flow with an | 9 // quite yet. Instead, we currently use the native app flow with an |
| 10 // authorization code that the user must cut/paste. | 10 // authorization code that the user must cut/paste. |
| 11 |
| 12 var remoting = chrome.extension.getBackgroundPage().remoting; |
| 13 |
| 11 function OAuth2() { | 14 function OAuth2() { |
| 12 this.OAUTH2_REFRESH_TOKEN_NAME = 'oauth2_refresh_token'; | 15 this.OAUTH2_REFRESH_TOKEN_NAME = 'oauth2_refresh_token'; |
| 13 | 16 |
| 14 this.client_id = encodeURIComponent( | 17 this.client_id = encodeURIComponent( |
| 15 '440925447803-m890isgsr23kdkcu2erd4mirnrjalf98.' + | 18 '440925447803-m890isgsr23kdkcu2erd4mirnrjalf98.' + |
| 16 'apps.googleusercontent.com'); | 19 'apps.googleusercontent.com'); |
| 17 this.client_secret = encodeURIComponent('TgKrL73H2kJe6Ir0ufp7bf6e'); | 20 this.client_secret = encodeURIComponent('TgKrL73H2kJe6Ir0ufp7bf6e'); |
| 18 this.scope = encodeURIComponent( | 21 this.scope = encodeURIComponent( |
| 19 'https://www.googleapis.com/auth/chromoting ' + | 22 'https://www.googleapis.com/auth/chromoting ' + |
| 20 'https://www.googleapis.com/auth/googletalk'); | 23 'https://www.googleapis.com/auth/googletalk'); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 xhr.open('POST', 'https://accounts.google.com/o/oauth2/token', true); | 132 xhr.open('POST', 'https://accounts.google.com/o/oauth2/token', true); |
| 130 xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | 133 xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); |
| 131 var post_data = 'client_id=' + this.client_id | 134 var post_data = 'client_id=' + this.client_id |
| 132 + '&client_secret=' + this.client_secret | 135 + '&client_secret=' + this.client_secret |
| 133 + '&redirect_uri=' + this.redirect_uri | 136 + '&redirect_uri=' + this.redirect_uri |
| 134 + '&code=' + encodeURIComponent(code) | 137 + '&code=' + encodeURIComponent(code) |
| 135 + '&grant_type=authorization_code'; | 138 + '&grant_type=authorization_code'; |
| 136 xhr.send(post_data); | 139 xhr.send(post_data); |
| 137 } | 140 } |
| 138 | 141 |
| OLD | NEW |