Customize Web App Behavior Based on User
Note
The ability to customize web app behavior based on the user is supported in the standalone MATLAB® Web App Server™ product and not the development version included in MATLAB Compiler™. For details, see MATLAB Web App Server Differences.
Prerequisites
Enable SSL on the server. For more information, see Enable SSL on MATLAB Web App Server.
Enable authentication on the server. For more information, see Authentication.
Create userinfo.json File
You can customize the behavior of a web app based on which user is logged in. To customize behavior:
Create a file named
userinfo.jsonand place it in thewebapps_privatefolder on the server.The
webapps_privatefolder is in:Operating System Folder Location Windows®
%ProgramData%\MathWorks\webapps\R2025b\config\webapps_privateLinux®
/local/MathWorks/webapps/R2025b/config/webapps_privatemacOS
/Library/Application Support/MathWorks/webapps/R2025b/config/webapps_privateWhile authoring your web app using App Designer in MATLAB, use the
compiler.UserInfo(MATLAB Compiler) function in your app code to retrieve user-specific details from theuserinfo.jsonfile.
The JSON schema for userinfo.json
is:
{
"version": "<major>.<minor>.<patch>",
"userInfo.doc": "Property values to be fetched during login from IdP",
"userInfo": {
"UserID": "<uid_or_upn>",
"DisplayName": "<user_name_that_is_displayed>",
"Groups": "<group_membership_of_user>",
"<propertyName1>": "<value1>",
"<propertyName2>": "<value2>",
"<propertyName3>": "<value3>",
...
},
"appAccess.doc": "Policy for allowing access to user properties within an app or group of apps",
"appAccess": {
"<appName>": ["<userInfo_propertyName>","<userInfo_propertyName>", ...],
...
"*": "*"
}
}
version: Specify the version of the JSON schema. The default value for R2025b is
1.0.0.userInfo.doc: Text describing the purpose of the
userInfoblock.userInfo: The
userInfoblock contains a list of property names and values that help identify users. The property namesUserID,DisplayName, andGroupsare required in everyuserinfo.jsonfile. Other property names and values can be included as necessary. Property names and values correspond to LDAP or OIDC attributes. For example, if you want to use an email address as part of a user's information, you can specifyEmailas a property name and attribute value for theEmailAddressas the property value.UserID: Specify the LDAP or OIDC attribute type that corresponds to a user's ID as a property value.
UserIDis a required property name. For example:"UserID": "uid"If you do not specify an attribute type as a property value to the
UserIDproperty name,compiler.UserInfo(MATLAB Compiler), which queries user details, returns<missing>as a property value.DisplayName: Specify the LDAP or OIDC attribute type that corresponds to a user's preferred name. For example:
"DisplayName": "displayName"Groups: Specify the LDAP or OIDC attribute type that corresponds to the group that the user belongs to. For example:
"Groups": "groups"Note
UserID,DisplayName, andGroupsproperty names are required in everyuserinfo.jsonfile. You can add custom property names to theuserInfoblock and assign property values based on LDAP or OIDC attribute types. For example, if you want to use an email address as part of a user's information, you can specifyEmailas a property name and the LDAP attribute typeEmailAddress(ormailif using OIDC) as a property value.appAccess.doc: Text describing the purpose of the
appAccessblock.appAccess: The
appAccessblock contains a list of property names that correspond to app names hosted on the server and property values that correspond to property names from theuserInfoblock. Once you specify an app within theappAccessblock, you can then determine which user properties that particular app has access to.<appName>: Specify an app name as the property name and a combination of property names from theuserInfoblock as property values, indicating what properties can be accessed within an app. For example:"BloodPressure": ["UserID", "Email"]
Tip
You can use an asterisk (*) wildcard character as both a property name and property value to indicate that all apps can be accessed by all users. For example:
"*": "*"The property names
WebAppsRoleandWebAppsDisplayNameare reserved and cannot be used in theuserInfoblock. However, they can be used in theappAccessblock as property values. For example:"Mystery": ["UserID", "Email", "WebAppsRole", "WebAppsDisplayName"]WebAppsRolecorresponds to the user's role: Author and User. For details, see Role-Based Access.WebAppsDisplayNamecorresponds to the name displayed on the apps home page.
If you make any changes in the
userInfoblock, you must restart the server. For details, seewebapps-restart.
Example Using the userinfo.json File and compiler.UserInfo Function
In the following sample userinfo.json file the
userInfo block contains the required property names:
UserID, DisplayName, and
Groups. In addition, it contains two custom property
names, LastName and Email. All property
names are assigned OIDC attributes as property values.
The appAccess block contains three apps:
BloodPressure, Mortgage, and
Mystery.
The
BloodPressureapp has access to theUserIDandDisplayNameproperties from theuserInfoblock.The
Mortgageapp has access to theUserIDandLastNameproperties from theuserInfoblock.The
Mysteryapp has access to theUserIDandDisplayNameproperties, and the reserved propertiesWebAppsRoleandWebAppsDisplayNamefrom theuserInfoblock.
{
"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": {
"BloodPressure": ["UserID","Email"],
"Mortgage": ["UserID","LastName"],
"Mystery": ["UserID","Email","WebAppsRole","WebAppsDisplayName"]
}
}Given the userinfo.json file above, the
BloodPressure app can use the
compiler.UserInfo function within the app code as
follows:
function startupFcn(app) try user = compiler.UserInfo(); catch me error(me.message); return end if ~ismissing(user.UserID) % app code % Example: % app.userIDLabel.Text = [app.userIDLabel.Text user.UserID]; end if isprop(user, 'Email') % app code % Example: % app.EmailLabel.Text = [app.EmailLabel.Text user.Email]; end ...
Given the userinfo.json file above, the
Mystery app can use the
compiler.UserInfo function within the app code as
follows:
function startupFcn(app) try user = compiler.UserInfo(); catch me error(me.message); return end if isprop(user, 'WebAppsDisplayName') % app code % Example: % app.DisplayNameLabel.Text = [app.DisplayNameLabel.Text user.WebAppsDisplayName]; end if isprop(user, 'WebAppsRole') % app code % Example: % app.RoleLabel.Text = [app.RoleLabel.Text user.WebAppsRole]; end ...
See Also
compiler.UserInfo (MATLAB Compiler)