Ejemplo n.º 1
0
        public async Task <JwtResponse> GenerateJwtAsync(string clientId, string clientSecret, string username)
        {
            var jwtResponse = new JwtResponse();
            var spec        = new ClientApiSpecification(clientId, clientSecret);
            var clientApi   = await _clientApiRepository.GetAsync(spec);

            if (clientApi != null)
            {
                jwtResponse = _jwt.GetJwt(clientApi, username);

                //update ClientApi
                clientApi.Token        = jwtResponse.Token;
                clientApi.ExpiredToken = jwtResponse.ValidTo;
                clientApi.ModifiedBy   = username;
                await _clientApiRepository.UpdateAsync(clientApi);
            }

            return(jwtResponse);
        }
Ejemplo n.º 2
0
        public AuthorizeModel Authentication(Domain.Models.AccountView acc)
        {
            List <Claim> claims = new List <Claim>()
            {
                new Claim(ClaimsIdentity.DefaultNameClaimType, acc.UserName),
                new Claim(ClaimsIdentity.DefaultRoleClaimType, acc.Role),
                new Claim("id", acc.Id.ToString())
            };
            ClaimsIdentity identity = new ClaimsIdentity(
                claims,
                "Token",
                ClaimsIdentity.DefaultNameClaimType,
                ClaimsIdentity.DefaultRoleClaimType);

            AuthorizeModel model = new AuthorizeModel()
            {
                AccountId      = acc.Id,
                AccessToken    = _jwt.GetJwt(identity),
                RefreshToken   = Guid.NewGuid().ToString(),
                RefreshExpires = DateTime.Now.AddMinutes(_settings.Value.RefreshLifetime)
            };

            return(model);
        }