project method
Validates candidate, falling back to fallback when it is blank.
Throws a FormatException when the candidate is not allowed by this policy.
Implementation
Uri project(String? candidate, {required Uri fallback}) {
final value = candidate?.trim() ?? '';
if (value.isEmpty) return _validateFixed(fallback);
final uri = Uri.tryParse(value);
if (uri == null || uri.hasFragment || uri.userInfo.isNotEmpty) {
throw const FormatException('invalid_saml_callback');
}
if (!uri.hasScheme && !uri.hasAuthority) {
if (!allowRelative ||
!uri.path.startsWith('/') ||
uri.path.startsWith('//')) {
throw const FormatException('invalid_saml_callback');
}
return uri;
}
if (!trustedOrigins.contains(_originOnly(uri))) {
throw const FormatException('invalid_saml_callback');
}
return uri;
}