2.引用令牌 - soul-soft/IdentityServer GitHub Wiki
说明
使用reference token的好处就是可以由Identityserver统一验证token,而不再是由客户端自行验证。对安全性,以及时效性有要求的可以采用该方案。
优点:由于只返回一个随机串,相对更安全。体积小,网络传输快。可撤销是它最大的亮点
缺点:需要占用服务器存储,验证需要访问存储介质。
客户端
new Client()
{
ClientId = "client",
//使用reference Token
AccessTokenType = AccessTokenType.Reference,
AllowedGrantTypes = new []
{
GrantTypes.Password,
},
ClientSecrets = new Secret[]
{
new Secret("secret".Sha512())
},
AllowedScopes = new[]
{
StandardScopes.OpenId,
"api"
}
}
Api资源
new ApiScope("api")
{
}
//使用reference token验证时,必须定义ApiResource,请求时需要提供apiResource名称以及secret
new ApiResource("orderapi")
{
ClaimTypes = new string[]
{
JwtClaimTypes.Role
},
Scopes =
{
"api",
},
ApiSecrets =
{
new Secret("secret".Sha256())
}
}
请求自省端点
POST /connect/introspect HTTP/1.1
Host: localhost:7150
Content-Type: application/x-www-form-urlencoded
Content-Length: 84
client_id=orderapi&client_secret=secret&token=FAFAF7878GAFAHGHJHJSDFG544578415457878