.NET - Svet Paregov https://paregov.net Svetoslav (Svet) Paregov's Personal Web Site Mon, 24 Jan 2022 14:33:39 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 https://paregov.net/wp-content/uploads/2019/11/cropped-site_icon_512x512-32x32.png .NET - Svet Paregov https://paregov.net 32 32 169379028 Add custom claims to access token in IdentityServer4 https://paregov.net/add-custom-claims-to-access-token-in-identityserver4/?utm_source=rss&utm_medium=rss&utm_campaign=add-custom-claims-to-access-token-in-identityserver4 Tue, 11 Jan 2022 14:07:40 +0000 https://paregov.net/?p=9598 All identity providers are flexible and allow you to add custom claims in the issued access token. IdentityServer4 is no different in this scenario. Here is a short manual how to add custom claims in IdentityServer4 access token response.

You need to implement a ProfileService:

public class ProfileService : IProfileService
{
	public ProfileService(
		UserManager<PafUseruserManager)
	{
		_userManager = userManager;
	}

	public async Task GetProfileDataAsync(ProfileDataRequestContext context)
	{
		var user = await _userManager.GetUserAsync(context.Subject);

		var claims = new List<Claim{
			new Claim("custom_claim1", user.CustomClaim1),
			

…

The post Add custom claims to access token in IdentityServer4 first appeared on Svet Paregov.

]]>
All identity providers are flexible and allow you to add custom claims in the issued access token. IdentityServer4 is no different in this scenario. Here is a short manual how to add custom claims in IdentityServer4 access token response.

You need to implement a ProfileService:

public class ProfileService : IProfileService
{
	public ProfileService(
		UserManager<PafUseruserManager)
	{
		_userManager = userManager;
	}

	public async Task GetProfileDataAsync(ProfileDataRequestContext context)
	{
		var user = await _userManager.GetUserAsync(context.Subject);

		var claims = new List<Claim{
			new Claim("custom_claim1", user.CustomClaim1),
			
…

The post Add custom claims to access token in IdentityServer4 first appeared on Svet Paregov.

]]>
9598
Issue access token to IdentityServer 4 from IdentityServer 4 https://paregov.net/issue-access-token-to-identityserver-4-from-identityserver-4/?utm_source=rss&utm_medium=rss&utm_campaign=issue-access-token-to-identityserver-4-from-identityserver-4 Tue, 11 Jan 2022 13:54:05 +0000 https://paregov.net/?p=9594 You need sometimes IdentityServer 4 to interact with other services and to need information from them. And in many cases the same instance of the IdentityServer is the one that authorizes the access to those other services. Wee need to issue an access token to our-self in order to get/post the necessary information.

In my case I needed to create a corresponding object in another service on new user registration. To get the access token needed I have used IdentityServerTooks …

The post Issue access token to IdentityServer 4 from IdentityServer 4 first appeared on Svet Paregov.

]]>
You need sometimes IdentityServer 4 to interact with other services and to need information from them. And in many cases the same instance of the IdentityServer is the one that authorizes the access to those other services. Wee need to issue an access token to our-self in order to get/post the necessary information.

In my case I needed to create a corresponding object in another service on new user registration. To get the access token needed I have used IdentityServerTooks …

The post Issue access token to IdentityServer 4 from IdentityServer 4 first appeared on Svet Paregov.

]]>
9594
Fix Unable to unprotect the message.State. exception on Identity Server redirect https://paregov.net/fix-unable-to-unprotect-the-message-state-exception-on-identity-server-redirect/?utm_source=rss&utm_medium=rss&utm_campaign=fix-unable-to-unprotect-the-message-state-exception-on-identity-server-redirect Thu, 06 Jan 2022 19:02:00 +0000 https://paregov.net/?p=9571 After fixing the 502 Bad Gateway issue I hit another one.

Here is the exception I have from the logs

HTTP POST /signin-oidc responded 500 in 77.6515 ms

System.Exception: An error was encountered while handling the remote login. —> System.Exception: Unable to unprotect the message.State. — End of inner exception stack trace — at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync() at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

As mentioned in the previous post – when I run from Visual …

The post Fix Unable to unprotect the message.State. exception on Identity Server redirect first appeared on Svet Paregov.

]]>
After fixing the 502 Bad Gateway issue I hit another one.

Here is the exception I have from the logs

HTTP POST /signin-oidc responded 500 in 77.6515 ms

System.Exception: An error was encountered while handling the remote login. —> System.Exception: Unable to unprotect the message.State. — End of inner exception stack trace — at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync() at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

As mentioned in the previous post – when I run from Visual …

The post Fix Unable to unprotect the message.State. exception on Identity Server redirect first appeared on Svet Paregov.

]]>
9571
Solve identity server signin-oidc 502 Bad Gateway error https://paregov.net/solve-identity-server-signin-oidc-502-bad-gateway-error/?utm_source=rss&utm_medium=rss&utm_campaign=solve-identity-server-signin-oidc-502-bad-gateway-error Thu, 06 Jan 2022 17:12:59 +0000 https://paregov.net/?p=9560 It was time to run the Identity Server 4 with the rest of the microservices in the Kubernetes cluster on a dedicated machine. I am running single node cluster, since this is not production, but just one of my pet projects and it is running locally. Still, it is going through one more Nginx (on top of the Kubernetes ingress) used to expose over the internet and create the certificates through Let’s Encrypt.

When I run the Identity Server 4 …

The post Solve identity server signin-oidc 502 Bad Gateway error first appeared on Svet Paregov.

]]>
It was time to run the Identity Server 4 with the rest of the microservices in the Kubernetes cluster on a dedicated machine. I am running single node cluster, since this is not production, but just one of my pet projects and it is running locally. Still, it is going through one more Nginx (on top of the Kubernetes ingress) used to expose over the internet and create the certificates through Let’s Encrypt.

When I run the Identity Server 4 …

The post Solve identity server signin-oidc 502 Bad Gateway error first appeared on Svet Paregov.

]]>
9560