This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public UserTokenBinding(IServiceProvider serviceProvider) | |
{ | |
_readTokenService = serviceProvider.GetService<IReadTokenService>(); | |
_configuration = serviceProvider.GetService<IConfiguration>(); | |
} | |
public Task<IValueProvider> BindAsync(BindingContext context) | |
{ | |
var headers = context.BindingData["Headers"] as IDictionary<string, string>; | |
var issuerToken = _configuration["JwtIssuer"]; | |
if (!headers.ContainsKey("Authorization")) | |
return Task.FromResult<IValueProvider>(new UserTokenValueProvider(string.Empty, issuerToken, _readTokenService)); | |
var userTokenGroups = Regex.Match(headers["Authorization"], @"^Bearer (\S+)$").Groups; | |
var userToken = userTokenGroups.ElementAt(1).Value; | |
return Task.FromResult<IValueProvider>(new UserTokenValueProvider(userToken, issuerToken, _readTokenService)); | |
} | |
public ParameterDescriptor ToParameterDescriptor() | |
{ | |
return new ParameterDescriptor(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment