--- title: "hasRole" description: "Returns true if the user has the given role. The username and usersource parameters are optional in the client scope, but required in the Gateway scope." --- # hasRole > Returns true if the user has the given role. The username and usersource parameters are optional in the client scope, but required in the Gateway scope. **This function is used by Ignition's Expression language**. ## Description ## Syntax ` hasRole(role[, username][, usersource])` ### Parameters | Type | Parameter | Description | |---|---|---| | String | `role` | The name of a role. | | String | `username` | A username. Defaults to the current user. [optional] | | String | `usersource` | The usersource of the username. Defaults to the usersource of the current user. [optional] | :::note When using Perspective, all parameters are required since it's in the Gateway scope. For certain Perspective applications, using [isAuthorized](isAuthorized.md) is recommended instead. ::: ### Results **Boolean** - True if the specified user has the specified role, False if not. ## Examples ```python title="Code Snippet" // This is an example using the current user and default userSource in the Client scope: hasRole("Administrator") ``` ```python title="Code Snippet" // This is an example using a username and userSource, as required for Perspective. hasRole("Administrator", "bob", "default") ``` ```python title="Code Snippet" // This example shows how to handle when the Identity Provider and Users, Roles names are not identical. // If the Identity Provider name is “CompanyIdentity”, but the Users, Roles the IdP points to is “CompanyUsers”, // include the Users, Roles name as the usersource to avoid receiving an error. hasRole(“Operator”, {session.props.auth.user.userName}, “CompanyUsers”) ```