public IActionResult GetRedirectFromBank(BankEnum bankId, string userId) { IBankApi bankApi; switch (bankId) { case BankEnum.Seb: //should differ from swed bankApi = new SebApi(); break; case BankEnum.MobileSign: bankApi = new IsignMobileApi(); break; default: throw new Exception("Bank not supported"); } var tokenDto = bankApi.GetAuthorized(userId); TokensRepository.Add(tokenDto); return(Redirect($"http://localhost:3000/link?token={tokenDto.Token}")); }
public static Token CreateToken(User u, string deviceName) { string key = "401b09eab3c013d4ca54922bb802bec8fd5318192b0a75f201d8b3727429090fb337591abd3e44453b954555b7a0812e1081c39b740293f765eae731f5a65ed1"; var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)); var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256Signature); var header = new JwtHeader(credentials); var payload = new JwtPayload { { "Name", u.Name }, { "Surname", u.Surname }, { "Email", u.Email }, { "DeviceName", deviceName }, { "CreationDateTime", System.DateTime.Now } }; var secToken = new JwtSecurityToken(header, payload); var handler = new JwtSecurityTokenHandler(); var tokenString = handler.WriteToken(secToken); Token t = new Token(); t.TokenString = tokenString; t.ObjectUser = u; t.ValidTo = System.DateTime.Now.AddHours(8); t.DeviceName = deviceName; _tokenRepository.Add(t); _tokenRepository.Save(); return(t); }