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 credentials; | 5 library credentials; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:http/http.dart' as http; | 10 import 'package:http/http.dart' as http; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 "grant_type": "refresh_token", | 166 "grant_type": "refresh_token", |
167 "refresh_token": refreshToken, | 167 "refresh_token": refreshToken, |
168 // TODO(nweiz): the spec recommends that HTTP basic auth be used in | 168 // TODO(nweiz): the spec recommends that HTTP basic auth be used in |
169 // preference to form parameters, but Google doesn't support that. | 169 // preference to form parameters, but Google doesn't support that. |
170 // Should it be configurable? | 170 // Should it be configurable? |
171 "client_id": identifier, | 171 "client_id": identifier, |
172 "client_secret": secret | 172 "client_secret": secret |
173 }; | 173 }; |
174 if (!scopes.isEmpty) fields["scope"] = scopes.join(' '); | 174 if (!scopes.isEmpty) fields["scope"] = scopes.join(' '); |
175 | 175 |
176 return httpClient.post(tokenEndpoint, fields: fields); | 176 return httpClient.post(tokenEndpoint, body: fields); |
177 }).then((response) { | 177 }).then((response) { |
178 return handleAccessTokenResponse( | 178 return handleAccessTokenResponse( |
179 response, tokenEndpoint, startTime, scopes); | 179 response, tokenEndpoint, startTime, scopes); |
180 }).then((credentials) { | 180 }).then((credentials) { |
181 // The authorization server may issue a new refresh token. If it doesn't, | 181 // The authorization server may issue a new refresh token. If it doesn't, |
182 // we should re-use the one we already have. | 182 // we should re-use the one we already have. |
183 if (credentials.refreshToken != null) return credentials; | 183 if (credentials.refreshToken != null) return credentials; |
184 return new Credentials( | 184 return new Credentials( |
185 credentials.accessToken, | 185 credentials.accessToken, |
186 this.refreshToken, | 186 this.refreshToken, |
187 credentials.tokenEndpoint, | 187 credentials.tokenEndpoint, |
188 credentials.scopes, | 188 credentials.scopes, |
189 credentials.expiration); | 189 credentials.expiration); |
190 }); | 190 }); |
191 } | 191 } |
192 } | 192 } |
OLD | NEW |