resolveSsoCallbackParams function
Interprets the query parameters the API redirects back with.
Kept separate from any I/O so the mapping stays easy to read and test.
Implementation
SsoCallbackOutcome resolveSsoCallbackParams({
String? code,
String? status,
String? error,
}) {
final hasCode = code != null && code.isNotEmpty;
final hasStatus = status != null && status.isNotEmpty;
final hasError = error != null && error.isNotEmpty;
if (!hasCode && !hasStatus && !hasError) {
return const SsoCallbackNone();
}
if (hasError) {
return SsoCallbackError(_signInFailed, providerError: error);
}
if (status == 'error') {
// On this path the API puts its reason in `code` rather than `error`.
return SsoCallbackError(
_signInFailed,
providerError: hasCode ? code : 'oauth_failed',
);
}
if (!hasCode || !hasStatus) {
return const SsoCallbackError('Invalid SSO redirect');
}
return SsoCallbackExchange(code: code, status: status);
}