Jac*_*ick 5 .net identity claims-based-identity stormpath asp.net-core
我有一个使用Stormpath中间件进行身份验证的应用程序设置.我还有我的帐户设置来使用每个组织模型的组.它似乎登录和一切,但我正在努力找到一个合理的方法来获取组织ID或名称基于登录的用户.
使用Stormpath.SDK.Account引用,我可以执行以下操作:
private readonly IAccount _account;
var name = _account.FullName;
Run Code Online (Sandbox Code Playgroud)
我希望有类似的东西可以检索组织,但我没有在他们的SDK参考中找到任何东西.到目前为止,我已经尝试过:
从我的索赔中检索组织.看起来它可以通过"onk"声明获得,但是当我从以下代码查看_claim的属性时,我没有看到它作为一个选项:
ClaimsPrincipal _claim = new ClaimsPrincipal(User.Identity);
var OrganizationId = _claim.FindFirst("onk").Value;
Run Code Online (Sandbox Code Playgroud)
我也没有看到从标题中检索组织的方法.这似乎是主机可用的头,但核心的SDK似乎并没有让我明白了.
理想情况下,我希望用户能够登录而不将其租户指定为子域或登录表单中的字段.由于它将按顺序通过我的组织商店,我希望这是可行的.
关于我缺少的任何想法?
在 Stormpath 中可以使用namekey
.
如何创建Organization
var bankOfAOrg = client.Instantiate<IOrganization>()
.SetName("Bank of A")
.SetNameKey("bank-of-a")
.SetStatus(OrganizationStatus.Enabled);
Run Code Online (Sandbox Code Playgroud)
将帐户存储添加到组织:
// With a reference to an IDirectory:
var newMapping = await bankOfAOrg.AddAccountStoreAsync(existingDirectory);
// Or simply by href:
newMapping = await bankOfAOrg.AddAccountStoreAsync("directory_href");
Run Code Online (Sandbox Code Playgroud)
为了能够以上述方式将组和帐户添加到组织中,我们还应该确保将此帐户存储标记为帐户和组的默认值:
newMapping.SetDefaultAccountStore(true)
.SetDefaultGroupStore(true);
await newMapping.SaveAsync();
Run Code Online (Sandbox Code Playgroud)
将帐户添加到组织:
var chewie = client.Instantiate<IAccount>()
.SetGivenName("Chewbacca")
.SetSurname("the Wookiee")
.SetUsername("rrwwgggh")
.SetEmail("chewie@kashyyyk.rim")
.SetPassword("Changeme123!");
chewie.CustomData.Put("favoriteShip", "Millennium Falcon");
await bankOfAOrg.CreateAccountAsync(chewie);
Run Code Online (Sandbox Code Playgroud)
欲了解更多信息,请看这里。
归档时间: |
|
查看次数: |
129 次 |
最近记录: |