public async static Task <UserDTO> GetSSOData(SSOTokenDTO tokendata) { try { using var client = new HttpClient(); var result = await client.GetAsync($"https://sso.sdu.dk/serviceValidate?ticket={tokendata.Token}&service={tokendata.ServiceEndpoint}"); result.EnsureSuccessStatusCode(); Console.WriteLine(await result.Content.ReadAsStringAsync()); return(await ResolveSSOReponse(result)); } catch (HttpRequestException e) { Console.Out.WriteLine(e.StackTrace); throw new ArgumentException("SSO Response not a sucess return code", e); } }
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")); } }