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:json'; | 7 import 'dart:json'; |
8 import 'dart:uri'; | 8 import 'dart:uri'; |
9 | 9 |
10 import '../../../http/lib/http.dart' as http; | 10 import '../../../http/lib/http.dart' as http; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 /// You may request different scopes than the default by passing in | 137 /// You may request different scopes than the default by passing in |
138 /// [newScopes]. These must be a subset of [scopes]. | 138 /// [newScopes]. These must be a subset of [scopes]. |
139 /// | 139 /// |
140 /// This will throw a [StateError] if these credentials can't be refreshed, an | 140 /// This will throw a [StateError] if these credentials can't be refreshed, an |
141 /// [AuthorizationException] if refreshing the credentials fails, or a | 141 /// [AuthorizationException] if refreshing the credentials fails, or a |
142 /// [FormatError] if the authorization server returns invalid responses. | 142 /// [FormatError] if the authorization server returns invalid responses. |
143 Future<Credentials> refresh( | 143 Future<Credentials> refresh( |
144 String identifier, | 144 String identifier, |
145 String secret, | 145 String secret, |
146 {List<String> newScopes, | 146 {List<String> newScopes, |
147 http.BaseClient httpClient}) { | 147 http.Client httpClient}) { |
148 var scopes = this.scopes; | 148 var scopes = this.scopes; |
149 if (newScopes != null) scopes = newScopes; | 149 if (newScopes != null) scopes = newScopes; |
150 if (scopes == null) scopes = <String>[]; | 150 if (scopes == null) scopes = <String>[]; |
151 if (httpClient == null) httpClient = new http.Client(); | 151 if (httpClient == null) httpClient = new http.Client(); |
152 | 152 |
153 var startTime = new Date.now(); | 153 var startTime = new Date.now(); |
154 return async.chain((_) { | 154 return async.chain((_) { |
155 if (refreshToken == null) { | 155 if (refreshToken == null) { |
156 throw new StateError("Can't refresh credentials without a refresh " | 156 throw new StateError("Can't refresh credentials without a refresh " |
157 "token."); | 157 "token."); |
(...skipping 23 matching lines...) Expand all Loading... |
181 if (credentials.refreshToken != null) return credentials; | 181 if (credentials.refreshToken != null) return credentials; |
182 return new Credentials( | 182 return new Credentials( |
183 credentials.accessToken, | 183 credentials.accessToken, |
184 this.refreshToken, | 184 this.refreshToken, |
185 credentials.tokenEndpoint, | 185 credentials.tokenEndpoint, |
186 credentials.scopes, | 186 credentials.scopes, |
187 credentials.expiration); | 187 credentials.expiration); |
188 }); | 188 }); |
189 } | 189 } |
190 } | 190 } |
OLD | NEW |