Native authentication SDK attribute builder

Applies to: White circle with a gray X symbol. Workforce tenants Green circle with a white check mark symbol. External tenants (learn more)

In native authentication, the information you collect from the user during sign-up is configured in the user flow in the Microsoft Entra admin center. The name of the user attribute as it appears in the Microsoft Entra admin center is different from the variable name that you use when you reference it in your app.

Fortunately, the native authentication SDK enables you to build the user attributes and assign values to them before you use them in the SDKs signUp() method.

Build user attributes

To build user attributes in the Android SDK:

  • Use the utility class UserAttribute.Builder that the SDK provides. The UserAttributes.Builder class contains methods whose parameter is the value that you collect from the user.

  • Identify the user attributes that you want to build, then use the following code snippet to build them:

        //build the user attributes, both built-in and custom attributes
        val userAttributes = UserAttributes.Builder()
            .country(country)
            .city(city)
            .displayName(displayName)
            .givenName(givenName)
            .jobTitle(jobTitle)
            .postalCode(postalCode)
            .state(state)
            .streetAddress(streetAddress)
            .surname(surname)
            .build() 
    
        CoroutineScope(Dispatchers.Main).launch {
            //use the userAttributes variable in your signUp method 
            val actionResult = authAuthClientInstance.signUp(
                username = emailAddress,
                attributes = userAttributes
            )
        }  
    
  • To build custom attributes, use UserAttribute.Builder class customAttribute() method. The method accepts the custom attribute's programmable name, and the value of the attribute:

       val userAttributes = UserAttributes.Builder()
           .customAttribute("extension_2588abcdwhtfeehjjeeqwertc_loyaltyNumber", loyaltyNumber)
           .build() 
    
       CoroutineScope(Dispatchers.Main).launch {
           //use the userAttributes variable in your signUp method 
           val actionResult = authAuthClientInstance.signUp(
               username = emailAddress,
               attributes = userAttributes
           )
       }  
    

To learn more about the programmable names of user profile attributes, see the User profile attributes article.