示例#1
0
        private async Task <IActionResult> GetToken(TokenRequestViewModel model)
        {
            try
            {
                var user = await UserManager.FindByNameAsync(model.username);

                if (user == null && model.username.Contains("@"))
                {
                    user = await UserManager.FindByEmailAsync(model.username);
                }

                if (user == null ||
                    !await UserManager.CheckPasswordAsync(user, model.password))
                {
                    return(new UnauthorizedResult());
                }

                var rt = CreateRefreshToken(model.client_id, user.Id);

                dataProcessor.AddNewRefreshToken(this.DbContext, rt);

                var newToken = CreateAccessToken(user.Id, rt.Value);

                return(new JsonResult(newToken, JsonSettings));
            }
            catch (Exception ex)
            {
                return(new UnauthorizedResult());
            }
        }