2

I need to customize the login views (login, logout, loggedout, error...) based on the clientID and select the look and feel dinamically (even, if possible, add behaviour). I've seen the IViewService interface and his implementation DefaultViewService in Identity Server 3. Link.

I have seen that this interface and its implementation have been eliminated in version 4.

What is the best way to proceed in the case of using Identity Server 4?

Some link with some practical example?

Edit: For NetCore 2.0 we can use the IViewLocationExpander interface. Thanks to this interface I have managed to change the search path of Razor views: https://stackoverflow.com/a/39490990/1201787

Alpha75
  • 2,140
  • 1
  • 26
  • 49

2 Answers2

1

Your easiest way (and may be the best approach) is - in the AccountController you have a method public async Task<IActionResult> Login(string returnUrl) (there is one more method called Login, but it is after the user submits his login credentials). In this method you call var vm = await accountService.BuildLoginViewModelAsync(returnUrl);.

The result of this is a LoginViewModel class which contains your Client Name (you can extend the class to include more things). And based on the name, you can return a different view from the controller for every different client, according to your needs.

EDIT

All this is if you use the quick starts - check here for more info.

m3n7alsnak3
  • 3,026
  • 1
  • 15
  • 24
0

IIdentityServerInteractionService.GetAuthorizationContextAsync(string) is your friend here.

It will give you the details of the current authorize request and from that you can discover the client ID and then use IClientStore.FindClientByIdAsync(string) to get the info you need.

mackie
  • 4,996
  • 1
  • 17
  • 17
  • That's fine, I will get the client. But now, how can I customize the view (eg Login.cshtml) based on that client? I want than every client will have a different look. By default, Identity Server load the same view for all of them. – Alpha75 Feb 02 '18 at 13:38
  • 1
    We're just talking about standard ASP.Net MVC here so it's entirely up to you how you implement custom views. IDS4 does not dicatate anything UI related. – mackie Feb 02 '18 at 16:40
  • 1
    Finally, I've created an implementation of IViewLocationExpander (available for netcore 2.0). In this implementation I can change the razor's views search path based on clientId. – Alpha75 Feb 04 '18 at 20:50