请帮助我理解以下场景:
Web 应用程序正在从 STS 请求令牌。STS 是 Thinktecture Identity server v2。STS 配置如下:
webapplication 和 STS 都通过安装所需的证书建立了信任关系。
Web 应用程序使用 WS-Trust 协议使用以下代码请求令牌:
WSTrustChannelFactory factory = new WSTrustChannelFactory(new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential),
string.Format(WS_TRUST_END_POINT, identityServer));
string relyingParty = "urn:test:symmetric";
factory.TrustVersion = TrustVersion.WSTrust13;
factory.Credentials.UserName.UserName = username;
factory.Credentials.UserName.Password = password;
RequestSecurityToken rst = new RequestSecurityToken
{
RequestType = RequestTypes.Issue,
KeyType = KeyTypes.Bearer,
TokenType = TokenTypes.JsonWebToken,
AppliesTo = new EndpointReference(relyingParty),
};
GenericXmlSecurityToken xmlToken = factory.CreateChannel().Issue(rst) as GenericXmlSecurityToken;
handlers = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers;
SecurityTokenHandlerCollection jwtToken = handlers.ReadToken(new XmlTextReader(new StringReader(xmlToken.TokenXml.OuterXml))) as JwtSecurityToken;
var Identity = handlers.ValidateToken(jwtToken);
应用程序 web.config 如下所示:
<system.identityModel>
<identityConfiguration saveBootstrapContext="true">
<audienceUris>
<add value="urn:test:symmetric"/>
</audienceUris>
<securityTokenHandlers>
<add type="System.IdentityModel.Tokens.JwtSecurityTokenHandler, System.IdentityModel.Tokens.Jwt, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089">
<sessionTokenRequirement lifetime="00:30:00"/>
</add>
<securityTokenHandlerConfiguration>
<issuerTokenResolver type="System.IdentityModel.Tokens.NamedKeyIssuerTokenResolver, System.IdentityModel.Tokens.JWT">
<securityKey symmetricKey="JDQLsrFL1VGBj5GZcAo0Xick4stoHyV5ah0B8RDBUoM=" name="TH_STS"/>
</issuerTokenResolver>
<issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<!-- STS Authority Nodes
-->
<authority name="TH_STS">
<keys>
<add symmetricKey="JDQLsrFL1VGBj5GZcAo0Xick4stoHyV5ah0B8RDBUoM="/>
</keys>
<validIssuers>
<add name="TH_STS"/>
</validIssuers>
</authority>
</issuerNameRegistry>
</securityTokenHandlerConfiguration>
</securityTokenHandlers>
</identityConfiguration>
</system.identityModel>
我阅读了 WIF 概念,但我仍在努力理解流程。我是否正确理解以下内容:
- 令牌请求适用于 https。
- 通过安装适当的证书,在令牌请求者(Web 应用程序)和 STS 之间建立信任。
- Web 应用程序通过 WS-Trust 协议请求令牌,包括用户名/密码、依赖方、keytype= Bearer 和 tokentype=JSonwebtoken 的详细信息。
- STS 验证用户凭据并创建和发送 JWT 令牌。使用在 STS 中为上述依赖方配置的对称密钥对令牌进行签名。声明未加密。
- 收到令牌后,Web 应用程序通过验证令牌来自同一 STS 来验证令牌,并使用相同的对称密钥解密令牌。
上面的理解似乎正确吗?我在这里遗漏了什么或有什么不对吗?
还有一个问题是如何生成对称密钥?