问题
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