getJwt method

String? getJwt(
  1. RequestContext req
)

Retrieves a JWT from a request, if any was sent at all.

Implementation

String? getJwt(RequestContext req) {
  if (req.headers?.value('Authorization') != null) {
    final authHeader = req.headers?.value('Authorization');
    if (authHeader != null) {
      // Allow Basic auth to fall through
      if (_rgxBearer.hasMatch(authHeader)) {
        return authHeader.replaceAll(_rgxBearer, '').trim();
      }
    }

    _log.info('RequestContext.headers is null');
  } else if (allowCookie &&
      req.cookies.any((cookie) => cookie.name == 'token')) {
    return req.cookies.firstWhere((cookie) => cookie.name == 'token').value;
  } else if (allowTokenInQuery) {
    //&& req.uri?.queryParameters['token'] is String) {
    if (req.uri != null) {
      return req.uri?.queryParameters['token']?.toString();
    }
  }

  return null;
}