public ApiResponse<IdentityToken> UserToken(Admin admin) { var user = Context.Admins.FirstOrDefault(x => x.LoginName == admin.LoginName && x.Password == admin.Password && x.IsActive); if (user == null) { throw new UnauthorizedAccessException(""); } ClaimsIdentity oAuthIdentity = new ApplicationIdentityUser().GenerateUserIdentity(user, "Jwt"); var ticket = new AuthenticationTicket(oAuthIdentity, new AuthenticationProperties()); var currentUtc = new SystemClock().UtcNow; ticket.Properties.IssuedUtc = currentUtc; ticket.Properties.ExpiresUtc = currentUtc.AddDays(1); var token = AuthConfig.OAuthServerOptions.AccessTokenFormat.Protect(ticket); return new ApiResponse<IdentityToken>(new IdentityToken() { AccessToken = token, ExpiresIn = (long)AuthConfig.OAuthServerOptions.AuthorizationCodeExpireTimeSpan.TotalSeconds, TokenType = AuthConfig.OAuthServerOptions.AuthenticationType}); }