parse method Null safety

  1. @override
String? parse(
  1. String? authorizationHeader

Parses a Bearer token from authorizationHeader. If the header is malformed or doesn't exist, throws an AuthorizationParserException. Otherwise, returns the String representation of the bearer token.

For example, if the input to this method is "Bearer token" it would return 'token'.

If authorizationHeader is malformed or null, throws an AuthorizationParserException.


String? parse(String? authorizationHeader) {
  if (authorizationHeader == null) {
    throw AuthorizationParserException(

  final matcher = RegExp("Bearer (.+)");
  final match = matcher.firstMatch(authorizationHeader);
  if (match == null) {
    throw AuthorizationParserException(
  return match[1];