Я пытаюсь в данный момент войти в систему как пользователь в IdentityServer4 из моего приложения веб-форм Asp.Net.
Поскольку нет примера для проекта WebForms, я использую пример из IdentityServer3, предоставленный в GitHub repoIdentityServer
Вот проект client config in IdentityServer4
new Client
{
ClientId = "Foo",
ClientName = "Foo",
ClientSecrets =
{
new Secret("Secret".Sha256())
},
AllowedGrantTypes = GrantTypes.Implicit,
AllowOfflineAccess = true,
RequirePkce = false,
RequireClientSecret = false,
RequireConsent = false,
RedirectUris = redirectUris,
PostLogoutRedirectUris = postLogoutRedirectUris,
BackChannelLogoutUri = "https://localhost/LogOff",
AllowedCorsOrigins = allowedCorsOrigins,
AlwaysIncludeUserClaimsInIdToken = true,
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.OfflineAccess,
"firstName",
"lastName",
"emailId",
"api1"
}
}
Вот класс запуска в проекте веб-форм Asp.Net
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = "Cookies",
ExpireTimeSpan = TimeSpan.FromMinutes(10),
SlidingExpiration = true
});
var tokenHandler = new JwtSecurityTokenHandler();
tokenHandler.InboundClaimFilter.Clear();
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
AuthenticationType = "oidc",
SignInAsAuthenticationType = "Cookies",
Authority = "https://localhost:44367",
ClientId = "Foo",
RedirectUri = "https://localhost/callback",
PostLogoutRedirectUri = "https://localhost/LogOff",
ResponseType = "id_token token",
Scope = "openid profile emailId",
UseTokenLifetime = false,
Notifications = new OpenIdConnectAuthenticationNotifications
{
SecurityTokenValidated = async n =>
{
var claims_to_exclude = new[]
{
"aud", "iss", "nbf", "exp", "nonce", "iat", "at_hash"
};
var claims_to_keep =
n.AuthenticationTicket.Identity.Claims.Where(x => false == claims_to_exclude.Contains(x.Type)).ToList();
claims_to_keep.Add(new Claim("id_token", n.ProtocolMessage.IdToken));
if (n.ProtocolMessage.AccessToken != null)
{
claims_to_keep.Add(new Claim("access_token", n.ProtocolMessage.AccessToken));
var userInfoClient = new UserInfoClient(EP_Configuration.epIdpUserInfoAccessPoint);
var userInfoResponse = await userInfoClient.GetAsync(n.ProtocolMessage.AccessToken);
var userInfoClaims = userInfoResponse.Claims; // filter sub since we're already getting it from id_token
claims_to_keep.AddRange(userInfoClaims);
}
var ci = new ClaimsIdentity(
n.AuthenticationTicket.Identity.AuthenticationType);
ci.AddClaims(claims_to_keep);
n.AuthenticationTicket = new Microsoft.Owin.Security.AuthenticationTicket(
ci, n.AuthenticationTicket.Properties
);
},
RedirectToIdentityProvider = n =>
{
if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.Logout)
{
var id_token = n.OwinContext.Authentication.User.FindFirst("id_token")?.Value;
n.ProtocolMessage.IdTokenHint = id_token;
}
return Task.FromResult(0);
}
}
});
app.UseStageMarker(PipelineStage.Authenticate);
}
}
ПользовательloggedIn, в IdentityServer, как показано на изображении ниже,
Но Currentuser, похоже, не получает никаких претензий, и IsAuthenticated имеет значение false
void Application_PostAcquireRequestState(object sender, EventArgs e)
{
// now you can fix up you session object from
// if you use session state (which makes me sad if you do)
var cp = (ClaimsPrincipal)HttpContext.Current.User;
}
Любая идея, как сделать так, чтобы мой стартап работал и как в данный момент войти в систему Пользователь в IdentityServer в проекте веб-форм Asp.Net со стороны сервера.
PS: похоже, клиент WebForm вообще не вызывает IdentityServer.Файл журнала сервера идентификации не содержит обновлений при запуске клиентского приложения
. Здесь находится файл журнала IdentityServer
2019-06-03 16:36:05.074 +02:00 [INF] Starting IdentityServer4 version 2.3.2.0
2019-06-03 16:36:05.119 +02:00 [INF] You are using the in-memory version of the persisted grant store. This will store consent decisions, authorization codes, refresh and reference tokens in memory only. If you are using any of those features in production, you want to switch to a different store implementation.
2019-06-03 16:36:05.126 +02:00 [INF] Using the default authentication scheme idsrv for IdentityServer
2019-06-03 16:36:05.126 +02:00 [DBG] Using idsrv as default ASP.NET Core scheme for authentication
2019-06-03 16:36:05.126 +02:00 [DBG] Using idsrv as default ASP.NET Core scheme for sign-in
2019-06-03 16:36:05.126 +02:00 [DBG] Using idsrv as default ASP.NET Core scheme for sign-out
2019-06-03 16:36:05.126 +02:00 [DBG] Using idsrv as default ASP.NET Core scheme for challenge
2019-06-03 16:36:05.126 +02:00 [DBG] Using idsrv as default ASP.NET Core scheme for forbid
2019-06-03 16:36:05.437 +02:00 [DBG] Login Url: /Account/Login
2019-06-03 16:36:05.438 +02:00 [DBG] Login Return Url Parameter: ReturnUrl
2019-06-03 16:36:05.439 +02:00 [DBG] Logout Url: /Account/Logout
2019-06-03 16:36:05.439 +02:00 [DBG] ConsentUrl Url: /consent
2019-06-03 16:36:05.439 +02:00 [DBG] Consent Return Url Parameter: returnUrl
2019-06-03 16:36:05.439 +02:00 [DBG] Error Url: /home/error
2019-06-03 16:36:05.439 +02:00 [DBG] Error Id Parameter: errorId
.