platform/lib/src/exception.dart

63 lines
2.3 KiB
Dart
Raw Normal View History

2017-09-29 02:16:44 +00:00
import 'package:angel_http_exception/angel_http_exception.dart';
2017-10-16 06:38:46 +00:00
/// An Angel-friendly wrapper around OAuth2 [ErrorResponse] instances.
2017-09-29 02:16:44 +00:00
class AuthorizationException extends AngelHttpException {
final ErrorResponse errorResponse;
AuthorizationException(this.errorResponse,
2017-10-16 06:38:46 +00:00
{StackTrace stackTrace, int statusCode, error})
: super(error ?? errorResponse,
2017-09-29 02:16:44 +00:00
stackTrace: stackTrace, message: '', statusCode: statusCode ?? 401);
2017-10-16 06:38:46 +00:00
@override
Map toJson() {
var m = {
'error': errorResponse.code,
'error_description': errorResponse.description,
};
if (errorResponse.uri != null)
m['error_uri'] = errorResponse.uri.toString();
return m;
}
2017-09-29 02:16:44 +00:00
}
2017-10-16 06:38:46 +00:00
/// Represents an OAuth2 authentication error.
2017-09-29 02:16:44 +00:00
class ErrorResponse {
2017-10-16 06:38:46 +00:00
/// The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed.
static const String invalidRequest = 'invalid_request';
/// The client is not authorized to request an authorization code using this method.
static const String unauthorizedClient = 'unauthorized_client';
/// The resource owner or authorization server denied the request.
static const String accessDenied = 'access_denied';
/// The authorization server does not support obtaining an authorization code using this method.
static const String unsupportedResponseType = 'unsupported_response_type';
/// The requested scope is invalid, unknown, or malformed.
static const String invalidScope = 'invalid_scope';
/// The authorization server encountered an unexpected condition that prevented it from fulfilling the request.
static const String serverError = 'server_error';
/// The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.
static const String temporarilyUnavailable = 'temporarily_unavailable';
/// A short string representing the error.
final String code;
/// A relatively detailed description of the source of the error.
final String description;
/// An optional [Uri] directing users to more information about the error.
final Uri uri;
/// The exact value received from the client, if a "state" parameter was present in the client authorization request.
final String state;
const ErrorResponse(this.code, this.description, this.state, {this.uri});
2017-09-29 02:16:44 +00:00
}