First commit that builds.
This commit is contained in:
28
code/MessengerBroker/Handlers/AuthHandler.cs
Normal file
28
code/MessengerBroker/Handlers/AuthHandler.cs
Normal file
@ -0,0 +1,28 @@
|
||||
namespace MessengerBroker.Handlers
|
||||
{
|
||||
public class AuthHandler
|
||||
{
|
||||
private readonly Settings settings;
|
||||
|
||||
public AuthHandler(Settings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public Guid? Auth(HttpContext context)
|
||||
{
|
||||
var authHeader = context.Request.Headers["Authorization"].ToString();
|
||||
|
||||
if (!string.IsNullOrEmpty(authHeader) && authHeader.StartsWith("Bearer "))
|
||||
{
|
||||
var token = authHeader.Substring("Bearer ".Length).Trim();
|
||||
if (Guid.TryParse(token, out Guid brokerId) && this.settings.Slaves.Any(x => x.BrokerId == brokerId))
|
||||
{
|
||||
return brokerId;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user