Skip to content

Use new HTTP retry logic in openid client. #8737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 19 additions & 31 deletions app/lib/service/openid/openid_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,26 @@ import 'openid_models.dart';
Future<OpenIdData> fetchOpenIdData({
required String configurationUrl,
}) async {
final client = httpRetryClient();
try {
final configUri = Uri.parse(configurationUrl);
if (!envConfig.isRunningLocally && configUri.scheme != 'https') {
throw AssertionError(
'OpenID configuration URL must use `https` protocol, was: `$configurationUrl`.');
}
final providerRs = await client.get(configUri);
if (providerRs.statusCode != 200) {
throw Exception(
'Unexpected status code ${providerRs.statusCode} while fetching $configUri');
}
final providerData = json.decode(providerRs.body) as Map<String, dynamic>;
final provider = OpenIdProvider.fromJson(providerData);
final jwksUri = Uri.parse(provider.jwksUri);
if (!envConfig.isRunningLocally && jwksUri.scheme != 'https') {
throw AssertionError(
'JWKS URL must use `https` protocol, was: `$jwksUri`.');
}
final jwksRs = await client.get(jwksUri);
if (jwksRs.statusCode != 200) {
throw Exception(
'Unexpected status code ${jwksRs.statusCode} while fetching $jwksUri');
}
final jwksData = json.decode(jwksRs.body) as Map<String, dynamic>;
return OpenIdData(
provider: provider,
jwks: JsonWebKeyList.fromJson(jwksData),
);
} finally {
client.close();
final configUri = Uri.parse(configurationUrl);
if (!envConfig.isRunningLocally && configUri.scheme != 'https') {
throw AssertionError(
'OpenID configuration URL must use `https` protocol, was: `$configurationUrl`.');
}
final providerBody =
await httpGetWithRetry(configUri, responseFn: (rs) => rs.body);
final providerData = json.decode(providerBody) as Map<String, dynamic>;
final provider = OpenIdProvider.fromJson(providerData);
final jwksUri = Uri.parse(provider.jwksUri);
if (!envConfig.isRunningLocally && jwksUri.scheme != 'https') {
throw AssertionError(
'JWKS URL must use `https` protocol, was: `$jwksUri`.');
}
final jwksBody = await httpGetWithRetry(jwksUri, responseFn: (rs) => rs.body);
final jwksData = json.decode(jwksBody) as Map<String, dynamic>;
return OpenIdData(
provider: provider,
jwks: JsonWebKeyList.fromJson(jwksData),
);
}

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