IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

Possible to display ClientName instead of ClientId after user is Logged Out?

Open kenneth-y opened this issue 9 years ago • 12 comments

Hi,

I am using IdentityServer4 including the QuickStart UI from the IDSRV4 repo.

I can successfully connect my MVC App to IdentityServer using hybrid flow but I noticed one thing when I logged out of the application. In the IdentityServer4 LoggedOutView it is showing my ClientId (used to connect MVC app to IDSRV4) instead of the client name.

image

Is it possible to display the ClientName instead of the ClientId? I find ClientName more applicable to be displayed on the LoggedOut page.

Greatly appreciate for your inputs. Thanks.

IDSRV4 log snippet

image

IDSRV4 Client and MVC Client Configuration

new Client
{
    ClientId = "mvc-client",
    ClientName = "MVC Client",
    AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,

    ClientSecrets =
    {
        new Secret("secret".Sha256())
    },

    RedirectUris           = { "http://localhost:40078/signin-oidc" },
    PostLogoutRedirectUris = { "http://localhost:40078/signout-callback-oidc" },

    AllowedScopes =
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        "api1"
    },
    AllowOfflineAccess = true
};

// MVC Client
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
	AuthenticationScheme = "oidc",
	SignInScheme = "Cookies",
	Authority = "http://localhost:5000",
	RequireHttpsMetadata = false,
	ClientId = "mvc-client",
	ClientSecret = "secret",
	ResponseType = "code id_token",
	Scope = { "api1" },
	GetClaimsFromUserInfoEndpoint = true,
	SaveTokens = true,
	TokenValidationParameters = new TokenValidationParameters
	{
		NameClaimType = "name"
	}
});

kenneth-y avatar May 05 '17 02:05 kenneth-y

It is up to you to create the UI you want in the Identityserver. The repository contains just a sample implementation for the UI.

The LoggedOutViewModel has a property ClientName so you can change the ClientId to that.

<div>
    <p>
        Click <a class="btn btn-default" href="@Model.PostLogoutRedirectUri">here</a> to return to the
        <span>@Model.ClientName</span> application.
    </p>
</div>

user1336 avatar May 05 '17 06:05 user1336

thanks for the reply @user1336. i do know we have full control on the UI we want for IDSRV.

i have been checking the code in the AccountService.BuildLoggedOutViewModel() method but it seems the LogoutRequest (logout context returned) does not have the ClientName property. So I still could not set the value of the ClientName property in the LoggedOutViewModel.

do correct me if i am wrong.

image

above code snippet for LogoutMessage (parent class of LogoutRequest) does not have a ClientName property.

image

kenneth-y avatar May 05 '17 07:05 kenneth-y

If only there were a way to map clientId to a client.... hmmmm!

https://github.com/IdentityServer/IdentityServer4.Samples/blob/release/Quickstarts/8_EntityFrameworkStorage/src/QuickstartIdentityServer/Quickstart/Account/AccountService.cs#L73

Pretty sure this will point you in the right direction!

Mardoxx avatar May 05 '17 08:05 Mardoxx

Yes, what @Mardoxx said.

brockallen avatar May 05 '17 12:05 brockallen

thanks @Mardoxx @brockallen. I thought ClientName would be returned via the logoutcontext. no further questions from this issue.

kenneth-y avatar May 08 '17 01:05 kenneth-y

Sorry to reopen it, I have the same question. What is the solution now to show the Client Name in the UI.

LoggedOutViewModel is built from the LogoutMessage.

Why can't the LogoutMessasge have also the ClientName like this:


        public LogoutMessage(ValidatedEndSessionRequest request)
        {
            if (request != null)
            {
                Parameters = request.Raw;
                ClientId = request.Client?.ClientId;
                **ClientName= request.Client?.ClientName;**

LoggedOutViewModel will use the ClientName instead of ClientId:

           var vm = new LoggedOutViewModel
            {
                AutomaticRedirectAfterSignOut = AccountOptions.AutomaticRedirectAfterSignOut,
                PostLogoutRedirectUri = logout?.PostLogoutRedirectUri,
                **ClientName = logout?.ClientName**,
                SignOutIframeUrl = logout?.SignOutIFrameUrl,
                LogoutId = logoutId
            };

kevinlo avatar Dec 15 '17 21:12 kevinlo

@kevinlo send a PR please.

brockallen avatar Dec 15 '17 21:12 brockallen

@brockallen Ok. If you feel that is the right way, I'll do it, but maybe next week.

kevinlo avatar Dec 15 '17 22:12 kevinlo

@brockallen I just read about #231, you suggested to

inject the IClientStore into your controller, and then lookup the Client configuration (and thus the name) from the ClientId passed via the context.

That works for me. I don't need to add the ClientName to the LogoutMessage unless you feel that is a better way.

kevinlo avatar Dec 18 '17 22:12 kevinlo

Like I said, feel free to submit a PR if you think it helps improve the OSS code.

brockallen avatar Dec 19 '17 00:12 brockallen

Just submit the pull request #1893

kevinlo avatar Dec 20 '17 06:12 kevinlo

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 13 '20 22:01 lock[bot]