首页 > 解决方案 > 创建重定向到身份服务器登录页面的登录按钮

问题描述

我有一个 mvc 应用程序,它是客户端应用程序;然后我有一个身份服务器。

这是身份服务器的配置:

public static void AddIdentityServerContext(this IServiceCollection services, string connectionString)
{
    Microsoft.IdentityModel.Logging.IdentityModelEventSource.ShowPII = true; //Add this line

    services.AddIdentityServer(options =>
    {
        options.UserInteraction.LoginUrl = "/Signin/Identifier";
            
        ...
    })
    ...
}

这里是客户端应用程序的配置:

public void ConfigureServices(IServiceCollection services)
{
        ...

        .AddOpenIdConnect("oidc", options =>
        {
            options.Authority = "https://localhost:5001"; //IdentityServer

            options.ClientId = "mvc";
            options.ClientSecret = "secret";
            options.ResponseType = "code";

            options.SaveTokens = true; //SaveTokens is used to persist the tokens from IdentityServer in the cookie

            options.Scope.Add("api1");
            options.Scope.Add("offline_access");
            options.Scope.Add("email");
        });
}

现在在我的 MVC 客户端应用程序中,我想在身份服务器上的登录页面上创建一个登录按钮重定向,但我想避免在我的 cshtml 页面上以这种方式插入链接:

<a href= "https://localhost:5001/Signin/Identifier">Login</a>

我看到这个页面: https ://docs.identityserver.io/en/latest/quickstarts/4_javascript_client.html

我看到存在一些用于在基于 javascript 的应用程序上支持 oidc 协议的js 。我想服务器端也可能存在某些东西。

请问有什么帮助吗?

谢谢

标签: identityserver4openid-connect

解决方案


推荐阅读