I am using okta as idp in my application, I want to configure custom attribute eg: ID, how can be done in okta? and how to set those values in okta?
Here's the procedure to add custom attributes to Okta's SAML assertion:
When you test your app, you should get the following SAML AttributeStatement node:
<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"
>[email protected]</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"
>[email protected]</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>
(note the last "jobTitle" attribute)
I hope this helps!
You can use SDK Methods to Fetch And Then modify custom attributes of IAppUser. You can fetch User using following SDK Method.These are Asynchronous Methods. You can use following 2 methods to fetch:-
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
You can use jsonConvert to serialize it so that you can deserialize it to get data in your own Model(class)
string json = JsonConvert.SerializeObject(userWithCustomAttributes, Formatting.Indented);
userWithCustomModel = JsonConvert.DeserializeObject<"CustomModel">(json);
Above Method was to get User .. Then you can modify and send the modified user using following SetProperty()
Method of IAppUser
as follows:-
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 this method will modify your custom attributes which you set using setproperty()
. In setproperty()
first argument I've used string constant you can use your own according to your mapping variable name for that particular custom attribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With