标签: identityserver3

为什么 ASP.NET Core 在 User.Claims 属性中添加两次声明?

我有 asp.net core 应用程序,该应用程序正在使用 IdentityServer3 使用 OpenIdConnect 身份验证。当用户成功通过身份验证后,应用程序会从身份服务器收到正确的声明。我可以调试线路TokenValidatedContext.Ticket.Principal.ClaimsOnTokenValidatd确保应用程序收到所有声明。

代码片段

    var connectOptions = new OpenIdConnectOptions()
        {
            AutomaticAuthenticate = true,
            AutomaticChallenge = true,
            Authority = authority,
            ClientId = clientId,
            ResponseType = IdentityConstant.IdTokenClaim,
            AuthenticationScheme = IdentityConstant.OpenIdAuthenticationScheme,
            SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme,
            PostLogoutRedirectUri = postlogoutRedirectUri,
            CallbackPath = IdentityConstant.CallbackPath,
            Events = new OpenIdConnectEvents()
            {
                OnTokenValidated = async context =>
                {
                    var claims = context.Ticket.Principal.Claims;
                    await Task.FromResult(0);
                }
            }
        };
Run Code Online (Sandbox Code Playgroud)

下面是处理程序 TokenValidatedContext.Ticket.Principal.Claims中的快速观看OnTokenValidated

在此输入图像描述

但是,在家庭控制器中调试成功进行身份验证后User.Cliams,我看到所有声明都添加了两次。下面是Home控制器
的快速观看User.Claims

在此输入图像描述

为什么声明在 User.Claims 中添加两次?

asp.net-core-mvc coreclr identityserver3 asp.net-core

4
推荐指数
1
解决办法
1333
查看次数

UseJwtBearerAuthentication在令牌到期时返回HTTP 500

我正在使用像这样的UseJwtBearerAuthentication

app.UseJwtBearerAuthentication(options =>
{
   options.Authority = Configuration["Urls:IdentityServer"];
   options.RequireHttpsMetadata = false;

   options.Audience = Configuration["Urls:IdentityServer"] + "/resources";
   options.AutomaticAuthenticate = true;
   options.Events = new JwtBearerEvents
   {
        OnAuthenticationFailed = context =>
        {
          context.HandleResponse();   
          return Task.FromResult(0);
        }
   }; 
});
Run Code Online (Sandbox Code Playgroud)

在visual studio的诊断窗口中,我看到以下两个例外:

System.IdentityModel.Tokens.dll中的System.IdentityModel.Tokens.SecurityTokenExpiredException'("IDX10223:生命周期验证失败.令牌已过期.

并下线

抛出异常:Microsoft.AspNet.Authentication.dll中的"System.ArgumentNullException"("值不能为空.")

如何返回HTTP 401 Unauthorized?

asp.net-mvc jwt identityserver3 asp.net-core

3
推荐指数
1
解决办法
2868
查看次数

使用 web.config 授权元素时未触发 OWIN 质询

我正在将 Web 表单应用程序从表单身份验证迁移到 OpenID Connect(使用 OWIN 和 IdentityServer3)。该应用程序在 web.config 中已经有很多“授权”元素(针对不同位置),我想在迁移到 OWIN 后重用这些元素。

<authorization>
   <deny users="?" />
</authorization>
<location path="Path/Page.aspx">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>
...
Run Code Online (Sandbox Code Playgroud)

问题是,在我切换到 OWIN 而不是被重定向到登录页面后,我得到了 401(未经授权)。

目前,将用户重定向到登录页面的唯一方法是在 Page_Load 事件中手动进行质询:

if (!Request.IsAuthenticated)
{
   HttpContext.Current.GetOwinContext().Authentication.Challenge();
}
Run Code Online (Sandbox Code Playgroud)

这是我的 Startup.Auth 的样子:

public void ConfigureAuth(IAppBuilder app)
        {
            //reset the mapping dictionary to ensure the claims are not mapped to .NET standard claims
            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "ApplicationCookie",                    
                AuthenticationMode = AuthenticationMode.Active          
            });

            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions …
Run Code Online (Sandbox Code Playgroud)

c# asp.net owin asp.net-identity identityserver3

3
推荐指数
1
解决办法
1683
查看次数

来自POSTMAN Http Tool的Identity Server 3令牌请求

使用POSTMAN,我正在努力检索我的Identity Server 3令牌.

错误代码是: 400 Bad Request

以下是详细信息:

POST/identity/connect/token HTTP/1.1

Host:localhost:44358 Content-Type:应用程序; x-www-form-urlencoded

Cache-Control: 无缓存

Postman-Token: 57fc7aef-0006-81b2-8bf8-8d46b77d21d1

username= MYUSER-ID&password= MY-PASSWORD&grant_type= password&client_id= rzrwebguiangulajsclient&client_secret= myclientsecret&redirect_uri= https:// localhost:44331/callback

我用一个简单的Visual Studio 2015 WebApi项目做了类似的事情,其终点是\token.

在此输入图像描述

任何指导/建议表示赞赏......

问候,鲍勃

postman identityserver3

3
推荐指数
1
解决办法
9965
查看次数

'sub'声明是openid范围或配置文件范围的一部分吗?

根据OpenID Connect规范,sub声明是openid范围或profile范围的一部分?我找不到那些信息

Update1
我使用IdentityServer3进行身份验证.客户端正在向服务器发出请求,如下所示.作为回应,我没有sub按照Open ID Connect规范获得所需的声明.然而响应确实包括http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier具有作为相同的值sub是对nameidentifier相同sub要求.

这是客户要求

    public void Configuration(IAppBuilder app)
    {
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = "Cookies"
        });

        app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
        {
            Authority = "https://localhost:44314/identity",
            Scope = "openid",
            ClientId = "LocalHostMvcClient",
            RedirectUri = "http://localhost:34937/",
            ResponseType = "id_token",
            SignInAsAuthenticationType = "Cookies",
        }
   }
Run Code Online (Sandbox Code Playgroud)

id_token响应

在此输入图像描述


根据以下评论更新2我更新了客户端的启动文件

    private void TurnOffMicrosoftJWTMapping()
    {
        //The long claim names come from Microsoft’s JWT handler trying to map …
Run Code Online (Sandbox Code Playgroud)

openid-connect identityserver3

3
推荐指数
1
解决办法
4152
查看次数

如何向身份服务器本身发出访问令牌?

这可能是一个愚蠢的问题,但这里是:)

我在这个问题上有以下应用程序:

  • IdentityServer3
  • WebApi2应用程序,它使用Identityserver作为其身份验证器
  • MVC网络应用程序

我想要做的是从IdentityServer调用WebApi上的安全服务,但为了这样做,我需要一个访问令牌.

我如何在IdentityServer中向自己发出访问令牌(按顺序将通过WebApi自身进行身份验证)

c# identityserver3

3
推荐指数
1
解决办法
1404
查看次数

Identity Server身份验证,无需请求用户权限

有没有办法配置客户端以使其受信任,并且不需要用户批准访问其详细信息?

我正在构建一个Angular客户端应用程序,并使用Identity Server 3发出令牌以访问后端API,但是因为看起来您正在登录与您正在访问的API相同的环境,我不希望客户端成为提示输入此客户端应用程序/资源对的权限请求.目前我有类似于这个例子的东西:https: //damienbod.com/2015/11/08/oauth2-implicit-flow-with-angular-and-asp-net-5-identity-server/

是否有绕过批准的设置,或者我只是使用了错误的流程?

我想我正在寻找复制的例子是访问Auzure门户SPA.在那里,您被重定向到登录,然后Microsoft不会提示我访问Microsoft帐户详细信息.

oauth-2.0 angularjs identityserver3

3
推荐指数
1
解决办法
384
查看次数

从数据库而不是InMemoryClients和InMemoryScopes Identity Server 3获取范围和客户端

我想从数据库而不是Identity Server 3中的InMemoryClients和InMemoryScopes中读取范围和客户端.

任何人请帮助我如何阅读我们如何在身份服务器3中实现这一点.提前感谢.

identityserver3 identityserver4

3
推荐指数
1
解决办法
1625
查看次数

IdentityServer和ADFS

我正在尝试将IdentityServer设置为使用ADFS进行身份验证.流程将是:

用户 - >自定义应用程序 - > IS - > ADFS

我已经设置了几乎所有东西,但我仍然坚持IS和ADFS之间的通信.用户似乎在ADFS中成功登录,但是我收到错误:

ID4037:无法从以下安全密钥标识符'SecurityKeyIdentifier解析验证签名所需的密钥

当我回到IS.

显而易见,令牌签名证书在一方或另一方存在问题.我试图找到一些解释不同证书之间关系的文档,但没有成功.

现在我在IS中有自签名证书,签署令牌(使用IdentityServerOptions的SigningCertificate属性设置),我在ADFS中配置了AD证书来签署令牌.

有关如何正确地做到这一点的指导或建议吗?两者应该是相同的,还是应该配置其他东西以使其工作?

编辑 使用Fiddler我可以看到ADFS中的所有内容都运行良好,错误是将结果发布到IdentityServer时.在wresult param中发布的XML是:

<t:RequestSecurityTokenResponse xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
  <t:Lifetime>
    <wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2017-06-20T12:25:31.148Z</wsu:Created>
    <wsu:Expires xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2017-06-20T13:25:31.148Z</wsu:Expires>
  </t:Lifetime>
  <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
    <wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing">
      <wsa:Address>urn:identityServer</wsa:Address>
    </wsa:EndpointReference>
  </wsp:AppliesTo>
  <t:RequestedSecurityToken>
    <saml:Assertion MajorVersion="1" MinorVersion="1" AssertionID="_fd1a14cd-4d18-407b-97d4-9f9dfcacd29a" Issuer="http://ssosrv.mydomain.com/adfs/services/trust" IssueInstant="2017-06-20T12:25:31.148Z" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">
      <saml:Conditions NotBefore="2017-06-20T12:25:31.148Z" NotOnOrAfter="2017-06-20T13:25:31.148Z">
        <saml:AudienceRestrictionCondition>
          <saml:Audience>urn:identityServer</saml:Audience>
        </saml:AudienceRestrictionCondition>
      </saml:Conditions>
      <saml:AttributeStatement>
        <saml:Subject>
          <saml:NameIdentifier>user@mydomain.com</saml:NameIdentifier>
          <saml:SubjectConfirmation>
            <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod>
          </saml:SubjectConfirmation>
        </saml:Subject>
        <saml:Attribute AttributeName="emailaddress" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims">
          <saml:AttributeValue>name.surname@mydomain.tv</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute AttributeName="name" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims">
          <saml:AttributeValue>Name Surname</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute AttributeName="upn" AttributeNamespace="http://schemas.xmlsoap.org/ws/2005/05/identity/claims">
          <saml:AttributeValue>user@mydomain.com</saml:AttributeValue>
        </saml:Attribute>
      </saml:AttributeStatement>
      <saml:AuthenticationStatement AuthenticationMethod="urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport" AuthenticationInstant="2017-06-20T12:25:31.039Z">
        <saml:Subject>
          <saml:NameIdentifier>user@mydomain.com</saml:NameIdentifier>
          <saml:SubjectConfirmation>
            <saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod> …
Run Code Online (Sandbox Code Playgroud)

adfs active-directory single-sign-on identityserver3

3
推荐指数
1
解决办法
909
查看次数

IdentityServer3 PublicOrigin和IssuerUri在IdentityServerOptions中的区别和用法

部署到IIS时出现问题。显然,客户端使用反向代理,并且所有OpenId配置迪斯科显示IP地址而不是其域名。PublicOrigin解决了我的问题。但是,我仍然不了解两者之间的区别,

PublicOrigin
Run Code Online (Sandbox Code Playgroud)

IssuerUri
Run Code Online (Sandbox Code Playgroud)

范例:

var options = new IdentityServerOptions
{
    PublicOrigin = "https://myids/project1/",
    IssuerUri = "https://myids/project1/",
    ...
}
Run Code Online (Sandbox Code Playgroud)

我可以从迪斯科舞厅看到,如果两个值都分别更新,也显示出变化,即;

{
  "issuer": "https://myids/project1/",
  "jwks_uri": "https://myids/project1/.well-known/jwks",
  "authorization_endpoint": "https://myids/project1/connect/authorize",
  "token_endpoint": "https://myids/project1/connect/token",
  "userinfo_endpoint": "https://myids/project1/connect/userinfo",
  "end_session_endpoint": "https://myids/project1/connect/endsession",
  "check_session_iframe": "https://myids/project1/connect/checksession",
  "revocation_endpoint": "https://myids/project1/connect/revocation",
  "introspection_endpoint": "https://myids/project1/connect/introspect",
  ...
}
Run Code Online (Sandbox Code Playgroud)

and why not just make it the same as IssuerUri. I have read the documentation on this. Technically is just a description of the properties. I would like to understand more.

Many thanks.

identityserver3 identityserver4

3
推荐指数
1
解决办法
1399
查看次数