Manage custom attributes of the user’s profile via the REST API using Asgardeo React SDK

Hey Everyone! As for our next article of the Asgardeo blog series, Let’s discuss how to manage custom attributes in a Asgardeo organization via SCIM2.0 API. Same as previous tutorials I will use React sample application with Asgardeo React SDK integration for the demonstrations.

In case you missed the previous article on how to integrate Asgardeo React SDK to the existing React application, you can find it below.

Also if you are more interested in how to manage authenticated user profiles and user sessions via REST API, you can refer to the below articles.

Manage Custom Attributes and Mappings In Asgardeo Organization

An attribute is a piece of information associated with a user such as an email, username, country, etc. Using attributes, we can manage user information required to the applications. User information displayed in the user profile is managed using attributes. You can find more information from the Asgardeo documentation below.

  1. After logging in to Asgardeo console, navigate to Manage -> Attributes

2. Click on Attributes -> New Attribute

3. Enter the new custom attribute name and attribute display name.

As we are going to manage this attribute via SCIM API, we need to keep SCIM 2.0 protocol mapping for our new custom attribute.

4. click Finish.

  • Now If you navigate to Manage-> Attributes-> SCIM 2.0 -> Custom Schema attributes, you will find our new custom attribute.

Update Custom Attribute Using SCIM 2.0 REST API

As we successfully created a new custom attribute and mapped it to the SCIM custom schema, Let’s try to update the value of our new attribute using SCIM REST API.

For demonstration purposes, I will use the same React sample application that I have used for previous demos in the above articles.

In this case, we can use httpRequst API in Asgardeo Auth React SDK for the API invocation. With httpRequest, we don’t need to retrieve tokens separately to invoke the Asgardeo APIs because the httpRequest will send the token in the Authorization header of the request by default.

In order to update an attribute, we need to know the following details.

  1. What is the custom attribute name?
  2. What is the user schema that the custom attribute was added to?

So answers to the above points can be found after following the below steps.

  1. navigate to Manage-> Attributes-> SCIM 2.0 -> Custom Schema and search our new custom attribute “Activity Status”.

Also, you can find the schema and attribute name from the wizard which pops up when you create a new custom attribute.

2. As you can see the value of the SCIM Attribute column ->

urn:scim:wso2:schema:activitystatusSchema is -> urn:scim:wso2:schema
Attribute name is -> activitystatus

3. So now we know the respective values of the schema and custom attribute name, we can proceed to update our new custom attribute as follows.

  • Update the attribute(s) in the authenticated user’s profile:
    PATCH /scim2/Me
SCIM API SAMPLE
  • Retrieve the attributes in the authenticated user profile.
    GET /scim2/Me

You will get a response like this.

Also, we can retrieve only our custom attribute by using the “attributes” parameter like below.

The response will be like this.

You can find the full source code of the sample React application below.

Hope you got an idea about how to create new custom attributes in Asgardeo from the Asgardeo console and how we can update the values of the attributes using SCIM2.0 REST API from a React application with Asgardeo React SDK.

Thank you for reading this article.

Cheers!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store