sendAuthChallenge method
Send authentication challenge response
Implementation
void sendAuthChallenge(HttpRequest request, {String? error, String? errorDescription}) {
request.response.statusCode = 401;
String challenge = 'Bearer';
if (error != null) {
challenge += ' error="$error"';
if (errorDescription != null) {
challenge += ', error_description="$errorDescription"';
}
}
request.response.headers.set('WWW-Authenticate', challenge);
request.response.headers.set('Content-Type', 'application/json');
final errorResponse = {
'error': error ?? 'unauthorized',
'error_description': errorDescription ?? 'Authentication required',
};
request.response.write(jsonEncode(errorResponse));
}