C# 如何为IdentityServer 3创建其他参数授予类型:密码
我已启动IdentityServer3,并与网络身份和身份管理器合作。我已经基于资源所有者流的示例创建了一个JS客户端。我的AsNetIdentity实现是以这样的方式定制的:userstore具有组织表的外键。组织表充当租户表,因为我们的IdentityServer和WebApi将是多租户的。当用户登录时,我需要向请求传递指定用户租户id的其他参数。一旦获得租户id,我将覆盖AuthenticateLocalAsync以查找用户的租户信息 我无法在grant_type:password上传递额外的租户id或其他参数。我曾尝试传入act_值数组,但我不确定我是否以正确的方式执行了所有这些操作 任何关于范围、声明、角色等的解释的额外信息都会有很大的帮助,因为它们仍然是模糊的 这是idsvr上的客户端C# 如何为IdentityServer 3创建其他参数授予类型:密码,c#,.net,asp.net-identity,identityserver3,C#,.net,Asp.net Identity,Identityserver3,我已启动IdentityServer3,并与网络身份和身份管理器合作。我已经基于资源所有者流的示例创建了一个JS客户端。我的AsNetIdentity实现是以这样的方式定制的:userstore具有组织表的外键。组织表充当租户表,因为我们的IdentityServer和WebApi将是多租户的。当用户登录时,我需要向请求传递指定用户租户id的其他参数。一旦获得租户id,我将覆盖AuthenticateLocalAsync以查找用户的租户信息 我无法在grant_type:password上传递额
new Client
{
ClientId = "tleweb",
ClientName = "TLE Web Client",
ClientSecrets = new List<Secret>
{
new Secret("secret".Sha256())
},
Enabled = true,
Flow = Flows.ResourceOwner,
RequireConsent = false,
AllowRememberConsent = true,
RedirectUris = new List<string>(){ "https://localhost:13048/account/signInCallback"},
PostLogoutRedirectUris = new List<string>(){ "https://localhost:13048/"},
AllowedScopes = new List<string>()
{
Constants.StandardScopes.OpenId,
Constants.StandardScopes.Profile,
Constants.StandardScopes.Email,
"read",
"write",
"tenant_id"
},
AllowedCorsOrigins = new List<string>
{
"http://localhost:13048"
},
AccessTokenType=AccessTokenType.Jwt,
AccessTokenLifetime = 3600,
AbsoluteRefreshTokenLifetime = 86400,
SlidingRefreshTokenLifetime = 43200,
RefreshTokenUsage = TokenUsage.OneTimeOnly,
RefreshTokenExpiration = TokenExpiration.Sliding
}
找到了!在请求中使用acr_值参数
function getToken() {
var uid = document.getElementById("username").value;
var pwd = document.getElementById("password").value;
var xhr = new XMLHttpRequest();
xhr.onload = function (e) {
console.log(xhr.status);
console.log(xhr.response);
var response_data = JSON.parse(xhr.response);
if (xhr.status === 200 && response_data.access_token) {
token = response_data.access_token;
}
showToken(response_data);
}
xhr.open("POST", tokenUrl);
var data = {
username: uid,
password: pwd,
acr_values: ["1"],
grant_type: "password",
scope: "openid profile read write tenant_id"
};
var body = "";
for (var key in data) {
if (body.length) {
body += "&";
}
body += key + "=";
body += encodeURIComponent(data[key]);
}
xhr.setRequestHeader("Authorization", "Basic " + btoa(client_id + ":" + client_secret));
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(body);
}