When using Descope’s SDK to create an access key, ...
# ask-a-descoper
a
When using Descope’s SDK to create an access key, the corresponding audit event is generated with an
actorId
equal to the management key ID, and no
userId
is included. Is there a way to attach a custom field to the access key-such as the creator’s user ID or email - so that this information is populated as the
userId
in the
AccessKeyCreated
audit event?
n
Hey Aviya, Are you currently creating access keys from an SDK or within the console?
a
from an SDK
n
You can bind an access key to a user ID upon creation, so that any actions performed with that key are authorized as that user. The key is also affected if the user is disabled or deleted. Doc: https://docs.descope.com/management/m2m-access-keys/sdks#create-access-key
a
great, I will try to do that. thanks
@Nick Rodriguez Hi, I’ve tried binding the access key to a user by specifying the
userId
during creation, but it seems that no matter what I do, the access key is still being created under the management key identity rather than my own user identity. The resulting access key and its exchanged JWT always reflect the management key ID instead of the user who created it. This is the example for creating the access key:
Copy code
curl -X POST "https://api.descope.com/v1/mgmt/accesskey/create" \
  -H "Authorization: Bearer projectID:ManagementKey" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "test1",
    "keyTenants": [
      {
        "tenantId": "tenant1",
        "roleNames": [
          "role1",
          "role2"
        ]
      }
    ],
    "userId": "U2yb5hag6x5uzp38eeDlhGFUUnyz",
    "customClaims": {
      "email": "aviya@valkyrie.io"
    },
    "permittedIps": []
  }'
the access key that created, is bound to the created_by :
K35k8ROmlxlHkwoqjjNBoK5nSx9d
id, which is not my userId. After that, on the audit page I get no value for the
Access Key Created
event*.*
@Rahul Rijhwani can you help please? I see you are online
a
What is K35k8ROmlxlHkwoqjjNBoK5nSx9d ? It's not a user id. userIds start with a U
a
this is a management key id
a
@Aviya Baumgarten created by and bound user are 2 different attributes of the access key Using a MGMT key the
createdBy
will always be the mgmt key id that created this key The
Bound UserName
will be the correct user that this key is bound to
a
great, but I want the related audit event to show the userId created the access key. In order to do so what should I put on the access key creation call?
a
The access key is created by a management key So this is what created it We don't have that notion if created by api If it will be created via our widgets I think you will see the correct data you are after
a
ok, thanks