在asp.net WEB API中实现OpenID连接验证

时间:2018-06-16 20:45:57

标签: asp.net-mvc asp.net-web-api oauth-2.0 openid-connect owin-middleware

This is the Project Structure

这是我在My Angular Client Application中获得的 access_token



{
  "nbf": 1529181048,
  "exp": 1529184648,
  "iss": "https://localhost:44381",
  "aud": [
    "https://localhost:44381/resources",
    "myaspnetwebapi"
  ],
  "client_id": "AngularCore",
  "sub": "1",
  "auth_time": 1529181045,
  "idp": "local",
  "scope": [
    "openid",
    "profile",
    "myaspnetwebapi"
  ],
  "amr": [
    "pwd"
  ]
}




在我的ASP.NET WEB API项目中, 我正在使用这个OPEN ID CONNECT Nuget Package - https://www.nuget.org/packages/Microsoft.Owin.Security.OpenIdConnect/

我编写了以下代码来验证令牌但我得到的是401。 请帮帮我。我被困住了。 :( 提前致谢。

public partial class Startup
    {
        public void ConfigureAuth(IAppBuilder app)
        {
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(new CookieAuthenticationOptions());


            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {

                    ClientId = "AngularCore",
                    Authority = "https://localhost:44381",
                    TokenValidationParameters = new TokenValidationParameters()
                    {
                        ValidAudience = "myaspnetwebapi"
                    }
                });
        }
    }

0 个答案:

没有答案