mirror of
https://github.com/bitwarden/server.git
synced 2025-07-16 15:17:33 -05:00
fire up events for identityserver validation scheme
This commit is contained in:
@ -47,7 +47,8 @@ namespace Bit.Core.Identity
|
||||
if(!context.HttpContext.User.Identity.IsAuthenticated)
|
||||
{
|
||||
context.State = EventResultState.HandledResponse;
|
||||
context.Ticket = new AuthenticationTicket(context.HttpContext.User, new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
||||
context.Ticket = new AuthenticationTicket(context.HttpContext.User, new AuthenticationProperties(),
|
||||
context.Options.AuthenticationScheme);
|
||||
}
|
||||
|
||||
return Task.FromResult(0);
|
||||
|
30
src/Core/Identity/TokenRetrieval.cs
Normal file
30
src/Core/Identity/TokenRetrieval.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Bit.Core.Identity
|
||||
{
|
||||
public static class TokenRetrieval
|
||||
{
|
||||
public static Func<HttpRequest, string> FromAuthorizationHeaderOrQueryString(string headerScheme = "Bearer",
|
||||
string qsName = "account_token")
|
||||
{
|
||||
return (request) =>
|
||||
{
|
||||
string authorization = request.Headers["Authorization"].FirstOrDefault();
|
||||
|
||||
if(string.IsNullOrWhiteSpace(authorization))
|
||||
{
|
||||
return request.Query[qsName].FirstOrDefault();
|
||||
}
|
||||
|
||||
if(authorization.StartsWith(headerScheme + " ", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return authorization.Substring(headerScheme.Length + 1).Trim();
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user