Currently browsing: C#

Add custom claims to access token in IdentityServer4

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),
			
Read more

Issue access token to IdentityServer 4 from IdentityServer 4

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 …

Read more

First look at .NET Interactive and Jupyter

Wouldn’t be nice to have a place to test some quick things with C# in Jupyter Notebook?
You can do it now!

In the beginning of February 2020, Microsoft announced the second preview of .NET Notebooks experience.

What is .NET Interactive. It is a group of CLI tools and APIs that allow the users to create interactive experience across the web, markdown and notebooks.

.NET Interactive components.

Read more

Selecting local NuGet server

Doesn’t matter if you are a big corporation, small company, a team of people or even a single person writing software it is worth organizing your code in modules and reuse it.

Using .NET (Standard/Core/Framework …) has the advantage of NuGet. It is open source package manager for .NET. You can use the public feed on https://www.nuget.org/, run your own NuGet server or create a local feed.

Let’s start with the simplest one – Local Feed.
Local NuGet package …

Read more

How to create .NET Core NuGet Package in Visual Studio 2019

What is .NET Core?
.NET Core is an open source platform supported by Microsoft that can run on Windows, Windows, macOS and Linux operating systems and across multiple architectures including x64, x86 and ARM.
You can use multiple languages to write applications and libraries for .NET Core – C#, Visual Basic and F#.

In order to create a NuGet package with Visual Studio 2019 – select new Class Library (.NET Core) project.

I am going to call the project LoggingLib. …

Read more