コード例 #1
0
        public async Task <ActionResult> LoginGoogle([FromBody] LoginDataset loginDataset)
        {
            try
            {
                FirebaseToken decodedToken = await FirebaseAuth.DefaultInstance.VerifyIdTokenAsync(loginDataset.Token);

                AccountDataset account = await _service.Login(decodedToken, loginDataset.Flg);

                if (account != null)
                {
                    var claims = new[]
                    {
                        new Claim(JwtRegisteredClaimNames.Sub, account.AccountId.ToString()),
                        new Claim(JwtRegisteredClaimNames.Email, account.Email),
                        new Claim(ClaimTypes.Role, account.Role.RoleName),
                        new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                    };

                    var key   = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(AppSettings.Settings.JwtSecret));
                    var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
                    var token = new JwtSecurityToken(AppSettings.Settings.Issuer,
                                                     AppSettings.Settings.Audience,
                                                     claims,
                                                     // expires: DateTime.Now.AddSeconds(55 * 60),
                                                     signingCredentials: creds);
                    return(Ok(new
                    {
                        token = new JwtSecurityTokenHandler().WriteToken(token)
                    }));
                }
                else
                {
                    return(Forbid());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
コード例 #2
0
 public IActionResult Login([FromBody] LoginRequest model)
 {
     return(_authenService.Login(this, model));
 }