Tag: identityserver4

如何在ASP.NET标识中使用ASP.NET成员资格数据库?

我有几个遗留的ASP.NET Web应用程序共享ASP.NET成员资格的数据库。 我想转向使用.NET Core和IdentityServer4的微服务架构,并在新的微服务生态系统中使用身份服务器来使用现有的ASP.NET Membership用户存储,但.NET Core似乎不支持ASP.NET Membership所有。 我目前有一个概念证据,涉及Web API,身份服务器和MVC Web应用程序作为我的客户端。 身份服务器实现IdentityUser的子类,并实现IUserStore / IUserPasswordStore / IUserEmailStore以使其适应我现有数据库中的ASP.NET Membership表。 我可以注册新用户并通过我的POC MVC客户端应用程序登录,但这些用户无法登录我的旧应用程序。 相反,在旧版应用程序中注册的用户无法登录我的POC MVC客户端。 我假设它是因为我的IPasswordHasher实现并没有像我的遗留应用程序中的ASP.NET成员资格一样散列密码。 以下是我的代码。 任何洞察我可能做错的事情都将非常感激。 安全和加密不是我的强项。 Startup.cs public class Startup { public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile(“appsettings.json”, optional: false, reloadOnChange: true) .AddJsonFile($”appsettings.{env.EnvironmentName}.json”, optional: true); if (env.IsDevelopment()) { // For more details on […]

使用授权中间件而不是AuthorizationAttribute ASPNET Core

我有一个专用的IdServer运行,它有一个登录页面,其他应用程序将启动未经身份validation的用户。 我目前的管道是: app.UseCookieAuthentication app.UseOpenIdConnectAuthentication app.UseDefaultFiles // because it is a SPA app app.UseStaticFiles // the SPA app 所以所有教程都说要在你的控制器上使用[Authorize] …… 但是,我希望中间授权我的所有控制器和静态文件。 那么我该如何编写一个中间件来处理它呢。 我目前的设置是: public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions identityServerAppOptions) { loggerFactory.AddConsole(Configuration.GetSection(“Logging”)); loggerFactory.AddDebug(); var serverAppOptions = identityServerAppOptions.Value; loggerFactory.CreateLogger(“Configure”).LogDebug(“Identity Server Authority Configured: {0}”, serverAppOptions.Authority); JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = “Cookies” }); app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions […]

如何在IdentityServer 4中使用’refresh_token’?

我正在使用.net核心与IdentityServer 4.我有一个Web api,以及一个访问api上安全端点的MVC应用程序。 它与IdentityServer快速入门的设置非常相似: https://github.com/IdentityServer/IdentityServer4.Samples/tree/release/Quickstarts/6_AspNetIdentity 我发现我的access_tokens即将到期,我想了解如何重新协商refresh_tokens 。 以下面的代码为例(摘自此处的快速入门): public async Task CallApiUsingUserAccessToken() { var accessToken = await HttpContext.Authentication.GetTokenAsync(“access_token”); var client = new HttpClient(); client.SetBearerToken(accessToken); var content = await client.GetStringAsync(“http://localhost:5001/identity”); ViewBag.Json = JArray.Parse(content).ToString(); return View(“json”); } 如果access_token已过期,它将失败并返回401响应。 是否有使用refresh_token重新协商access_token的内置机制?

ASP.NET Identity(使用IdentityServer4)获取外部资源oauth访问令牌

我已经浏览了identityServer4的文档,我已将其设置为使用Microsoft Office 365作为登录提供程序。 当用户登录时,我想创建一个按钮,他可以让我的应用程序使用graph.microsoft.com的webhooks api订阅他的日历事件 startup.cs中的代码 app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions { AuthenticationScheme = “Microsoft”, DisplayName = “Microsoft”, SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme, ClientId = “CLIENT ID”, ClientSecret = “CLIENT SECRET”, CallbackPath = new PathString(“/signin-microsoft”), Events = new OAuthEvents { OnCreatingTicket = context => { redisCache.Set(“AccessToken”, context.AccessToken.GetBytes(), new DistributedCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.UtcNow.AddDays(3) }); return Task.FromResult(context); } } Scope = […]

如何在IdentityServer4中添加自定义声明来访问令牌?

我正在使用IdentityServer4 。 我想添加其他自定义声明来访问令牌,但我无法做到这一点。 我修改了Quickstart5,并按照下面的Coemgen的建议,通过ProfileService添加了ASP.NET Identity Core和自定义声明。 你可以在这里下载我的代码:[zip package] [3]。 (它基于:带有ASP.NET Identity Core的Quickstart5和通过ProfileService添加的声明)。 问题:GetProfileDataAsync未执行。

拦截asp.net核心授权操作以在成功授权后执行自定义操作

我的网络应用控制器上有[授权]属性,因此任何端点命中都会确保用户首先被重定向到登录OAuth服务器(如果尚未登录)。 我现在想要在用户每次登录时开始将用户声明写入Web应用程序数据库。为此,我需要在每次用户成功登录/授权时在Web应用程序上运行一些代码。 我得到了一个线索,它涉及添加自定义中间件。 我的启动ConfigureServices代码目前如下: public class Startup { public Startup(IConfiguration configuration, IHostingEnvironment env) { Configuration = configuration; Env = env; } public IHostingEnvironment Env { get; } public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // Adds a default in-memory implementation of IDistributedCache. services.AddDistributedMemoryCache(); services.AddSession(options => { options.Cookie.HttpOnly = true; }); […]

Identity Server 4授权代码流示例

我正在尝试使用授权代码流实现带有AspNet Core的Identity Server 4。 问题是,github上的IdentityServer4存储库有几个样本,但没有一个带有授权代码流 。 有没有人有关于如何使用Identity Server 4和MVC中的客户端实现授权代码流的示例?