@@ -13,38 +13,26 @@ import 'openid_models.dart';
13
13
Future <OpenIdData > fetchOpenIdData ({
14
14
required String configurationUrl,
15
15
}) async {
16
- final client = httpRetryClient ();
17
- try {
18
- final configUri = Uri .parse (configurationUrl);
19
- if (! envConfig.isRunningLocally && configUri.scheme != 'https' ) {
20
- throw AssertionError (
21
- 'OpenID configuration URL must use `https` protocol, was: `$configurationUrl `.' );
22
- }
23
- final providerRs = await client.get (configUri);
24
- if (providerRs.statusCode != 200 ) {
25
- throw Exception (
26
- 'Unexpected status code ${providerRs .statusCode } while fetching $configUri ' );
27
- }
28
- final providerData = json.decode (providerRs.body) as Map <String , dynamic >;
29
- final provider = OpenIdProvider .fromJson (providerData);
30
- final jwksUri = Uri .parse (provider.jwksUri);
31
- if (! envConfig.isRunningLocally && jwksUri.scheme != 'https' ) {
32
- throw AssertionError (
33
- 'JWKS URL must use `https` protocol, was: `$jwksUri `.' );
34
- }
35
- final jwksRs = await client.get (jwksUri);
36
- if (jwksRs.statusCode != 200 ) {
37
- throw Exception (
38
- 'Unexpected status code ${jwksRs .statusCode } while fetching $jwksUri ' );
39
- }
40
- final jwksData = json.decode (jwksRs.body) as Map <String , dynamic >;
41
- return OpenIdData (
42
- provider: provider,
43
- jwks: JsonWebKeyList .fromJson (jwksData),
44
- );
45
- } finally {
46
- client.close ();
16
+ final configUri = Uri .parse (configurationUrl);
17
+ if (! envConfig.isRunningLocally && configUri.scheme != 'https' ) {
18
+ throw AssertionError (
19
+ 'OpenID configuration URL must use `https` protocol, was: `$configurationUrl `.' );
47
20
}
21
+ final providerBody =
22
+ await httpGetWithRetry (configUri, responseFn: (rs) => rs.body);
23
+ final providerData = json.decode (providerBody) as Map <String , dynamic >;
24
+ final provider = OpenIdProvider .fromJson (providerData);
25
+ final jwksUri = Uri .parse (provider.jwksUri);
26
+ if (! envConfig.isRunningLocally && jwksUri.scheme != 'https' ) {
27
+ throw AssertionError (
28
+ 'JWKS URL must use `https` protocol, was: `$jwksUri `.' );
29
+ }
30
+ final jwksBody = await httpGetWithRetry (jwksUri, responseFn: (rs) => rs.body);
31
+ final jwksData = json.decode (jwksBody) as Map <String , dynamic >;
32
+ return OpenIdData (
33
+ provider: provider,
34
+ jwks: JsonWebKeyList .fromJson (jwksData),
35
+ );
48
36
}
49
37
50
38
String parseAsString (Map <String , dynamic > map, String key) {
0 commit comments