Skip to content

Determine whether the user has a certain role

This document is automatically generated based on https://github.com/authing/authing-docs-factory based on https://api-explorer.genauth.ai V3 API, and is consistent with API parameters and return results. If the description of this document is incorrect, please refer to V3 API.

Use user ID to determine whether the user has a certain role. Supports passing in multiple roles, and can choose to specify the user ID type, etc.

Method Name

ManagementClient.hasAnyRole

Request Parameters

NameTypeIs it required?Default valueDescriptionSample value
roles<a HasRoleRolesDto[]yes-Role list
userIdstringyes-The unique identifier of the user, which can be user ID, user name, email, phone number, externalId, or ID in the external identity source. For details, see the description of the userIdType field. The default is user id.6229ffaxxxxxxxxcade3e3d9
options<a HasAnyRoleOptionsDtono-Optional parameters

Example Code

ts
import { ManagementClient, Models } from "authing-node-sdk";

// Initialize ManagementClient
const managementClient = new ManagementClient({
  // Need to be replaced with your GenAuth Access Key ID
  accessKeyId: "GEN_AUTH_ACCESS_KEY_ID",
  // Need to be replaced with your GenAuth Access Key Secret
  accessKeySecret: "GEN_AUTH_ACCESS_KEY_SECRET",
  // If it is a private deployment customer, you need to set the GenAuth service domain name
  // host: 'https://api.your-authing-service.com'
});

(async () => {
  const result = await managementClient.hasAnyRole({
    // Replace user ID
    userId: "6229ffaxxxxxxxxcade3e3d9",
    roles: [
      {
        namespace: "default",
        code: "admin",
      },
    ],
    options: {
      userIdType: Models.HasAnyRoleOptionsDto.userIdType.USER_ID,
    },
  });
  console.log(JSON.stringify(result, null, 2));
})();

Request Response

type: HasAnyRoleRespDto

NameTypeDescription
statusCodenumberBusiness status code, which can be used to determine whether the operation is successful. 200 means success.
messagestringDescription
apiCodenumberSegmented error code, which can be used to get the specific error type (successful requests are not returned). For a detailed list of error codes, see: API Code List
requestIdstringRequest ID. Returned when the request fails.
data<a HasAnyRoleDtoResponse data

Sample result:

json
{
  "statusCode": 200,
  "message": "Operation successful",
  "requestId": "934108e5-9fbf-4d24-8da1-c330328abd6c",
  "data": {
    "hasAnyRole": true
  }
}

Data Structure

HasRoleRolesDto

NameTypeIs it requiredDescriptionExample value
namespacestringNoCode of the permission group (permission space). Do not pass to obtain the default permission group.default
codestringYesRole codeadmin

HasAnyRoleOptionsDto

NameTypeIs it requiredDescriptionSample value
userIdTypestringNoUser ID type, the default value is user_id, the optional values are:
- user_id: GenAuth user ID, such as 6319a1504f3xxxxf214dd5b7
- phone: user phone number
- email: user email
- username: username
- external_id: user ID in the external system, corresponding to the externalId field of GenAuth user information
- identity: user's external identity source information, in the format of <extIdpId>:<userIdInIdp>, where <extIdpId> is the ID of the GenAuth identity source, and <userIdInIdp> is the user's ID in the external identity source.
Example value: 62f20932716fbcc10d966ee5:ou_8bae746eac07cd2564654140d2a9ac61.
- sync_relation: The user's external identity source information, in the format of <provier>:<userIdInIdp>, where <provier> is the synchronization identity source type, such as wechatwork, lark; <userIdInIdp> is the user's ID in the external identity source.
Example value: lark:ou_8bae746eac07cd2564654140d2a9ac61.
user_id

HasAnyRoleDto

NameTypeIs it required?DescriptionSample value
hasAnyRolebooleanYesDoes it have any of the roles?true

Agent infrastructure for identity, memory, and web action.