public async Task <string> GetTokenFromHeader(string authorizationHeader)
        {
            var token = _jwtTokenHandler.GetFromAuthorizationHeader(authorizationHeader);

            if (token.IsEmpty())
            {
                _logger.LogError($"Can not get token from header, because value from authorization header is empty.");
            }

            return(await Task.FromResult(token));
        }
Exemple #2
0
        private static StatelessAuthenticationConfiguration Configuration(IJwtTokenHandler jwtTokenHandler)
        => new StatelessAuthenticationConfiguration(ctx =>
        {
            var authToken = jwtTokenHandler.GetFromAuthorizationHeader(ctx.Request.Headers.Authorization);
            if (authToken.HasNoValue)
            {
                return(null);
            }
            var jwt = jwtTokenHandler.Parse(authToken.Value);
            if (jwt.HasNoValue)
            {
                return(null);
            }
            var token = jwt.Value;

            return(jwt.HasValue ? new CollectivelyIdentity(token.Subject,
                                                           token.Role, token.State, token.Claims) : null);
        });