Base Pipeline for SSO Server Development Based On ASP.Net Identity and Openiddict

Single Sign-On (SSO) has become a key solution in the web application space, offering users a seamless and efficient way to access multiple services with a single account. This article serves as a basic guide for developing an SSO server based on ASP.Net Identity and Openiddict. Whether you’re a developer looking to improve the user experience or an IT professional looking to simplify access management, join us as we uncover the ins and outs of implementing SSO and improving your web ecosystem. This guide uses Openiddict instead of Identity Server 4 because the latter’s developers have moved to a new licensing scheme and the free option is no longer supported for enterprise use.

Requirements: .NET 7

Creating a project:

First, we need to create a new ASP.NET Core Razor Pages application with the “Individual Authentication” option enabled.

Creating a project .NET
Creating a project .NET

After creating the project, you can run it and a new tab with such a window will open in your browser.

After creating the project, you can run it and a new tab with such a window will open in your browser
After creating the project, you can run it and a new tab with such a window will open in your browser

Adding and setting up Openiddict:

Adding and setting up Openiddict
Adding and setting up Openiddict

Now we need to add the Openiddict packages to your .csproj file or through the NuGet package manager.

Now we need to add the Openiddict packages to your .csproj file or through the NuGet package manager
Now we need to add the Openiddict packages to your .csproj file or through the NuGet package manager

Create the following AuthorizeViewModel and ErrorViewModel in the Models folder.

We also need 2 helpers AsyncEnumerableExtensions and FormValueRequiredAttribute. Create them in a folder Helpers.

Create the following AuthorizeViewModel and ErrorViewModel in the Models folder
Create the following AuthorizeViewModel and ErrorViewModel in the Models folder
We also need 2 helpers AsyncEnumerableExtensions and FormValueRequiredAttribute
We also need 2 helpers AsyncEnumerableExtensions and FormValueRequiredAttribute

Add to Views/_ViewImports.cshtml

Add to Views/_ViewImports.cshtml
Add to Views/_ViewImports.cshtml

Add a page Logout to confirm logout Views/Authorization/Logout.cshtml.

Add a page Logout to confirm logout Views/Authorization/Logout.cshtml
Add a page Logout to confirm logout Views/Authorization/Logout.cshtml

Add page Authorize to confirm system logout

Views/Authorization/Authorize.cshtml.

Views/Authorization/Authorize.cshtml
Views/Authorization/Authorize.cshtml

Next we need to edit the file Program.cs

Paste options.UseOpenIddict() in the context configuration.

Paste options.UseOpenIddict() in the context configuration
Paste options.UseOpenIddict() in the context configuration

Add integration Quartz.Net into your application to perform repetitive tasks.

Add integration Quartz.Net into your application to perform repetitive tasks
Add integration Quartz.Net into your application to perform repetitive tasks

Now it’s time to set up Openiddict. You can see the description in the screenshots.

Now it's time to set up Openiddict. You can see the description in the screenshots
Now it’s time to set up Openiddict. You can see the description in the screenshots
Now it's time to set up Openiddict. You can see the description in the screenshots 1
Now it’s time to set up Openiddict. You can see the description in the screenshots 1

You can see a complete example of a configuration file here.

Now we need to add custom controllers, since Openiddict does not have them out of the box, unlike the Identity server. You can find ready-made implementations for this example here and here.

Creating a client:

Now we need to add primary data when the application starts. To do this, create a file Worker.cs

Creating a client
Creating a client

To initialize the data, add this line to the file Program.cs

To initialize the data, add this line to the file Program.cs
To initialize the data, add this line to the file Program.cs

It’s time to add the migrations and apply them to the database (by default the project uses SqLite, if you want you can easily switch to any EF Core supported database).

Example commands for adding and applying migration:

dotnet ef migrations add –project SsoSample\SsoSample.csproj –startup-project SsoSample\SsoSample.csproj –context SsoSample.Data.ApplicationDbContext –configuration Debug AddOpeniddict –output-dir Data\Migrations

dotnet ef database update –project SsoSample\SsoSample.csproj –startup-project SsoSample\SsoSample.csproj –context SsoSample.Data.ApplicationDbContext –configuration Debug 20231008224445_AddOpeniddict

Once the migrations are created, you can run the application and register your user.

To simulate a plug-in application, we will use Postman. Go into it and go to the Authorization -> Configure New Token tab, in Type select Oauth 2.0 and fill in the fields as shown in the example below.

To simulate a plug-in application, we will use Postman
To simulate a plug-in application, we will use Postman

Click Get New Access Token, a browser window will open in which you will be asked to log in to your account. If you see errors at this stage, check whether you are initializing the correct data in the database. If everything went well, you will be transferred back to Postman.

Click Get New Access Token
Click Get New Access Token

Next you will be able to view the received token, which you can use to send to your secure Api.

Next you will be able to view the received token, which you can use to send to your secure Api
Next you will be able to view the received token, which you can use to send to your secure Api

Please note that if you copy the resulting token and paste it into jwt.io, you will receive an invalid signature error since the payload is encrypted by Openiddict. For more details, read this GitHub issue: https://github.com/openiddict/openiddict-core/issues/325

For more details, read this GitHub issue
For more details, read this GitHub issue

Conclusion

The implementation of single sign-on (SSO) in web applications is an integral part of modern authorization and authentication systems. This technology allows users to access multiple applications with a single set of credentials, making the login process much easier and faster.

The benefits of SSO are obvious:

  • increased safety
  • improved user experience
  • reducing the load on administrators.

Users can log in once and automatically gain access to various applications without having to re-enter their credentials. This reduces the risk of password leaks and simplifies application access management.

In this article, we have provided a step-by-step guide on how to implement SSO in web applications. You can easily add other Grant Types (implicit, password, etc.) to this example to allow you to connect even more types of applications to your SSO.

Implementing SSO can be a challenge, but with this guide, you’ve got all the instructions you need for a successful implementation. Remember that security should be your priority, so follow best practices for setting up and securing your SSO system.

Contact Us
Contact Us



    Array
    (
        [_edit_lock] => Array
            (
                [0] => 1749559003:47
            )
    
        [_edit_last] => Array
            (
                [0] => 47
            )
    
        [_thumbnail_id] => Array
            (
                [0] => 20860
            )
    
        [_yoast_wpseo_metadesc] => Array
            (
                [0] => Learn how to implement SSO in your web applications using ASP.Net Identity and Openiddict. #SSO #WebDevelopment #ASPNet"
            )
    
        [_yoast_wpseo_estimated-reading-time-minutes] => Array
            (
                [0] => 9
            )
    
        [_yoast_wpseo_wordproof_timestamp] => Array
            (
                [0] => 
            )
    
        [custom_permalink] => Array
            (
                [0] => blog/base-pipeline-for-sso-server-development-based-on-asp-net-identity-and-openiddict/
            )
    
        [_custom_permalink] => Array
            (
                [0] => field_602ec1181fed7
            )
    
        [images_slider] => Array
            (
                [0] => 
            )
    
        [_images_slider] => Array
            (
                [0] => field_5ee75564abe1e
            )
    
        [template_54_template_name] => Array
            (
                [0] => template-54
            )
    
        [_template_54_template_name] => Array
            (
                [0] => field_6374ce6e52fa9
            )
    
        [template_54_css_class_name] => Array
            (
                [0] => 
            )
    
        [_template_54_css_class_name] => Array
            (
                [0] => field_6374ce8652faa
            )
    
        [template_54_custom_navigation_header] => Array
            (
                [0] => 0
            )
    
        [_template_54_custom_navigation_header] => Array
            (
                [0] => field_6374cec652fab
            )
    
        [template_54_testimonials] => Array
            (
                [0] => 
            )
    
        [_template_54_testimonials] => Array
            (
                [0] => field_6374cf0252fac
            )
    
        [template_54_2_template_name] => Array
            (
                [0] => template-54-2
            )
    
        [_template_54_2_template_name] => Array
            (
                [0] => field_6374ecf40d893
            )
    
        [template_54_2_css_class_name] => Array
            (
                [0] => 
            )
    
        [_template_54_2_css_class_name] => Array
            (
                [0] => field_6374ecf40d8cb
            )
    
        [template_54_2_title_menu] => Array
            (
                [0] => 0
            )
    
        [_template_54_2_title_menu] => Array
            (
                [0] => field_6374ecf40d901
            )
    
        [template_54_2_testimonials] => Array
            (
                [0] => 
            )
    
        [_template_54_2_testimonials] => Array
            (
                [0] => field_6374ecf40d937
            )
    
        [template_55_template_name] => Array
            (
                [0] => template-55
            )
    
        [_template_55_template_name] => Array
            (
                [0] => field_6374df7806a52
            )
    
        [template_55_css_class_name] => Array
            (
                [0] => 
            )
    
        [_template_55_css_class_name] => Array
            (
                [0] => field_6374dfae06a53
            )
    
        [template_55_custom_navigation_header] => Array
            (
                [0] => 
            )
    
        [_template_55_custom_navigation_header] => Array
            (
                [0] => field_6374dfc706a54
            )
    
        [template_55_title] => Array
            (
                [0] => 
            )
    
        [_template_55_title] => Array
            (
                [0] => field_6374dfe906a55
            )
    
        [template_55_items] => Array
            (
                [0] => 
            )
    
        [_template_55_items] => Array
            (
                [0] => field_6374e02606a56
            )
    
        [template_55_buttons] => Array
            (
                [0] => 
            )
    
        [_template_55_buttons] => Array
            (
                [0] => field_63760d837e8bc
            )
    
        [template_56_template_name] => Array
            (
                [0] => template-56
            )
    
        [_template_56_template_name] => Array
            (
                [0] => field_6374e4c352117
            )
    
        [template_56_css_class_name] => Array
            (
                [0] => 
            )
    
        [_template_56_css_class_name] => Array
            (
                [0] => field_6374e563f561f
            )
    
        [template_56_custom_navigation_header] => Array
            (
                [0] => 
            )
    
        [_template_56_custom_navigation_header] => Array
            (
                [0] => field_6374e57ff5620
            )
    
        [template_56_title] => Array
            (
                [0] => 
            )
    
        [_template_56_title] => Array
            (
                [0] => field_6374e592f5621
            )
    
        [template_56_caption] => Array
            (
                [0] => 
            )
    
        [_template_56_caption] => Array
            (
                [0] => field_6376117bfa43c
            )
    
        [template_56_items] => Array
            (
                [0] => 
            )
    
        [_template_56_items] => Array
            (
                [0] => field_6374e601f5622
            )
    
        [template_56_url] => Array
            (
                [0] => 
            )
    
        [_template_56_url] => Array
            (
                [0] => field_6376127349c70
            )
    
        [template_57_template_name] => Array
            (
                [0] => template-57
            )
    
        [_template_57_template_name] => Array
            (
                [0] => field_6374e66bf4273
            )
    
        [template_57_css_class_name] => Array
            (
                [0] => 
            )
    
        [_template_57_css_class_name] => Array
            (
                [0] => field_6374e688f4274
            )
    
        [template_57_custom_navigation_header] => Array
            (
                [0] => 
            )
    
        [_template_57_custom_navigation_header] => Array
            (
                [0] => field_6374e699f4275
            )
    
        [template_57_title] => Array
            (
                [0] => 
            )
    
        [_template_57_title] => Array
            (
                [0] => field_6376155db54eb
            )
    
        [template_57_caption] => Array
            (
                [0] => 
            )
    
        [_template_57_caption] => Array
            (
                [0] => field_6376157cb54ec
            )
    
        [template_57_items] => Array
            (
                [0] => 
            )
    
        [_template_57_items] => Array
            (
                [0] => field_6376159ab54ed
            )
    
        [template_58_template_name] => Array
            (
                [0] => template-58
            )
    
        [_template_58_template_name] => Array
            (
                [0] => field_6374eb92882bd
            )
    
        [template_58_css_class_name] => Array
            (
                [0] => 
            )
    
        [_template_58_css_class_name] => Array
            (
                [0] => field_6374ebad882be
            )
    
        [template_58_custom_navigation_header] => Array
            (
                [0] => 
            )
    
        [_template_58_custom_navigation_header] => Array
            (
                [0] => field_6374ebc4882bf
            )
    
        [template_58_title] => Array
            (
                [0] => 
            )
    
        [_template_58_title] => Array
            (
                [0] => field_63761879feb02
            )
    
        [template_58_caption] => Array
            (
                [0] => 
            )
    
        [_template_58_caption] => Array
            (
                [0] => field_6376188ffeb03
            )
    
        [template_58_items] => Array
            (
                [0] => 
            )
    
        [_template_58_items] => Array
            (
                [0] => field_637618a4feb04
            )
    
        [template_58_2_template_name] => Array
            (
                [0] => template-58-2
            )
    
        [_template_58_2_template_name] => Array
            (
                [0] => field_637618f9a59c1
            )
    
        [template_58_2_css_class_name] => Array
            (
                [0] => 
            )
    
        [_template_58_2_css_class_name] => Array
            (
                [0] => field_637618f9a59f8
            )
    
        [template_58_2_custom_navigation_header] => Array
            (
                [0] => 
            )
    
        [_template_58_2_custom_navigation_header] => Array
            (
                [0] => field_637618f9a5a2e
            )
    
        [template_58_2_title] => Array
            (
                [0] => 
            )
    
        [_template_58_2_title] => Array
            (
                [0] => field_637618f9a5a65
            )
    
        [template_58_2_caption] => Array
            (
                [0] => 
            )
    
        [_template_58_2_caption] => Array
            (
                [0] => field_637618f9a5a9b
            )
    
        [template_58_2_items] => Array
            (
                [0] => 
            )
    
        [_template_58_2_items] => Array
            (
                [0] => field_637618f9a5ad1
            )
    
        [_yoast_wpseo_primary_category] => Array
            (
                [0] => 
            )
    
        [primary_tag] => Array
            (
                [0] => 194
            )
    
        [_primary_tag] => Array
            (
                [0] => field_669f60677f9e1
            )
    
        [lang_page_id] => Array
            (
                [0] => 20835
            )
    
        [_lang_page_id] => Array
            (
                [0] => field_67167a251e356
            )
    
        [short_title] => Array
            (
                [0] => 
            )
    
        [_short_title] => Array
            (
                [0] => field_5ecf97d78daad
            )
    
        [css_class_name_general] => Array
            (
                [0] => 
            )
    
        [_css_class_name_general] => Array
            (
                [0] => field_5ed094cbee060
            )
    
        [enable_breadcrumb] => Array
            (
                [0] => 1
            )
    
        [_enable_breadcrumb] => Array
            (
                [0] => field_5eddfba50cb74
            )
    
        [enable_right_side_bar] => Array
            (
                [0] => 1
            )
    
        [_enable_right_side_bar] => Array
            (
                [0] => field_5ee09b21eb9b6
            )
    
        [enable_case_studies_block] => Array
            (
                [0] => 1
            )
    
        [_enable_case_studies_block] => Array
            (
                [0] => field_5ecf982ce922c
            )
    
        [enable_news_block] => Array
            (
                [0] => 1
            )
    
        [_enable_news_block] => Array
            (
                [0] => field_5ecf9950d8e87
            )
    
        [enable_contact_form_block] => Array
            (
                [0] => 1
            )
    
        [_enable_contact_form_block] => Array
            (
                [0] => field_5ecf99695a591
            )
    
        [case_study_block_css_class_name] => Array
            (
                [0] => 
            )
    
        [_case_study_block_css_class_name] => Array
            (
                [0] => field_5ed09500ae937
            )
    
        [case_study_block_header_title] => Array
            (
                [0] => Case studies
            )
    
        [_case_study_block_header_title] => Array
            (
                [0] => field_5ecf9b149f113
            )
    
        [case_study_block_caption] => Array
            (
                [0] => 
            )
    
        [_case_study_block_caption] => Array
            (
                [0] => field_5ed0812ca5fe4
            )
    
        [case_study_solution_categories] => Array
            (
                [0] => 
            )
    
        [_case_study_solution_categories] => Array
            (
                [0] => field_5ee74d2cc8b67
            )
    
        [case_study_industry_categories] => Array
            (
                [0] => 
            )
    
        [_case_study_industry_categories] => Array
            (
                [0] => field_5ee74ee7b2529
            )
    
        [case_study_technology_categories] => Array
            (
                [0] => 
            )
    
        [_case_study_technology_categories] => Array
            (
                [0] => field_5ee74f21b252a
            )
    
        [news_block_css_class_name] => Array
            (
                [0] => 
            )
    
        [_news_block_css_class_name] => Array
            (
                [0] => field_5ed095295310a
            )
    
        [news_block_header_title] => Array
            (
                [0] => News
            )
    
        [_news_block_header_title] => Array
            (
                [0] => field_5ecf9b8a4bc15
            )
    
        [news_block_caption] => Array
            (
                [0] => 
            )
    
        [_news_block_caption] => Array
            (
                [0] => field_62b4904f21245
            )
    
        [news_block_more_news_title] => Array
            (
                [0] => More news
            )
    
        [_news_block_more_news_title] => Array
            (
                [0] => field_5ecf9bbcbc459
            )
    
        [news_block_categories] => Array
            (
                [0] => 
            )
    
        [_news_block_categories] => Array
            (
                [0] => field_5ee0b7b2b1008
            )
    
        [contact_form_block_css_class_name] => Array
            (
                [0] => news
            )
    
        [_contact_form_block_css_class_name] => Array
            (
                [0] => field_5ed0953ea14e1
            )
    
        [contact_form_block_image_banner] => Array
            (
                [0] => 
            )
    
        [_contact_form_block_image_banner] => Array
            (
                [0] => field_5ecf9cf052349
            )
    
        [news_block_more_news_url] => Array
            (
                [0] => 
            )
    
        [_news_block_more_news_url] => Array
            (
                [0] => field_673df8af3eaa3
            )
    
        [_yoast_wpseo_title] => Array
            (
                [0] => SSO Server Dev Pipeline with ASP.Net Identity & Openiddict
            )
    
    )