예제 #1
0
        public JsonWebToken Create(string username)
        {
            var nowUtc       = DateTime.UtcNow;
            var centuryBegin = new DateTime(1970, 1, 1).ToUniversalTime();
            var iat          = (long)(new TimeSpan(nowUtc.Ticks - centuryBegin.Ticks).TotalSeconds);
            var payload      = new JwtPayload
            {
                { "sub", username },
                { "iss", _options.Issuer },
                { "iat", iat },
                { "unique_name", username },
            };
            var jwt   = new JwtSecurityToken(_jwtHeader, payload);
            var token = _jwtSecurityTokenHandler.WriteToken(jwt);

            _accessManager.Activate(token);
            return(new JsonWebToken
            {
                AccessToken = token,
            });
        }