Multiple IdentityServer Federation : Error Unable to unprotect the message.State

I believe you are getting the Unable to unprotect the message.State error because one of your OIDC providers is trying to decrypt/unprotect the message state of the other one. (The message state is just a random string to help with security.) I suggest that you name the AuthenticationSchemes for each OIDC provider like oidc-demo and … Read more

Generate access token with IdentityServer4 without password

[HttpPost(“loginas/{id}”)] [Authorize(Roles = “admin”)] public async Task<IActionResult> LoginAs(int id, [FromServices] ITokenService TS, [FromServices] IUserClaimsPrincipalFactory<ApplicationUser> principalFactory, [FromServices] IdentityServerOptions options) { var Request = new TokenCreationRequest(); var User = await userManager.FindByIdAsync(id.ToString()); var IdentityPricipal = await principalFactory.CreateAsync(User); var IdServerPrincipal = IdentityServerPrincipal.Create(User.Id.ToString(), User.UserName, IdentityPricipal.Claims.ToArray()); Request.Subject = IdServerPrincipal; Request.IncludeAllIdentityClaims = true; Request.ValidatedRequest = new ValidatedRequest(); Request.ValidatedRequest.Subject = Request.Subject; Request.ValidatedRequest.SetClient(Config.GetClients().First()); Request.Resources … Read more

ApiResource vs ApiScope vs IdentityResource

Scopes listed under IdentityResources are the scopes that will be included in the ID-token. ApiScopes is what you ask for as a client and as a user you give consent to. Optionally, one or more ApiResources can associated with an ApiScope. The ApiScope and ApiResources controls what is included in the access token. ApiResources points … Read more

IdentityServer4 register UserService and get users from database in asp.net core

Update – IdentityServer 4 has changed and replaced IUserService with IResourceOwnerPasswordValidator and IProfileService I used my UserRepository to get all the user data from the database. This is injected (DI) into the constructors, and defined in Startup.cs. I also created the following classes for identity server (which is also injected): First define ResourceOwnerPasswordValidator.cs: public class … Read more