1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

token retrieval from header or qs

This commit is contained in:
Kyle Spearrin 2018-03-09 11:02:31 -05:00
parent 45dd2dc909
commit 64277f54f8
2 changed files with 34 additions and 0 deletions

View File

@ -17,6 +17,7 @@ using Bit.Core.Utilities;
using IdentityModel;
using IdentityServer4.AccessTokenValidation;
using jsreport.AspNetCore;
using Bit.Core.IdentityServer;
namespace Bit.Api
{
@ -79,6 +80,7 @@ namespace Bit.Api
options.Authority = globalSettings.BaseServiceUri.InternalIdentity;
options.RequireHttpsMetadata = !Environment.IsDevelopment() &&
globalSettings.BaseServiceUri.InternalIdentity.StartsWith("https");
options.TokenRetriever = TokenRetrieval.FromAuthorizationHeaderOrQueryString();
options.NameClaimType = ClaimTypes.Email;
options.SupportedTokens = SupportedTokens.Jwt;
});

View File

@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Linq;
namespace Bit.Core.IdentityServer
{
public static class TokenRetrieval
{
private static string _headerScheme = "Bearer ";
private static string _queuryScheme = "access_token";
private static string _authHeader = "Authorization";
public static Func<HttpRequest, string> FromAuthorizationHeaderOrQueryString()
{
return (request) =>
{
var authorization = request.Headers[_authHeader].FirstOrDefault();
if(string.IsNullOrWhiteSpace(authorization))
{
return request.Query[_queuryScheme].FirstOrDefault();
}
if(authorization.StartsWith(_headerScheme, StringComparison.OrdinalIgnoreCase))
{
return authorization.Substring(_headerScheme.Length).Trim();
}
return null;
};
}
}
}