Authentication API
Version Change Notice:
- 1.7.0+: Auth API paths use GraphSpace format, such as
/graphspaces/DEFAULT/auth/users, and group/target IDs match their names (e.g.,admin)- 1.5.x and earlier: Auth API paths include graph name, and group/target IDs use format like
-69:grant. See HugeGraph 1.5.x RESTful API
10.1 User Authentication and Access Control
To enable authentication and related configurations, please refer to the Authentication Configuration documentation.
Overview of User Authentication and Access Control:
HugeGraph supports multi-user authentication and fine-grained access control. It adopts a 4-tier design based on “User-User Group-Operation-Resource” to flexibly control user roles and permissions. Resources describe data in the graph database, such as vertices that meet certain conditions. Each resource consists of three elements: type, label, and properties. There are a total of 18 types and combinations of any label and properties to form resources. The internal condition of a resource is an “AND” relationship, while the condition between multiple resources is an “OR” relationship. Users can belong to one or more user groups, and each user group can have permissions for any number of resources. The types of operations include read, write, delete, execute, etc. HugeGraph supports dynamically creating users, user groups, and resources, and supports dynamically assigning or revoking permissions. During the initialization of the database, a super administrator user is created, and subsequently, various role users can be created by the super administrator. If a newly created user is assigned sufficient permissions, they can create or manage more users.
Example:
user(name=boss) -belong-> group(name=all) -access(read)-> target(graph=graph1, resource={label: person, city: Beijing})
Description: User ‘boss’ has read permission for people in the ‘graph1’ graph from Beijing.
Interface Description:
The core of user authentication and access control is 5 categories: UserAPI, GroupAPI, TargetAPI, BelongAPI, AccessAPI. Alongside them, ManagerAPI grants graphspace-level manager roles, LoginAPI issues and verifies tokens, and ProjectAPI groups several graphs so that permissions can be granted for the whole set at once. Note Before 1.5.0, the format of ids such as group/target was similar to -69:grant. After 1.7.0, the id and name were consistent. Such as admin HugeGraph 1.5 x RESTful API
10.2 User (User) API
The user interface includes APIs for creating users, deleting users, modifying users, and querying user-related information.
10.2.1 Create User
Params
- user_name: User name
- user_password: User password
- user_nickname: User nickname
- user_phone: User phone number
- user_email: User email
- user_avatar: URL of the user avatar
- user_description: User description
Both user_name and user_password are required, the rest are optional.
Request Body
Method & Url
Response Status
Response Body
In the response message, the password is encrypted as ciphertext.
10.2.2 Delete User
Params
- id: User ID to be deleted
Method & Url
Response Status
10.2.3 Modify User
Params
- id: User ID to be modified
Method & Url
Request Body
Modify user_password and user_phone. user_name can not be changed, and when it is passed it must match the existing name.
Response Status
Response Body
The returned result is the entire user object including the modified content.
10.2.4 Query User List
Params
- name: Return only the user with this name. When it is given, the response is a single user object instead of a list, and
404is returned if no such user exists. - limit: Upper limit of the number of results returned, default is 100
Method & Url
Response Status
Response Body
10.2.5 Query a User
Params
- id: User ID to be queried
Method & Url
Response Status
Response Body
10.2.6 Query Roles of a User
Method & Url
Response Status
Response Body
10.3 Group (Group) API
Groups grant corresponding resource permissions, and users are assigned to different groups, thereby having different resource permissions. The group interface includes APIs for creating groups, deleting groups, modifying groups, and querying group-related information.
10.3.1 Create Group
Params
- group_name: Group name
- group_description: Group description
Request Body
Method & Url
Response Status
Response Body
10.3.2 Delete Group
Params
- id: Group ID to be deleted
Method & Url
Response Status
10.3.3 Modify Group
Params
- id: Group ID to be modified
Method & Url
Request Body
Modify group_description
Response Status
Response Body
The returned result is the entire group object including the modified content.
10.3.4 Query Group List
Params
- limit: Upper limit of the number of results returned
Method & Url
Response Status
Response Body
10.3.5 Query a Specific Group
Params
- id: Group ID to be queried
Method & Url
Response Status
Response Body
10.4 Resource (Target) API
Resources describe data in the graph database, such as vertices that meet certain criteria. Each resource includes three elements: type, label, and properties. There are 18 types in total, and the combination of any label and any properties forms a resource. The internal conditions of a resource are based on the AND relationship, while the conditions between multiple resources are based on the OR relationship.
The resource API includes creating, deleting, modifying, and querying resources.
10.4.1 Create Resource
Params
- target_name: Name of the resource
- target_graph: Graph of the resource
- target_url: URL of the resource
- target_resources: Resource definitions (list)
target_resources can include multiple target_resource, stored in the form of a list.
Each target_resource contains:
- type: Optional value: VERTEX, EDGE, etc. Can be filled with ALL, indicating it can be a vertex or edge.
- label: Optional value: name of a vertex or edge type. Can be filled with *, indicating any type.
- properties: Map type, can contain multiple key-value pairs of properties. Must match all property values. Property values can support conditional ranges (e.g., age: P.gte(18)). If properties are null, it means any property is allowed. If both the property name and value are ‘*’, it also means any property is allowed.
For example, a specific resource: “target_resources”: [{“type”:“VERTEX”,“label”:“person”,“properties”:{“city”:“Beijing”,“age”:“P.gte(20)”}}]
The resource definition means: a vertex of type ‘person’ with the city property set to ‘Beijing’ and the age property greater than or equal to 20.
Request Body
Method & Url
Response Status
Response Body
10.4.2 Delete Resource
Params
- id: Resource Id to be deleted
Method & Url
Response Status
10.4.3 Modify Resource
Params
- id: Resource Id to be modified
Method & Url
Request Body
Modify the ’type’ in the resource definition.
Response Status
Response Body
The response contains the entire target group object, including the modified content.
10.4.4 Query Resource List
Params
- limit: Upper limit of the number of returned results.
Method & Url
Response Status
Response Body
10.4.5 Query a Specific Resource
Params
- id: Id of the resource to query
Method & Url
Response Status
Response Body
10.5 Association of Roles (Belong) API
The association between users and user groups allows a user to be associated with one or more user groups. User groups have permissions for related resources, and the permissions for different user groups can be understood as different roles. In other words, users are associated with roles.
The API for associating roles includes creating, deleting, modifying, and querying the association of roles for users.
10.5.1 Create an Association of Roles for a User
Params
- user: User ID
- group: User group ID
- belong_description: Description
Request Body
Method & Url
Response Status
Response Body
10.5.2 Delete an Association of Roles
Params
- id: ID of the association of roles to delete
Method & Url
Response Status
10.5.3 Modify an Association of Roles
An association of roles can only be modified for its description. The user and group properties cannot be modified. If you need to modify an association of roles, you need to delete the existing association and create a new one.
Params
- id: ID of the association of roles to modify
Method & Url
Request Body
Modify the belong_description field
Response Status
Response Body
The response includes the modified content as well as the entire association of roles object
10.5.4 Query List of Associations of Roles
Params
- user: Return only the associations of this user
- group: Return only the associations of this group
- limit: Upper limit on the number of results to return, default is 100
user and group can not be used together.
Method & Url
Response Status
Response Body
10.5.5 View a Specific Association of Roles
Params
- id: The id of the association of roles to be queried
Method & Url
Response Status
Response Body
10.6 Authorization (Access) API
Grant permissions to user groups for resources, including operations such as READ, WRITE, DELETE, EXECUTE, etc. The authorization API includes: creating, deleting, modifying, and querying permissions.
10.6.1 Create Authorization (Granting permissions to user groups for resources)
Params
- group: Group ID
- target: Resource ID
- access_permission: Permission grant
- access_description: Authorization description
Access permissions:
- READ: Read operations, including all queries such as querying the schema, retrieving vertices/edges, aggregating vertex and edge counts (VERTEX_AGGR/EDGE_AGGR), and reading the graph’s status (STATUS), variables (VAR), tasks (TASK), etc.
- WRITE: Write operations, including creating and updating operations, such as adding property keys to the schema or adding/updating properties of vertices.
- DELETE: Delete operations, including deleting metadata, vertices, or edges.
- EXECUTE: Execute operations, including executing Gremlin queries, executing tasks, and executing metadata functions.
Request Body
Method & Url
Response Status
Response Body
10.6.2 Delete Authorization
Params
- id: The ID of the authorization to be deleted
Method & Url
Response Status
10.6.3 Modify Authorization
Authorization can only be modified for its description. User group, resource, and permission cannot be modified. If you need to modify the authorization relationship, delete the original authorization and create a new one.
Params
- id: The ID of the authorization to be modified
Method & Url
Request Body
Modify access_description
Response Status
Response Body
The response includes the modified content as well as the entire authorization object.
10.6.4 Query Authorization List
Params
- group: Return only the authorizations of this group
- target: Return only the authorizations on this resource
- limit: The maximum number of results to return, default is 100
group and target can not be used together.
Method & Url
Response Status
Response Body
10.6.5 Query a Specific Authorization
Params
- id: The ID of the authorization to be queried
Method & Url
Response Status
Response Body
10.7 Graphspace Manager (Manager) API
Note: Before using the following APIs, you need to create a graphspace first. For example, create a graphspace named
gs1via the Graphspace API. The examples below assume thatgs1already exists.
Note: The manager APIs only work when the server runs in PD mode. In standalone mode they return
400with the messageGraphSpace management is not supported in standalone mode.
- The graphspace manager API is used to grant/revoke manager roles for users at the graphspace level, and to query the roles of the current user or other users in a graphspace. Supported role types include
SPACE,SPACE_MEMBER, andADMIN.
10.7.1 Check whether the current login user has a specific role
Params
- type: Role type to check, required, one of
SPACE,SPACE_MEMBER,ADMIN
Method & Url
Response Status
Response Body
10.7.2 List graphspace managers
Params
- type: Role type, required, one of
SPACE,SPACE_MEMBER,ADMIN.SPACElists the managers of the graphspace,SPACE_MEMBERlists its members, andADMINlists the administrators of the whole cluster.
Method & Url
Response Status
Response Body
10.7.3 Grant/create a graphspace manager
- The following example grants user
bosstheSPACE_MEMBERrole in graphspacegs1.
Params
- user: User or group name, required
- type: Role type, required, one of
SPACE,SPACE_MEMBER,ADMIN
Granting
SPACEto a user that is already a space member revokes the member role first, and the other way round. Only an administrator can grantADMIN.
Request Body
Method & Url
Response Status
Response Body
10.7.4 Revoke graphspace manager privileges
- The following example revokes the
SPACE_MEMBERrole of userbossin graphspacegs1.
Params
- user: User name to revoke. The built-in
adminuser can not be removed fromADMIN. - type: Role type to revoke, one of
SPACE,SPACE_MEMBER,ADMIN
Method & Url
Response Status
10.7.5 Query roles of a specific user in a graphspace
Params
- user: User name
Method & Url
Response Status
Response Body
The returned roles are a subset of ADMIN, SPACE and SPACE_MEMBER; NONE is returned when the user holds none of them in this graphspace.
10.7.6 Check whether the current login user holds a default role
Default roles are the built-in roles of a graphspace, see Graphspace API. Valid role values are space, space_member, analyst and observer; graph is only taken into account for the observer role.
Params
- role: Default role name, required
- graph: Graph name, optional, only used with
role=observer
Method & Url
Response Status
Response Body
10.8 Login (Login) API
Besides HTTP Basic authentication, the server can hand out a JWT token that is then passed as Authorization: Bearer <token>. The login endpoints are not scoped to a graphspace.
The token is signed with the auth.token_secret option and expires after auth.token_expire seconds (default 86400). The default secret is generated randomly at startup, so set it explicitly when tokens must stay valid across a restart or must be accepted by more than one server.
10.8.1 Log in and get a token
Params
- user_name: User name, required
- user_password: User password, required
- token_expire: Token lifetime in seconds, optional
Request Body
Method & Url
Response Status
Wrong credentials return 401.
Response Body
10.8.2 Log out and invalidate the token
The token to invalidate is taken from the request header, no request body is needed.
Params
Request header
- Authorization:
Bearer <token>, required. Only the Bearer scheme is accepted, other schemes return400.
Method & Url
Response Status
An invalid or expired token returns 401.
10.8.3 Verify a token
Params
Request header
- Authorization:
Bearer <token>, required
Method & Url
Response Status
An invalid or expired token returns 401.
Response Body
10.9 Project (Project) API
A project groups a set of graphs together with an admin group and an op group, so that permissions can be granted for the whole set at once. Creating a project also creates its project_target, project_admin_group and project_op_group, which are returned in the response but can not be set by the client.
10.9.1 Create Project
Params
- project_name: Project name, required
- project_description: Project description, optional
project_graphs can not be passed on creation, use the add_graph action below.
Request Body
Method & Url
Response Status
Response Body
10.9.2 Add graphs to or remove graphs from a project
Params
- id: Project ID
- action:
add_graphto add graphs,remove_graphto remove them
Request Body
Method & Url
Response Status
Response Body
The whole project object is returned, including the updated graph list.
10.9.3 Modify the description of a project
Params
- id: Project ID
Leave action out to update the description. project_graphs must not be present in this case.
Request Body
Method & Url
Response Status
10.9.4 Query Project List
Params
- limit: The maximum number of results to return, default is 100
Method & Url
Response Status
Response Body
10.9.5 Query a Specific Project
Params
- id: Project ID
Method & Url
Response Status
10.9.6 Delete Project
Params
- id: Project ID
Remove all graphs from the project before deleting it.