getOAuthKey method
Fetches the OAuth public key with id kid
from issuer
.
Keys are cached by default to avoid unnecessary requests.
You can disable the key cache by setting the datahub.enableKeyCache
configuration value to false.
Implementation
Future<RSAPublicKey> getOAuthKey(Uri issuer, String alg, String kid,
{bool forceFetch = false}) async {
if (_enableCache && !forceFetch && _openIdCache.containsKey(issuer)) {
return await getJWKSKey(_openIdCache[issuer]!, alg, kid);
}
final issuerClient = await RestClient.connect(issuer);
try {
final openIdConfig = await issuerClient
.get('/.well-known/openid-configuration')
.thenGetJsonBody();
if (Uri.tryParse(openIdConfig['issuer'])?.host != issuer.host) {
throw Exception('Issuer mismatch in openid-configuration.');
}
if (openIdConfig['jwks_uri'] == null) {
throw Exception('Missing JWKS uri in openid-configuration.');
}
final jwksUri = Uri.parse(openIdConfig['jwks_uri']);
return await getJWKSKey(jwksUri, alg, kid);
} finally {
await issuerClient.close();
}
}