Skip to content

Commit f6720dc

Browse files
authored
Use new HTTP retry logic in openid client. (#8737)
1 parent 344745a commit f6720dc

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

app/lib/service/openid/openid_utils.dart

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,26 @@ import 'openid_models.dart';
1313
Future<OpenIdData> fetchOpenIdData({
1414
required String configurationUrl,
1515
}) 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`.');
4720
}
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+
);
4836
}
4937

5038
String parseAsString(Map<String, dynamic> map, String key) {

0 commit comments

Comments
 (0)