Implement OpenID connect Authetication in asp.net WEB API

人盡茶涼 提交于 2019-12-20 07:40:46

问题


This is the Project Structure

This is the access_token I am getting in My Angular Client Application.

{
  "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"
  ]
}

In My ASP.NET WEB API Project, I am using this OPEN ID CONNECT Nuget Package - https://www.nuget.org/packages/Microsoft.Owin.Security.OpenIdConnect/

I have written the following code to validate the Token But I am getting 401. Please please help me. I am stuck like anything. :( Thanks in advance.

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"
                    }
                });
        }
    }

来源:https://stackoverflow.com/questions/50891611/implement-openid-connect-authetication-in-asp-net-web-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!