mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.Net.Http.Headers;
|
|
|
|
namespace Squidex.Web.Pipeline
|
|
{
|
|
public sealed class AccessTokenQueryMiddleware
|
|
{
|
|
private readonly RequestDelegate next;
|
|
|
|
public AccessTokenQueryMiddleware(RequestDelegate next)
|
|
{
|
|
this.next = next;
|
|
}
|
|
|
|
public Task InvokeAsync(HttpContext context)
|
|
{
|
|
var request = context.Request;
|
|
|
|
if (HasNoAuthHeader(request) && request.Query.TryGetValue("access_token", out var token))
|
|
{
|
|
request.Headers[HeaderNames.Authorization] = $"Bearer {token}";
|
|
}
|
|
|
|
return next(context);
|
|
}
|
|
|
|
private static bool HasNoAuthHeader(HttpRequest request)
|
|
{
|
|
return string.IsNullOrWhiteSpace(request.Headers[HeaderNames.Authorization]);
|
|
}
|
|
}
|
|
}
|
|
|