我有一个身份服务器(带有身份服务器 4 2.0.0 的 ASP.NET Core 2)配置为使用 Kestrel 和 IISIntegration,在 launchSettings.json 上启用了匿名和 Windows 身份验证。我还像这样配置了 IISOptions:
services.Configure<IISOptions>(iis =>
{
iis.AutomaticAuthentication = false;
iis.AuthenticationDisplayName = "Windows";
});
services.AddAuthentication();
services.AddCors()
.AddMvc();
services.AddIdentityServer(); // with AspNetIdentity configured
app.UseAuthentication()
.UseIdentityServer()
.UseStaticFiles()
.UseCors(options => options.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin())
.UseMvcWithDefaultRoute();
Run Code Online (Sandbox Code Playgroud)
我有这个客户端(也是启用了 Windows 和匿名身份验证的 ASP.NET Core 2,在带有 IISIntegration 的 Kestrel 上运行)
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddOpenIdConnect(config =>
{
config.Authority = "http://localhost:5000";
config.RequireHttpsMetadata = false;
config.ClientId = "MyClientId";
config.ClientSecret = "MyClientSecret";
config.SaveTokens = true;
config.GetClaimsFromUserInfoEndpoint = true;
});
services.AddMvc();
Run Code Online (Sandbox Code Playgroud)
身份服务器在http://localhost:5000上运行,客户端在http://localhost:2040 上运行。 …
c# windows-authentication openid-connect asp.net-core identityserver4
我正在使用 oidc-client-js 库与 IdentityServer3 一起工作,它运行良好,但每次 oidc-client-js 尝试更新令牌时我无法设置自动“无声令牌更新”我在控制台中收到错误
拒绝在框架中显示“ https://identity.blablabla.com/core/connect/authorize?client_id= ...”,因为它将“X-Frame-Options”设置为“sameorigin”。
我用于测试来自 oidc github 的 angular2 应用程序,在应用程序尝试更新令牌的那一刻有错误的屏幕截图 在 此处输入图像描述
我知道这是身份服务器安全性的一部分,以防止在 iframe 中打开其页面,但在这种情况下,oidc-client-js 无法使用IdentityServer3进行静默令牌更新。可能有人有这个问题的经验,可以帮助解决它?
在 OAuth2 协议中,客户端(OIDC 中的 RP)应用程序获取访问令牌,这使其能够代表Resource Owner使用不同的服务(资源服务器角色)。
另一方面,在 OpenID Connect 协议中,Client获得 2 个令牌(access 和 id 令牌)。现在此客户端可以使用访问令牌从 UserInfo 端点获取用户声明。
我已经阅读了这里关于状态和现时参数之间的区别以及据我了解状态参数由身份验证服务器(身份服务器)生成并由客户端用于防止 CSRF 攻击,而现时参数由客户端生成然后身份验证服务器将其包含在令牌中,客户端将使用它来检查令牌有效性。
我的第一个问题是:在使用隐式授权类型时,在 identityServer4 的情况下,上述流程是否正确?
我的第二个问题:nonce参数存储在用户代理(浏览器)的何处,客户端如何生成和传输它?
我的第三个问题:客户端如何交叉检查状态参数是否有效?
在当前的 ASP.NET Core 项目 ( v2.1.6) 中,Identity Server 4 ( v2.2.0) 是为用户和 API 身份验证而实现的,它的工作原理非常棒。唯一grant_type被设置为客户端是client-credentials和scopes被设置到一些自定义范围offline_access是不容许。
访问后.well-known/openid-configuration发现支持的范围grant_types比指定的多,offline_access即使它被禁用(为简洁起见缩短)也是支持的范围:
{
"scopes_supported": [
"custom_scope_1",
"custom_scope_2",
"offline_access"
],
"grant_types_supported": [
"authorization_code",
"client_credentials",
"refresh_token",
"implicit",
"password"
],
}
Run Code Online (Sandbox Code Playgroud)
IdentityServer4的文档但找不到如何设置这样一个选项的线索。我偶然发现了一个可能较旧的文档,但这似乎不是当前版本的一部分。
是否有可能在我刚刚错过的配置期间明确定义支持的授权类型?还是自动生成的,根本无法设置?
I have configured a user my_user who belongs to my_group in Keycloak 4.8.3. I have then obtained an id token for it with grant type Resource Owner Password Credentials (ROPC). When I inspect the issued id token with a tool such as jwt.io I can see that the user's id and name are included as JWT clains sub and preferred_username respectively.
But where does group membership show up inside the JWT?
我正在尝试使用 Identity Server 4 中的 API 资源,并认为一定有我不理解的地方。
我有一个 SPA 客户端应用程序,它需要通过 IdP 对用户进行身份验证,然后代表该用户向 API 资源发出授权请求。API 没有作用域,所以我在 Identity Server 中定义了一些与 API 资源相关的 API 声明,但没有费心为此资源定义任何作用域或作用域声明。
但是,我现在对如何请求访问此 API 资源作为 OIDC 流程的一部分感到困惑。通常我会在授权请求中使用范围,但在这种情况下我没有范围可以使用。所以在我的 实现中IProfileService,当我构建返回的声明时,它context.RequestedResources.ApiResources是空的。
那么,请求提供对无作用域 API 资源的访问的令牌的正确流程是什么?我很确定我在这里遗漏了一些基本的知识,我将摆脱这种谦虚和愚蠢的态度。但是他们说没有愚蠢的问题,对吧?
人们,
您能否为我澄清这两种方法的区别和目的:
根据名称一个是用来授权的,另一个是用来验证用户的,对吧?因此,如果我的 mvc 应用程序需要知道我需要使用谁来.AddOpenIdConnect()获取用户id_token?如果我需要代表当前用户从 mvc 应用程序调用资源服务,我需要添加.AddOAuth()以获得access_token?
auth0.com 的实验表明,代码 with.AddOAuth()能够获得访问令牌作为 的结果HttpContext.GetTokenAsync("access_token"),但如果HttpContext.GetTokenAsync("id_token").
反之亦然 -.AddOpenIdConnect()可以获得 id_token,但不能获得 access_token。
两者的配置是相等的:
.AddOAuth("oauth", o =>
{
o.AuthorizationEndpoint = "https://<Realm>.auth0.com/authorize?audience=resourceAPI-server";
o.TokenEndpoint = "https://<REALM>.auth0.com/oauth/token";
o.ClientId = "<clientID>";
o.ClientSecret = "<secret>";
o.CallbackPath = "/cb_oauth";
o.SaveTokens = true;
})
.AddOpenIdConnect("openIdConnect", o =>
{
o.Authority = "https://<REALM>.auth0.com";
o.ClientId = "<clientID>";
o.ClientSecret = "<secret>";
o.CallbackPath = "/cb_openIdConnect";
o.SaveTokens = true;
o.Events =new OpenIdConnectEvents()
{ …Run Code Online (Sandbox Code Playgroud) 我有这个控制器
[Route("Authentication")]
public class AuthenticationController : Controller
{
Run Code Online (Sandbox Code Playgroud)
而这个动作
[HttpGet("SignOut")]
public async Task<IActionResult> SignOut([FromQuery] string sid)
{
await ControllerContext.HttpContext.SignOutAsync(Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectDefaults.AuthenticationScheme);
await ControllerContext.HttpContext.SignOutAsync(Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationDefaults.AuthenticationScheme);
return View();
Run Code Online (Sandbox Code Playgroud)
这按预期工作。
但是,当我为具有相同路由的 OpenId 身份验证配置 SignedOutCallbackPath 时,它不再起作用。我的控制器的构造函数没有被调用,动作没有被点击,浏览器中的结果是一个空白页面(代码 200),带有 html/head/body,但都是空的,不匹配任何模板或视图。
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.Cookie.HttpOnly = true;
})
.AddOpenIdConnect(options =>
{
options.SignedOutCallbackPath = "/Authentication/SignOut";
Run Code Online (Sandbox Code Playgroud)
SignedOutCallbackPath 不应该是我自己的视图吗?
我在身份服务器 4 中使用 OIDC 客户端 JS,反应不断收到错误
Client secret validation failed for client, Invalid client secret
关于授权码流程,
Oidc设置
private getClientSettings(): any {
return {
authority: "https://localhost:5001",
client_id: "Local",
redirect_uri: "https://localhost:5001/auth-callback",
post_logout_redirect_uri: "https://localhost:5001",
response_type: "code",
scope: "profile openid email IdentityPortal.API offline_access",
//filterProtocolClaims: environment.openID.filterProtocolClaims,
loadUserInfo: true,
monitorSession: true,
silent_redirect_uri: "https://localhost:5001/silent-reniew.html",
accessTokenExpiringNotificationTime: 20, //default 60
checkSessionInterval: 5000, //default 2000
silentRequestTimeout: 2000,
};
}
Run Code Online (Sandbox Code Playgroud)
身份服务器 4 配置
public static IEnumerable<Client> GetClients()
{
// client credentials client
return new List<Client>
{
new Client
{
ClientId = …Run Code Online (Sandbox Code Playgroud) asp.net reactjs openid-connect identityserver4 oidc-client-js
openid-connect ×10
asp.net-core ×4
oauth-2.0 ×3
asp.net ×2
angular ×1
asp.net-mvc ×1
c# ×1
jwt ×1
keycloak ×1
openid ×1
reactjs ×1