1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 01:22:50 -05:00

setup to receive & process event postings

This commit is contained in:
Kyle Spearrin
2017-12-04 10:59:07 -05:00
parent 31d0caf73e
commit 9cb1047f2b
12 changed files with 189 additions and 30 deletions

View File

@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Linq;
namespace Bit.Core.IdentityServer
{
public static class TokenRetrieval
{
public static Func<HttpRequest, string> FromAuthorizationHeaderOrQueryString(string[] authHeaderSchemes)
{
return (request) =>
{
var authorization = request.Headers["Authorization"].FirstOrDefault();
if(string.IsNullOrWhiteSpace(authorization))
{
// Bearer token could exist in the 'Content-Language' header on clients that want to avoid pre-flights.
var languageAuth = request.Headers["Content-Language"].FirstOrDefault();
if(string.IsNullOrWhiteSpace(languageAuth) ||
!languageAuth.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
{
return request.Query["access_token"].FirstOrDefault();
}
else
{
authorization = languageAuth.Split(',')[0];
}
}
foreach(var headerScheme in authHeaderSchemes)
{
if(authorization.StartsWith($"{headerScheme} ", StringComparison.OrdinalIgnoreCase))
{
return authorization.Substring(headerScheme.Length + 1).Trim();
}
}
return null;
};
}
}
}