Migrate your ASP.NET Core based IdentityServer inside Azure Functions
Image from https://undraw.co

Migrate your ASP.NET Core based IdentityServer inside Azure Functions

Azure Functions

Summary:

Creating a business application based on Azure Functions will often involve User Authentication. In the .NET world, it often means leveraging IdentityServer, so migrating it to Azure Functions seems like an interesting approach to lower the cost of hosting your authentication server. 

TLDR: Check the sample on GitHub.

 Ingredients:

Disclaimer:

This is mainly a proof of concept to show the possibilities. TestServer, which is used in this recipe, should be reviewed for thread safety/performance and a new custom server should be developed to use this recipe in production. Thanks to Christian Weyer for pointing me to this blog post which provides an alternative approach inspired from TestServer. 

Directions:

⏲️ Preparation👨‍🍳 Ready In
15 minutes30 minutes
  1. Download IdentityServer4 samples from GitHub: https://github.com/IdentityServer/IdentityServer4.Samples
  2. Open the solution for Quickstart #3: 3_ImplicitFlowAuthentication
  3. Apply the Hosting your ASP.NET Core MVC APIs inside Azure Functions recipe to project Api.
    1. Make sure that local.settings.json is using a LocalHttpPort of 5001
  4. Apply the Hosting your ASP.NET Core Razor Pages inside Azure Functions recipe to projects IdentityServer.
    1. Make sure that local.settings.json is using a LocalHttpPort of 5000
    2. Post-build steps are not required here.
  5. Apply the Hosting your ASP.NET Core Razor Pages inside Azure Functions recipe to projects MvcClient.
    1. Make sure that local.settings.json is using a LocalHttpPort of 5002
  6. Change startup project to start multiple project at once: ApiIdentityServer MvcClient
    Open StartUp Projects Configuration
    Put your caption here
    Select StartUp Projects Configuration
    Put your caption here
  7. Press OK.
  8. Press F5 to start all 3 Functions.
  9. To test your Functions, navigate to http://localhost:5002
    1. Select the Secure menu on top.
      MvcClient Secure Menu
      MvcClient Secure Menu
    2. Since there is no user authenticated, it will navigate to the IdentityServer with specific URL on http://localhost:5000/Account/Login in order to authenticate. Use Username bob and Password password. Press Login.
      IdentityServer Credentials
      IdentityServer Credentials
    3. The IdentityServer will then request your permission, press Yes, Allow.
      IdentityServer Permission Request
      IdentityServer Permission Request
    4. IdentityServer will now navigate back, authenticated to http://localhost:5002/Home/Secure and display information about the authenticated user.

 References:

 

Comments