Skip to content

Support PATCH for identities #2380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
frederikhors opened this issue Apr 8, 2022 · 17 comments · Fixed by #2471
Closed
3 tasks done

Support PATCH for identities #2380

frederikhors opened this issue Apr 8, 2022 · 17 comments · Fixed by #2471
Labels
feat New feature or request. good first issue A good issue to tackle when being a novice to the project.

Comments

@frederikhors
Copy link
Contributor

frederikhors commented Apr 8, 2022

Preflight checklist

  • I could not find a solution in the existing issues, docs, nor discussions.
  • I agree to follow this project's Code of Conduct.
  • I have read and am following this repository's Contribution Guidelines.

Describe your problem

I think it sholud be possible to use adminUpdateIdentity without passing a traits object in it (or a nil).

I'm using it only to change state of the identity (active/inactive).

Is there another way?

Version

0.9.0-alpha.3

@frederikhors frederikhors added the feat New feature or request. label Apr 8, 2022
@aeneasr
Copy link
Member

aeneasr commented Apr 8, 2022

Using PUT (update) requires you to send the full identity as it replaces all of the contents. We do not support PATCH yet but it would be a good idea to add it and support updating only individual fields

@aeneasr aeneasr changed the title API: adminUpdateIdentity with nil traits or nothing Support PATCH for identities Apr 8, 2022
@aeneasr aeneasr added the good first issue A good issue to tackle when being a novice to the project. label Apr 8, 2022
@renom
Copy link

renom commented Jun 8, 2022

Supporting JSON Patch would be useful for updating arrays in an identity. Could it be added too?

@jonas-jonas
Copy link
Member

@zepatrik JSON Patch might be a good solution for "merging" traits, as we talked about in #2380. I would even say it might be in scope of the existing PR, and I would be willing to take a look at it over there. There are Golang SDKs available: https://jsonpatch.com/#go WDYT?

@aeneasr
Copy link
Member

aeneasr commented Jun 9, 2022

We have PATCH support in Hydra already, we can for sure just copy the approach :)

https://github.com/ory/hydra/blob/5a753234bea813f875869d5dd9042dc96482e3ef/client/handler.go#L343

@frederikhors
Copy link
Contributor Author

@aeneasr
Copy link
Member

aeneasr commented Oct 5, 2022

Hope this fixes it: #2784

@frederikhors
Copy link
Contributor Author

I still cannot see it in docs page:

image

@aeneasr
Copy link
Member

aeneasr commented Oct 5, 2022

It is not yet released, only merged

@frederikhors
Copy link
Contributor Author

Ok. Sorry.

@renom
Copy link

renom commented Jan 9, 2023

Is there no way to patch the identity with HTTP API from frontend at the moment?

@aeneasr
Copy link
Member

aeneasr commented Jan 10, 2023

This has long been released

@renom
Copy link

renom commented Feb 7, 2023

This has long been released

I mean a use-case when a logged in user patches their own identity.

@renom
Copy link

renom commented Feb 7, 2023

Patching metadata_admin doesn't work.

Request:

GET http://server_url/admin/identities/identity_id

Response:

{
    "id": "identity_id",
    "credentials": {
        // credentials data
    },
    "schema_id": "default",
    "schema_url": "http://schema_url",
    "state": "active",
    "state_changed_at": "2023-02-07T12:38:46.777687Z",
    "traits": {},
    "metadata_public": {},
    "metadata_admin": {},
    "created_at": "2023-02-07T12:38:46.781842Z",
    "updated_at": "2023-02-07T12:38:46.781842Z"
}

Request:

PATCH http://server_url/admin/identities/identity_id
[
  { "op": "add", "path": "/metadata_admin/field1", "value": "value1" }
]

Response:

{
    "error": {
        "code": 400,
        "status": "Bad Request",
        "reason": "add operation does not apply: doc is missing path: \"/metadata_admin/field1\": missing value",
        "message": "The request was malformed or contained invalid parameters"
    }
}

@renom
Copy link

renom commented Feb 7, 2023

An extra example.

Request:

GET http://server_url/admin/identities/identity_id

Response:

{
    "id": "identity_id",
    "credentials": {
        // credentials data
    },
    "schema_id": "default",
    "schema_url": "http://schema_url",
    "state": "active",
    "state_changed_at": "2023-02-07T12:38:46.777687Z",
    "traits": {},
    "metadata_public": {},
    "metadata_admin": {
        "field1": ""
    },
    "created_at": "2023-02-07T12:38:46.781842Z",
    "updated_at": "2023-02-07T12:38:46.781842Z"
}

Request:

PATCH http://server_url/admin/identities/identity_id
[
  { "op": "add", "path": "/metadata_admin/field1", "value": "value1" }
]

Response:

{
    "error": {
        "code": 400,
        "status": "Bad Request",
        "reason": "add operation does not apply: doc is missing path: \"/metadata_admin/field1\": missing value",
        "message": "The request was malformed or contained invalid parameters"
    }
}

@renom
Copy link

renom commented Feb 7, 2023

Request:

GET http://server_url/admin/identities/identity_id

Response:

{
    "id": "identity_id",
    "credentials": {
        // credentials data
    },
    "schema_id": "default",
    "schema_url": "http://schema_url",
    "state": "active",
    "state_changed_at": "2023-02-07T12:38:46.777687Z",
    "traits": {},
    "metadata_public": {},
    "metadata_admin": {
        "field1": ""
    },
    "created_at": "2023-02-07T12:38:46.781842Z",
    "updated_at": "2023-02-07T12:38:46.781842Z"
}

Request:

PATCH http://server_url/admin/identities/identity_id
[
  { "op": "replace", "path": "/metadata_admin/field1", "value": "value1" }
]

Response:

{
    "error": {
        "code": 400,
        "status": "Bad Request",
        "reason": "replace operation does not apply: doc is missing path: /metadata_admin/field1: missing value",
        "message": "The request was malformed or contained invalid parameters"
    }
}

@renom
Copy link

renom commented Feb 7, 2023

Similar requests for metadata_public work fine.

peturgeorgievv pushed a commit to senteca/kratos-fork that referenced this issue Jun 30, 2023
@reginbald
Copy link

Patching a field in metadata_public works but the identity returned doesn't include the change, metadata_public is null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request. good first issue A good issue to tackle when being a novice to the project.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants