# Complement Token Flow

This flow is executed during the creation of tokens and token introspection.

The flow is represented by the following Ids in the API: `2`

## [Pre Userinfo creation (id_token / userinfo / introspection endpoint)](/content/docs/apis/actions/complement-token#pre-userinfo-creation-id-token-userinfo-introspection-endpoint/index.html)

This trigger is called before userinfo are set in the id_token or userinfo and introspection endpoint response.

The trigger is represented by the following Ids in the API: `4`

### [Parameters of Pre Userinfo creation](/content/docs/apis/actions/complement-token#parameters-of-pre-userinfo-creation/index.html)

- `ctx`
  The first parameter contains the following fields:
  - `v1`
    - `claims` [_Claims_](/content/docs/apis/actions/objects#claims/index.html)
    - `getUser()` [_User_](/content/docs/apis/actions/objects#user/index.html)
    - `user`
      - `getMetadata()` [_metadataResult_](/content/docs/apis/actions/objects#metadata-result/index.html)
      - `grants` [_UserGrantList_](/content/docs/apis/actions/objects#user-grant-list/index.html)
    - `org`
      - `getMetadata()` [_metadataResult_](/content/docs/apis/actions/objects#metadata-result/index.html)
    - `application`
      - `getClientId()` _string_
        The client id of the application the token was requested for
    - `actor` [_token actor_](/content/docs/apis/actions/objects#token-actor/index.html)
      The party which obtained the token on behalf of the user, `null` unless the token was obtained through token exchange or impersonation
- `api`
  The second parameter contains the following fields:
  - `v1`
    - `userinfo`
      This function is deprecated, please use `api.v1.claims`
      - `setClaim(string, Any)`
        Sets any value if the key is not already present. If it's already present there is a message added to `urn:zitadel:iam:action:${action.name}:log`
        Note that keys with prefix `urn:zitadel:iam` will be ignored.
    - `claims`
      - `setClaim(string, Any)`
        Sets any value if the key is not already present. If it's already present there is a message added to `urn:zitadel:iam:action:${action.name}:log`
        Note that keys with prefix `urn:zitadel:iam` will be ignored.
    - `user`
      - `setMetadata(string, Any)`
        Key of the metadata and any value

## [Pre access token creation](/content/docs/apis/actions/complement-token#pre-access-token-creation/index.html)

This trigger is called before the claims are set in the access token and the token type is `jwt`.

The trigger is represented by the following Ids in the API: `5`

### [Parameters of Pre access token creation](/content/docs/apis/actions/complement-token#parameters-of-pre-access-token-creation/index.html)
