如何调用 OWIN OpenID Connect 登录?

How is OWIN OpenID Connect Login called?

使用 OWIN 和 OpenID Connect,我很难理解我的代码是如何工作的。我从网上的样本中得到了这个。这是一个 .Net 4.7.2 应用程序。

相关OWIN启动代码:

     app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                ClientId = System.Configuration.ConfigurationManager.AppSettings["clientID"], 
                ClientSecret = System.Configuration.ConfigurationManager.AppSettings["clientSecret"],
                Authority = System.Configuration.ConfigurationManager.AppSettings["Authority"],
                RedirectUri = System.Configuration.ConfigurationManager.AppSettings["redirectURI"],


                Scope = System.Configuration.ConfigurationManager.AppSettings["scope"],
                CallbackPath = new Microsoft.Owin.PathString(System.Configuration.ConfigurationManager.AppSettings["callbackURL"]),
                RedeemCode = true,
                SaveTokens = true,
                ResponseType = OpenIdConnectResponseType.Code,
                ResponseMode = OpenIdConnectResponseMode.Query
 }

然后我有这个带有登录功能的索引页面:

<form method="post" action="">
    <div class="d-flex justify-content-center">
        @*<button class="btn btn-primary mx-2" formaction="/Home/Login">Please Login!</button>*@
        <input  class="btn btn-primary mx-2" type="button" value="Login for access..." onclick="location.href='@Url.Action("Login", "Home")'" />
    </div>

那么家庭控制器中的这个登录功能:

[Authorize]
    public ActionResult Login()
    {

        var user = User;
       

        //_Claims = ClaimsPrincipal.Current.Identities.First().Claims.ToList();

        string result = string.Empty;
        if (User.Identity.IsAuthenticated)
        {
            //do something
        }
    }

我的登录按钮以某种方式向我的身份提供者发出请求,一切正常。但是在哪里以及如何?我没有做任何事情来触发它。而且我不使用任何 Challenge() method/mechanism。有人可以解释或指出我对此的详细解释吗?提前致谢!

当授权处理程序发现具有 [Authorize] 属性且用户未登录(未通过身份验证)的控制器时,它会自动向身份验证模块发送质询。它会依次查看向其添加了哪些处理程序 (OpenIDConnect)。因此,它将自动联系您的身份提供者,要求用户进行身份验证。最终,身份验证处理程序从 IdentityServer 获得一个请求(通过浏览器),因此它可以 sign-in 用户。