assertSecureAuthUrl function
Throws a SecurityException unless uri is a secure OAuth/OIDC endpoint.
field names the endpoint being validated (used in the error message).
Set allowInsecure to bypass the check for tests or an explicitly
opted-in insecure development environment.
Implementation
void assertSecureAuthUrl(
Uri uri, {
required String field,
bool allowInsecure = false,
}) {
if (allowInsecure) return;
if (isSecureAuthUrl(uri)) return;
throw SecurityException(
'Insecure OAuth endpoint URL for $field',
details:
'Refusing to use non-HTTPS URL "$uri" for $field. SMART on FHIR '
'requires TLS for all OAuth/OpenID Connect endpoints; only https (or '
'http on a loopback host for development) is permitted. Set '
'allowInsecureConnections to override in development.',
securityViolationType: SecurityViolationType.insecureConnection,
);
}