我有一个使用Stormpath中间件进行身份验证的应用程序设置.我还有我的帐户设置来使用每个组织模型的组.它似乎登录和一切,但我正在努力找到一个合理的方法来获取组织ID或名称基于登
使用Stormpath.SDK.Account引用,我可以执行以下操作:
private readonly IAccount _account; var name = _account.FullName;
我希望有类似的东西可以检索组织,但我没有在他们的SDK参考中找到任何东西.到目前为止,我已经尝试过:
从我的索赔中检索组织. This looks like it’ll be available via the “onk” claim,但是从以下代码查看_claim的属性时我没有看到这个选项:
ClaimsPrincipal _claim = new ClaimsPrincipal(User.Identity);
var OrganizationId = _claim.FindFirst("onk").Value;
我也没有看到从标题中检索组织的方法.它是appears that Host is available in the header,但SDK for Core似乎不允许我这样做.
理想情况下,我希望用户能够登录而不将其租户指定为子域或登录表单中的字段.由于它将按顺序通过我的组织商店,我希望这是可行的.
关于我缺少的任何想法?
在Stormpath中可以使用名称密钥.如何创建组织
var bankOfAOrg = client.Instantiate<IOrganization>()
.SetName("Bank of A")
.SetNameKey("bank-of-a")
.SetStatus(OrganizationStatus.Enabled);
将帐户存储添加到组织:
// With a reference to an IDirectory:
var newMapping = await bankOfAOrg.AddAccountStoreAsync(existingDirectory);
// Or simply by href:
newMapping = await bankOfAOrg.AddAccountStoreAsync("directory_href");
为了能够以上述方式向组织添加组和帐户,我们还应确保将此帐户存储标记为帐户和组的默认值:
newMapping.SetDefaultAccountStore(true) .SetDefaultGroupStore(true); await newMapping.SaveAsync();
将帐户添加到组织:
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);
欲了解更多信息,请查看here.
