【发布时间】:2016-11-07 05:01:13
【问题描述】:
我在我的应用程序中使用 okta 作为 idp,我想配置自定义属性,例如:ID,如何在 okta 中完成?以及如何在 okta 中设置这些值?
【问题讨论】:
标签: spring-boot saml-2.0 okta
我在我的应用程序中使用 okta 作为 idp,我想配置自定义属性,例如:ID,如何在 okta 中完成?以及如何在 okta 中设置这些值?
【问题讨论】:
标签: spring-boot saml-2.0 okta
以下是向 Okta 的 SAML 断言添加自定义属性的过程:
当您测试您的应用时,您应该获得以下 SAML AttributeStatement 节点:
<saml2:AttributeStatement xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion">
<saml2:Attribute Name="firstName"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"
>
<saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:string"
>Isaac</saml2:AttributeValue>
</saml2:Attribute>
<saml2:Attribute Name="lastName"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"
>
<saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:string"
>Brock</saml2:AttributeValue>
</saml2:Attribute>
<saml2:Attribute Name="Email"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"
>
<saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:string"
>isaac.brock@mailinator.com</saml2:AttributeValue>
</saml2:Attribute>
<saml2:Attribute Name="userName"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"
>
<saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:string"
>isaac@company.com</saml2:AttributeValue>
</saml2:Attribute>
<saml2:Attribute Name="phone"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"
>
<saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:string"
>+1 415 456 7893</saml2:AttributeValue>
</saml2:Attribute>
<saml2:Attribute Name="jobTitle"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified"
>
<saml2:AttributeValue xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:string"
>Vice President</saml2:AttributeValue>
</saml2:Attribute>
</saml2:AttributeStatement>
(注意最后一个“jobTitle”属性)
我希望这会有所帮助!
【讨论】:
您可以使用 SDK 方法来获取然后修改 IAppUser 的自定义属性。您可以使用以下 SDK 方法获取用户。这些是异步方法。您可以使用以下 2 种方法来获取:-
public async Task<IAppUser> GetOktaApplicationUser(string oktaProfileId)
{
var x = await
Client.Applications.**GetApplicationUserAsync**(ConfigurationManager.AppSettings["okta:ClientId"],
oktaProfileId);
return x;
}
var userApp = client.GetOktaApplicationUser(oktaProfileId).Result;
var userWithCustomAttributes = userApp.**GetData**(); //Getdata() to get Custom Attributes of User
你可以使用jsonConvert来序列化它,这样你就可以反序列化它来获取你自己的Model(class)
中的数据 string json = JsonConvert.SerializeObject(userWithCustomAttributes, Formatting.Indented);
userWithCustomModel = JsonConvert.DeserializeObject<"CustomModel">(json);
上面的方法是获取用户..然后你可以使用SetProperty()IAppUser的方法修改并发送修改后的用户,如下:-
public async Task<bool> UpdateApplicationUser(CustomModel user)
{
**IAppUser** appuser = new Okta.Sdk.AppUser();
appuser.Profile = new Resource();
appuser.Id = user.id;
appuser.Profile.**SetProperty**("email", user.profile.email);
appuser.Profile.**SetProperty**("<"Your custom attribute name">", user.profile.Roles);
try
{
var x = await Client.Applications.**UpdateApplicationUserAsync**(appuser, ConfigurationManager.AppSettings["okta:ClientId"], appuser.Id);
return true;
}
UpdateApplicationUserAsync 此方法将修改您使用setproperty() 设置的自定义属性。在setproperty() 第一个参数中,我使用了字符串常量,您可以根据特定自定义属性的映射变量名称使用自己的。
【讨论】: