Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.