verifyAndParseCodeFromCallbackUri function
Implementation
String verifyAndParseCodeFromCallbackUri(
String callbackUri, String redirectUri, String state) {
if (!callbackUri.startsWith(redirectUri)) {
throw LogtoAuthException(
LogtoAuthExceptions.callbackUriValidationError, 'invalid redirect uri');
}
var queryParams = Uri.parse(callbackUri).queryParameters;
if (queryParams['error'] != null) {
throw LogtoAuthException(LogtoAuthExceptions.callbackUriValidationError,
queryParams['error']!, queryParams['error_description']);
}
if (queryParams['state'] == null) {
throw LogtoAuthException(
LogtoAuthExceptions.callbackUriValidationError, 'missing state');
}
if (queryParams['state'] != state) {
throw LogtoAuthException(
LogtoAuthExceptions.callbackUriValidationError, 'invalid state');
}
if (queryParams['code'] == null) {
throw LogtoAuthException(
LogtoAuthExceptions.callbackUriValidationError, 'missing code');
}
return queryParams['code']!;
}