Main Content

compiler.UserInfo

Retrieve details of logged-in user

Since R2022a

Description

user = compiler.UserInfo() returns the details of a user logged in to the machine running a desktop version of MATLAB® or details of a user logged in to MATLAB Web App Server™.

example

Examples

collapse all

At the MATLAB command prompt execute:

user = compiler.UserInfo()
user = 
  UserInfo with properties:

         UserID: 'someid'
    DisplayName: <missing>
         Groups: <missing>
         Domain: 'SOME_DOMAIN'

To enable detailed user information on MATLAB Web App Server, you must create a userinfo.json file and place it in the webapps_private folder. This file maps properties from your Identity Provider (IdP) to MATLAB properties and defines which apps can access that data.

{
  "version": "1.0.0",
  "userInfo.doc": "Property values to be fetched during login from IdP",
  "userInfo": {
    "UserID": "upn",
    "DisplayName": "displayName",
    "Groups": "groups",
    "LastName": "surname",
    "Email": "mail"
  },
  "appAccess.doc": "Policy for allowing access to user properties within an app or group of apps",
  "appAccess": {
    "Health/BloodPressure": ["UserID", "Email"],
    "Finance/Mortgage": ["UserID", "LastName"],
    "Mystery": ["UserID", "Email", "WebAppsRole"]
  }
}

The keys in the appAccess object correspond to the location of your web apps relative to the apps root folder. If an application is stored in a subfolder, you must include the folder path in the mapping.

For example, if the BloodPressure app is located in a folder named Health, the key in the JSON file must be "Health/BloodPressure". If an app is located directly in the root apps folder, use the app name alone, such as "Mystery".

Use the compiler.UserInfo function within the startupFcn of your App Designer app to customize the app.

function startupFcn(app)
    try
        user = compiler.UserInfo();
    catch me
        % Handle errors if the server is not configured for authentication
        return
    end

    if ~ismissing(user.UserID)
        app.WelcomeLabel.Text = "Welcome, " + user.UserID;
    end
end

Output Arguments

collapse all

The returned object contains properties such as UserID, DisplayName, Groups, and any custom attributes defined in the userinfo.json file. Properties that are not mapped or not permitted for a specific app will return as <missing>.

Version History

Introduced in R2022a

See Also

|

Topics