Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var builder = services
- .AddIdentityServer(options =>
- {
- options.IssuerUri = "https://my.services.is4host";
- options.Events.RaiseErrorEvents = true;
- options.Events.RaiseInformationEvents = true;
- options.Events.RaiseFailureEvents = true;
- options.Events.RaiseSuccessEvents = true;
- });
- builder
- .AddInMemoryClients(IS4Config.GetClients())
- .AddInMemoryIdentityResources(IS4Config.GetIdentityResources())
- .AddInMemoryApiResources(IS4Config.GetAPIResources())
- .AddTestUsers(new List<TestUser>
- {
- new TestUser {
- SubjectId = Guid.NewGuid().ToString(),
- Claims = new List<Claim> {
- new Claim(JwtClaimTypes.Subject, MyDemoUser.ElevatedUser.UserName),
- new Claim(JwtClaimTypes.Email, MyDemoUser.ElevatedUser.Email),
- new Claim(JwtClaimTypes.Role, MyDemoUser.ElevatedUser.Roles[0]),
- new Claim(JwtClaimTypes.Role, MyDemoUser.ElevatedUser.Roles[1])
- },
- IsActive = true,
- Password = MyDemoUser.ElevatedUser.Password,
- Username = MyDemoUser.ElevatedUser.UserName
- },
- new TestUser {
- SubjectId = Guid.NewGuid().ToString(),
- Claims = new List<Claim> {
- new Claim(JwtClaimTypes.Subject, MyDemoUser.WorkstationUser.UserName),
- new Claim(JwtClaimTypes.Email, MyDemoUser.WorkstationUser.Email),
- new Claim(JwtClaimTypes.Role, MyDemoUser.WorkstationUser.Roles[0])
- },
- IsActive = true,
- Password = MyDemoUser.WorkstationUser.Password,
- Username = MyDemoUser.WorkstationUser.UserName
- }
- });
- var is4Host = new WebApplicationTestFactory<Services.IS4Host.Startup>();
- var client = is4Host.CreateClient();
- var disco = await client.GetDiscoveryDocumentAsync("https://amds.services.is4host");
- if (disco.IsError)
- {
- Console.WriteLine(disco.Error);
- return false;
- }
- // request token
- var tokenResponse = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
- {
- Address = disco.TokenEndpoint,
- ClientId = AMDSClient.QatarAMDS3.ClientId,
- ClientSecret = AMDSClient.QatarAMDS3.ClientSecret,
- Scope = AMDSApiResource.QatarGateway.Name,
- UserName = user.UserName,
- Password = user.Password
- });
- if (tokenResponse.IsError)
- {
- Console.WriteLine(tokenResponse.Error);
- return false;
- }
- Console.WriteLine(tokenResponse.Json);
- Console.WriteLine("nn");
- return true;
- {
- "error": "invalid_grant",
- "error_description": "invalid_username_or_password"
- }
Add Comment
Please, Sign In to add comment