34 lines
914 B
C#
34 lines
914 B
C#
using Microsoft.AspNetCore.Http;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Extensions {
|
|
public static class HttpRequestExtensions {
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="name"></param>
|
|
/// <returns></returns>
|
|
public static List<string> GetHeader(this HttpRequest request, string name) {
|
|
var headers = request.Headers[name].ToList();
|
|
return headers != null ? headers : new List<string>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Return clean JWT Bearer token from Authorisation Header
|
|
/// </summary>
|
|
public static string? GeBearerToken(this HttpRequest request) {
|
|
var header = request.GetHeader("Authorization").FirstOrDefault();
|
|
return header !=null
|
|
? header.Replace("Bearer ", "")
|
|
: default;
|
|
}
|
|
}
|
|
}
|