OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library authorization_code_grant; | 5 library authorization_code_grant; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
10 | 10 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 _state = _FINISHED_STATE; | 221 _state = _FINISHED_STATE; |
222 | 222 |
223 return _handleAuthorizationCode(authorizationCode); | 223 return _handleAuthorizationCode(authorizationCode); |
224 }); | 224 }); |
225 } | 225 } |
226 | 226 |
227 /// This works just like [handleAuthorizationCode], except it doesn't validate | 227 /// This works just like [handleAuthorizationCode], except it doesn't validate |
228 /// the state beforehand. | 228 /// the state beforehand. |
229 Future<Client> _handleAuthorizationCode(String authorizationCode) { | 229 Future<Client> _handleAuthorizationCode(String authorizationCode) { |
230 var startTime = new DateTime.now(); | 230 var startTime = new DateTime.now(); |
231 return _httpClient.post(this.tokenEndpoint, fields: { | 231 return _httpClient.post(this.tokenEndpoint, body: { |
232 "grant_type": "authorization_code", | 232 "grant_type": "authorization_code", |
233 "code": authorizationCode, | 233 "code": authorizationCode, |
234 "redirect_uri": this._redirectEndpoint.toString(), | 234 "redirect_uri": this._redirectEndpoint.toString(), |
235 // TODO(nweiz): the spec recommends that HTTP basic auth be used in | 235 // TODO(nweiz): the spec recommends that HTTP basic auth be used in |
236 // preference to form parameters, but Google doesn't support that. Should | 236 // preference to form parameters, but Google doesn't support that. Should |
237 // it be configurable? | 237 // it be configurable? |
238 "client_id": this.identifier, | 238 "client_id": this.identifier, |
239 "client_secret": this.secret | 239 "client_secret": this.secret |
240 }).then((response) { | 240 }).then((response) { |
241 var credentials = handleAccessTokenResponse( | 241 var credentials = handleAccessTokenResponse( |
242 response, tokenEndpoint, startTime, _scopes); | 242 response, tokenEndpoint, startTime, _scopes); |
243 return new Client( | 243 return new Client( |
244 this.identifier, this.secret, credentials, httpClient: _httpClient); | 244 this.identifier, this.secret, credentials, httpClient: _httpClient); |
245 }); | 245 }); |
246 } | 246 } |
247 | 247 |
248 /// Closes the grant and frees its resources. | 248 /// Closes the grant and frees its resources. |
249 /// | 249 /// |
250 /// This will close the underlying HTTP client, which is shared by the | 250 /// This will close the underlying HTTP client, which is shared by the |
251 /// [Client] created by this grant, so it's not safe to close the grant and | 251 /// [Client] created by this grant, so it's not safe to close the grant and |
252 /// continue using the client. | 252 /// continue using the client. |
253 void close() { | 253 void close() { |
254 if (_httpClient != null) _httpClient.close(); | 254 if (_httpClient != null) _httpClient.close(); |
255 _httpClient = null; | 255 _httpClient = null; |
256 } | 256 } |
257 } | 257 } |
OLD | NEW |