Guest User

Untitled

a guest
Jan 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. var builder = services
  2. .AddIdentityServer(options =>
  3. {
  4. options.IssuerUri = "https://my.services.is4host";
  5. options.Events.RaiseErrorEvents = true;
  6. options.Events.RaiseInformationEvents = true;
  7. options.Events.RaiseFailureEvents = true;
  8. options.Events.RaiseSuccessEvents = true;
  9. });
  10.  
  11. builder
  12. .AddInMemoryClients(IS4Config.GetClients())
  13. .AddInMemoryIdentityResources(IS4Config.GetIdentityResources())
  14. .AddInMemoryApiResources(IS4Config.GetAPIResources())
  15. .AddTestUsers(new List<TestUser>
  16. {
  17. new TestUser {
  18. SubjectId = Guid.NewGuid().ToString(),
  19. Claims = new List<Claim> {
  20. new Claim(JwtClaimTypes.Subject, MyDemoUser.ElevatedUser.UserName),
  21. new Claim(JwtClaimTypes.Email, MyDemoUser.ElevatedUser.Email),
  22. new Claim(JwtClaimTypes.Role, MyDemoUser.ElevatedUser.Roles[0]),
  23. new Claim(JwtClaimTypes.Role, MyDemoUser.ElevatedUser.Roles[1])
  24. },
  25. IsActive = true,
  26. Password = MyDemoUser.ElevatedUser.Password,
  27. Username = MyDemoUser.ElevatedUser.UserName
  28. },
  29. new TestUser {
  30. SubjectId = Guid.NewGuid().ToString(),
  31. Claims = new List<Claim> {
  32. new Claim(JwtClaimTypes.Subject, MyDemoUser.WorkstationUser.UserName),
  33. new Claim(JwtClaimTypes.Email, MyDemoUser.WorkstationUser.Email),
  34. new Claim(JwtClaimTypes.Role, MyDemoUser.WorkstationUser.Roles[0])
  35. },
  36. IsActive = true,
  37. Password = MyDemoUser.WorkstationUser.Password,
  38. Username = MyDemoUser.WorkstationUser.UserName
  39. }
  40. });
  41.  
  42. var is4Host = new WebApplicationTestFactory<Services.IS4Host.Startup>();
  43. var client = is4Host.CreateClient();
  44.  
  45. var disco = await client.GetDiscoveryDocumentAsync("https://amds.services.is4host");
  46. if (disco.IsError)
  47. {
  48. Console.WriteLine(disco.Error);
  49. return false;
  50. }
  51.  
  52. // request token
  53. var tokenResponse = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
  54. {
  55. Address = disco.TokenEndpoint,
  56. ClientId = AMDSClient.QatarAMDS3.ClientId,
  57. ClientSecret = AMDSClient.QatarAMDS3.ClientSecret,
  58. Scope = AMDSApiResource.QatarGateway.Name,
  59. UserName = user.UserName,
  60. Password = user.Password
  61. });
  62.  
  63. if (tokenResponse.IsError)
  64. {
  65. Console.WriteLine(tokenResponse.Error);
  66. return false;
  67. }
  68.  
  69. Console.WriteLine(tokenResponse.Json);
  70. Console.WriteLine("nn");
  71.  
  72. return true;
  73.  
  74. {
  75. "error": "invalid_grant",
  76. "error_description": "invalid_username_or_password"
  77. }
Add Comment
Please, Sign In to add comment