我正在尝试找到一种适当的方法,在从 Azure Active Directory 等外部身份提供者成功进行身份验证后,我可以注入服务以验证用户是否存在或在我的应用程序中注册。如果他的帐户尚未在我的应用程序中注册,我想要做的是将用户重定向到自定义错误页面或显示未经授权的消息。
我尝试使用 IProfileService 接口,但似乎不是正确的方法。
这是我的 Startup.cs 设置:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services
.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddTestUsers(Config.GetUsers())
.AddInMemoryIdentityResources(Config.GetIdentityResources())
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients()) // Client was configured with RequireConsent = false, EnableLocalLogin = false,
.AddProfileService<ProfileService>()
.Services.AddTransient<IUserRepository,UserRepository>();
services.AddAuthentication()
.AddOpenIdConnect("AAD", "Azure Active Directory", options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.SignOutScheme = IdentityServerConstants.SignoutScheme;
options.Authority = "https://login.microsoftonline.com/MyTenant";
options.ClientId = "MyClientId";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = false
};
options.GetClaimsFromUserInfoEndpoint = true;
});
}
public class ProfileService : IProfileService
{
private readonly IUserRepository _userRepository;
public ProfileService(IUserRepository userRepository)
{
_userRepository = userRepository
}
是否有任何可用的服务或接口可以用来注入我的用户验证以及允许我在该服务中注入我的用户存储库?是否可以在 IdentityServer4 中注入这种进程?有人可以指出我使用 IdentityServer4 实现目标的正确方向吗?
注意:假设我有 SPA 网络应用程序,并且我有自己的单独注册机制。如果用户不存在,我不想重定向回我的 SPA,而是在 IdentityServer4 中处理它。顺便说一句,为简洁起见,上面的一些代码不包括在内。
叮当猫咪
潇湘沐
回首忆惘然
随时随地看视频慕课网APP
相关分类