| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:http/http.dart' as http; | 7 import 'package:http/http.dart' as http; |
| 8 | 8 |
| 9 import 'client.dart'; | 9 import 'client.dart'; |
| 10 import 'handle_access_token_response.dart'; | 10 import 'handle_access_token_response.dart'; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 bool basicAuth: true, | 38 bool basicAuth: true, |
| 39 http.Client httpClient}) async { | 39 http.Client httpClient}) async { |
| 40 var startTime = new DateTime.now(); | 40 var startTime = new DateTime.now(); |
| 41 | 41 |
| 42 var body = { | 42 var body = { |
| 43 "grant_type": "password", | 43 "grant_type": "password", |
| 44 "username": username, | 44 "username": username, |
| 45 "password": password | 45 "password": password |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 var headers = {}; | 48 var headers = <String, String>{}; |
| 49 | 49 |
| 50 if (identifier != null) { | 50 if (identifier != null) { |
| 51 if (basicAuth) { | 51 if (basicAuth) { |
| 52 headers['Authorization'] = basicAuthHeader(identifier, secret); | 52 headers['Authorization'] = basicAuthHeader(identifier, secret); |
| 53 } else { | 53 } else { |
| 54 body['client_id'] = identifier; | 54 body['client_id'] = identifier; |
| 55 if (secret != null) body['client_secret'] = secret; | 55 if (secret != null) body['client_secret'] = secret; |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 if (scopes != null && !scopes.isEmpty) body['scope'] = scopes.join(' '); | 59 if (scopes != null && !scopes.isEmpty) body['scope'] = scopes.join(' '); |
| 60 | 60 |
| 61 if (httpClient == null) httpClient = new http.Client(); | 61 if (httpClient == null) httpClient = new http.Client(); |
| 62 var response = await httpClient.post(authorizationEndpoint, | 62 var response = await httpClient.post(authorizationEndpoint, |
| 63 headers: headers, body: body); | 63 headers: headers, body: body); |
| 64 | 64 |
| 65 var credentials = await handleAccessTokenResponse( | 65 var credentials = await handleAccessTokenResponse( |
| 66 response, authorizationEndpoint, startTime, scopes); | 66 response, authorizationEndpoint, startTime, scopes); |
| 67 return new Client(credentials, identifier: identifier, secret: secret); | 67 return new Client(credentials, identifier: identifier, secret: secret); |
| 68 } | 68 } |
| OLD | NEW |