public async Task <ActionResult> PostToken(SSOTokenDTO tokendata) { Console.WriteLine(tokendata); try { UserDTO user = await SSOHelper.GetSSOData(tokendata); User databaseUserReturn = await _context.Users.FindAsync(user.Username.ToLower()); if (databaseUserReturn == null) { _context.Users.Add(await UserFactory.Create(user.Username, user.Mail, user.Gn, user.Sn)); await _context.SaveChangesAsync(); user.AccountType = nameof(Models.User.UserType.User); } else { if (databaseUserReturn.Mail == null) { databaseUserReturn.Mail = user.Mail; } if (databaseUserReturn.GeneralName == null) { databaseUserReturn.GeneralName = user.Gn; } if (databaseUserReturn.Surname == null) { databaseUserReturn.Surname = user.Sn; } _context.Users.Update(databaseUserReturn); await _context.SaveChangesAsync(); user.AccountType = databaseUserReturn.AccountType.ToString(); } var response = new { jwt = JwtHelper.Create(user, _configuration.GetValue <String>("APIHostName")) }; return(Ok(response)); } catch (ArgumentException) { return(Unauthorized("Authentication Failed")); } }