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

support Bearer3 still

This commit is contained in:
Kyle Spearrin 2017-10-17 08:54:49 -04:00
parent 38106840b9
commit a63ad7772e
2 changed files with 10 additions and 7 deletions

View File

@ -84,7 +84,8 @@ namespace Bit.Api
options.RequireHttpsMetadata = !Environment.IsDevelopment() && options.RequireHttpsMetadata = !Environment.IsDevelopment() &&
globalSettings.BaseServiceUri.InternalIdentity.StartsWith("https"); globalSettings.BaseServiceUri.InternalIdentity.StartsWith("https");
options.NameClaimType = ClaimTypes.Email; options.NameClaimType = ClaimTypes.Email;
options.TokenRetriever = TokenRetrieval.FromAuthorizationHeaderOrQueryString("Bearer", "access_token"); options.TokenRetriever = TokenRetrieval.FromAuthorizationHeaderOrQueryString(
new string[] { "Bearer", "Bearer3" });
options.SupportedTokens = SupportedTokens.Jwt; options.SupportedTokens = SupportedTokens.Jwt;
}); });

View File

@ -6,8 +6,7 @@ namespace Bit.Api.Utilities
{ {
public static class TokenRetrieval public static class TokenRetrieval
{ {
public static Func<HttpRequest, string> FromAuthorizationHeaderOrQueryString(string headerScheme = "Bearer", public static Func<HttpRequest, string> FromAuthorizationHeaderOrQueryString(string[] authHeaderSchemes)
string qsName = "access_token")
{ {
return (request) => return (request) =>
{ {
@ -18,9 +17,9 @@ namespace Bit.Api.Utilities
// Bearer token could exist in the 'Content-Language' header on clients that want to avoid pre-flights. // Bearer token could exist in the 'Content-Language' header on clients that want to avoid pre-flights.
var languageAuth = request.Headers["Content-Language"].FirstOrDefault(); var languageAuth = request.Headers["Content-Language"].FirstOrDefault();
if(string.IsNullOrWhiteSpace(languageAuth) || if(string.IsNullOrWhiteSpace(languageAuth) ||
!languageAuth.StartsWith($"{headerScheme} ", StringComparison.OrdinalIgnoreCase)) !languageAuth.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
{ {
return request.Query[qsName].FirstOrDefault(); return request.Query["access_token"].FirstOrDefault();
} }
else else
{ {
@ -28,9 +27,12 @@ namespace Bit.Api.Utilities
} }
} }
if(authorization.StartsWith($"{headerScheme} ", StringComparison.OrdinalIgnoreCase)) foreach(var headerScheme in authHeaderSchemes)
{ {
return authorization.Substring(headerScheme.Length + 1).Trim(); if(authorization.StartsWith($"{headerScheme} ", StringComparison.OrdinalIgnoreCase))
{
return authorization.Substring(headerScheme.Length + 1).Trim();
}
} }
return null; return null;