我想从数据库读取范围和客户端,而不是 Identity Server 4 中的 InMemoryClients 和 InMemoryScopes。我读了问题,但它是关于身份版本 3 的,我找不到IScopeStorev3IClientStore中存在的接口。我该怎么做?
我正在使用 IdentityServer4 提供的示例应用程序: Quickstart6_AspNetIdentity.sln 使用 ro.client,我可以获得令牌。
但是当我使用相同的令牌获取用户信息时,我在同一个示例中收到 403 Forbidden 错误。按原样使用样品。不知道是bug 还是参数中遗漏了什么。遵循文档中提到的所有参数:https : //identityserver4.readthedocs.io/en/release/endpoints/userinfo.html
我使用身份服务器 4 进行身份验证,使用授权类型为“ResourceOwnerPassword”。我能够对用户进行身份验证,但无法获得与用户相关的声明。那么我怎样才能得到那些呢?
下面是我的代码
客户
启动文件
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = "http://localhost:5000",
RequireHttpsMetadata = false,
ApiName = "api1"
});
Run Code Online (Sandbox Code Playgroud)
控制器
public async Task<IActionResult> Authentication(LoginViewModel model)
{
var disco = await DiscoveryClient.GetAsync("http://localhost:5000");
// request token
var tokenClient = new TokenClient(disco.TokenEndpoint, "ro.client", "secret");
var tokenResponse = await tokenClient.RequestResourceOwnerPasswordAsync(model.Email, model.Password, "api1");
if (tokenResponse.IsError)
{
Console.WriteLine(tokenResponse.Error);
}
// Here I am not getting the claims, it is coming Forbidden
var extraClaims = new UserInfoClient(disco.UserInfoEndpoint);
var identityClaims = await extraClaims.GetAsync(tokenResponse.AccessToken);
if (!tokenResponse.IsError)
{
Console.WriteLine(identityClaims.Json);
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试向 IdentityServer4 添加 WSFederation 身份验证提供程序。最近Microsoft.AspNetCore.Authentication.WsFederation Preview 2发布了,我能够将它添加到普通的 Asp.NetCore 应用程序中。
但是我很难将它添加到IdentityServer4 EntityFramework-Quickstart-Example 中。
这就是我在 Startup.cs/ConfigureServices-method 中添加 AuthenticationProvider 的方式:
services.AddAuthentication()
.AddWsFederation("WsFederation", options =>
{
options.Wtrealm = realm;
options.MetadataAddress = metadata;
})
Run Code Online (Sandbox Code Playgroud)
我在前端获得了 WSFederation 按钮,我也可以登录。但是在回调之后我收到这个错误:
InvalidOperationException:子声明缺少 IdentityServer4.Hosting.IdentityServerAuthenticationService.AssertRequiredClaims(ClaimsPrincipal principal)
我可以理解这是从哪里来的,它是IdentityServer4 的 IdentityServerAuthenticationService.cs 中的这一行,它需要一个“子”声明——WSFed 不会返回这样的声明:
if (principal.FindFirst(JwtClaimTypes.Subject) == null) throw new InvalidOperationException("sub claim is missing");
Run Code Online (Sandbox Code Playgroud)
据我所知,我无法配置此声明,尽管快速入门项目中有一些表似乎可以用于此目的,尤其是那些 2:

我已经尝试将我想使用的声明而不是主题声明添加到表中,但它似乎没有任何影响,我也不知道数据库如何映射到我在代码中添加的身份提供者. 我很乐意为您提供有关后续步骤的任何提示,或者如果您知道任何示例,那就更好了。
PS:已经有一些关于这个主题的问题,但它们都是在 .Net Core 实现 WSFederation 之前可用的,或者参考 WSFederation 服务器的示例,而不是客户端。
我是编写 C# Api 的新手,正在查看 IdentityServer4 QuickStart1 我发现 QuickstartIdentityServer 模块具有
using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace QuickstartIdentityServer
{
public class Program
{
public static void Main(string[] args)
{
Console.Title = "IdentityServer";
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}
Run Code Online (Sandbox Code Playgroud)
并且API有
using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
namespace Api
{
public class Program
{
public static void Main(string[] args)
{
Console.Title = "API";
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
} …Run Code Online (Sandbox Code Playgroud) 我想login_hint在重定向到 Azure AD 时附加一个参数。原因是我已经知道用户名,不想让用户再次指定它。
在 Identity Server 中,我们像这样设置身份提供者:
services.AddAuthentication()
.AddOpenIdConnect()
Run Code Online (Sandbox Code Playgroud)
从帐户控制器,我们可以通过调用以下方式向身份提供者挑战新登录:
var properties = this.signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl, userId);
return this.Challenge(properties, provider);
Run Code Online (Sandbox Code Playgroud)
但是,我们如何向提供者,更具体地说是将用户重定向到的 URL 中包含其他参数?有一个字典AuthenticationProperties,我们可以在其中添加任意数据,所以我想我们可以在用户被重定向之前在某个地方使用这些数据。
我知道协议消息中有whrand domain_hint(有点类似于我想要实现的)属性,但是我们可以在何时何地访问这些或在管道中添加自定义参数?
作为学校作业,我必须做以下事情:
创建一个执行以下操作的React SPA:
使用带有PKCE的授权代码流对(欢迎使用IdentityServer4演示站点)进行身份验证
使用正确的令牌调用(测试)
在React中创建一个SPA 。这次必须使用React。
添加一个向SPA添加OIDC协议支持的库。确保支持带有PKCE的授权代码流
使用(欢迎使用IdentityServer4演示站点)作为授权服务器。该授权服务器通过PKCE支持授权代码流
使用正确的令牌调用(测试)并将结果显示给用户
在Netlify上托管react应用
作为该领域的初学者,我完全不理解作业。有人可以帮我吗?
single-page-application reactjs openid-connect identityserver4 pkce
使用 .NET Core 3.1 框架,我尝试使用以下设置配置 Web 平台:
所有这三个组件(Razor Pages + Angular + Identity Server)都捆绑到一个 .NET Core Web 项目中。我还搭建了 Identity 框架,以便能够自定义页面的外观和行为。
我几乎能够按照我想要的方式配置应用程序,方法是基本上混合 Razor Pages 选项的启动模板代码(用户帐户存储在本地)和 Angular 模板选项(用户帐户存储在本地)以及一些尝试、错误和调查。
我的申请目前的状态是:
本地主机:5001/Dashboard(Angular SPA 主路由)
/Identity(仅用于带有身份的页面),则 cookie 似乎不再包含正确的信息,并且我在这些路由中没有会话。这意味着,例如,如果我使用SignInManager.IsSignedIn(User)仅显示受 保护的管理页面的导航选项options.Conventions.AuthorizePage($"/Administration"),如果我位于具有身份路由的 URL 中,则将显示导航选项卡,否则将显示不显示:本地主机:5001/身份/帐户/登录
localhost:5001(Razor Pages 应用程序主路由)
asp.net-identity openid-connect .net-core asp.net-core identityserver4
我有一个 Vue 应用程序,我试图在其中设置静默令牌更新。
我的 Oidc 配置如下所示:
var mgr = new Oidc.UserManager({
authority: process.env.VUE_APP_IDENTITY_URL,
client_id: process.env.VUE_APP_CLIENT_ID,
redirect_uri: process.env.VUE_APP_REDIRECT_URI,
scope: 'openid profile',
response_type: 'id_token token',
silent_redirect_uri: process.env.VUE_APP_SILENT_REDIRECT_URI,
userStore: new Oidc.WebStorageStateStore({store: localStorage}),
automaticSilentRenew: true,
filterProtocolClaims: true,
loadUserInfo: true,
})
Run Code Online (Sandbox Code Playgroud)
我还有一个静态的silent-renew.html 页面:
<!DOCTYPE html>
<html>
<head>
<title>Silent Renew Token</title>
</head>
<body>
<script src='oidc-client.min.js'></script>
<script>
new Oidc.UserManager().signinSilentCallback().catch((err) => {
console.log(err);
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我加载应用程序时,静默更新只是无限循环:
我的访问令牌不会再过期一个小时,但它仍在触发事件,我无法深入了解。有谁知道还有什么可能导致这个循环?
javascript asp.net-identity vue.js identityserver4 oidc-client-js
我将Identityserver 4升级到1.5.1版,现在出现了内容安全策略错误。到目前为止,没有一个解决方案对我有用,我尝试过
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline' https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/css/bootstrap.min.css; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.min.js https://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js">
Run Code Online (Sandbox Code Playgroud)
但没有什么值得的
identityserver4 ×10
asp.net-core ×5
c# ×4
.net-core ×2
javascript ×1
oauth-2.0 ×1
pkce ×1
reactjs ×1
vue.js ×1