> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hybridbox.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 分配角色

> 创建帐户角色分配

<script src="/locale-bridge.js" />


## OpenAPI

````yaml /openapi.zh-cn.json POST /v1/public/accounts/{account_id}/auth/role-assignments
openapi: 3.1.0
info:
  title: Code API (Public)
  version: 1.0.0
servers:
  - url: https://api.hybridbox.io
security: []
paths:
  /v1/public/accounts/{account_id}/auth/role-assignments:
    post:
      tags:
        - public-accounts
        - public-account-auth
      summary: 创建帐户角色分配
      description: 创建帐户范围的角色分配。
      operationId: >-
        create_public_account_role_assignment_v1_public_accounts__account_id__auth_role_assignments_post
      parameters:
        - in: path
          name: account_id
          required: true
          schema:
            format: uuid
            title: Account Id
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RoleAssignmentRequest'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RoleAssignmentResponse'
          description: ''
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: 验证错误
      security:
        - PublicBearerAuth: []
components:
  schemas:
    RoleAssignmentRequest:
      description: 用于创建新角色分配的请求架构。
      properties:
        resource_id:
          description: 分配范围资源标识符
          format: uuid
          title: 资源 ID
          type: string
        resource_type:
          $ref: '#/components/schemas/ResourceType'
          description: 分配范围资源类型
        role_key:
          $ref: '#/components/schemas/RoleKey'
          description: 代码定义的角色键
        subject_id:
          description: 用户、组或服务账号标识符
          minLength: 1
          title: 主体 ID
          type: string
        subject_type:
          $ref: '#/components/schemas/SubjectType'
          description: 角色分配主体类型：user、group 或 service_account
      required:
        - subject_type
        - subject_id
        - role_key
        - resource_type
        - resource_id
      title: RoleAssignmentRequest
      type: object
    RoleAssignmentResponse:
      properties:
        created_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: 创建时间
        expanded_capability_keys:
          items:
            type: string
          title: 扩展功能键
          type: array
        id:
          format: uuid
          title: ID
          type: string
        resource_id:
          format: uuid
          title: 资源 ID
          type: string
        resource_type:
          title: 资源类型
          type: string
        revoked_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: 撤销时间
        role_key:
          title: 角色关键
          type: string
        subject_id:
          title: 主体 ID
          type: string
        subject_type:
          title: 主体类型
          type: string
      required:
        - id
        - subject_type
        - subject_id
        - role_key
        - resource_type
        - resource_id
        - expanded_capability_keys
      title: RoleAssignmentResponse
      type: object
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: 详情
          type: array
      title: HTTPValidationError
      type: object
    ResourceType:
      description: 授权资源和作用域类型。
      enum:
        - client
        - account
        - workspace
        - domain
        - dns_record
        - mailbox
        - redirect
        - forwarding
        - credential
        - tenant
        - route
        - proxy
      title: ResourceType
      type: string
    RoleKey:
      description: 稳定的可重用角色标识符。
      enum:
        - viewer
        - editor
        - domain_manager
        - manager
        - dns_manager
        - ip_manager
        - billing_viewer
        - billing_admin
        - credential_manager
      title: RoleKey
      type: string
    SubjectType:
      description: 授权主体类型。
      enum:
        - user
        - group
        - service_account
      title: SubjectType
      type: string
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          title: 位置
          type: array
        msg:
          title: 消息
          type: string
        type:
          title: 错误类型
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
      type: object
  securitySchemes:
    PublicBearerAuth:
      bearerFormat: JWT or Hybridbox Service account token
      description: >-
        Public API bearer credential sent as `Authorization: Bearer <token>`.
        Use either an OAuth access token or a Hybridbox Service account token.
      scheme: bearer
      type: http

````