extract method

  1. @override
Future<Result<String, Rejection>> extract(
  1. Request request
)
override

Produces the value, or the rejection that stops the handler.

Implementation

@override
Future<Result<String, Rejection>> extract(Request request) async {
  final header = Authorization.of(request);
  if (header == null || !header.isScheme('bearer')) {
    return Err(
      Rejection.unauthorized(
        'expected a bearer token',
        challenge: challenge,
      ),
    );
  }
  if (header.credentials.isEmpty) {
    return Err(
      Rejection.unauthorized('the bearer token is empty',
          challenge: challenge),
    );
  }
  return Ok(header.credentials);
}