FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    How to search all users with entity grant for an entity?

    Scheduled Pinned Locked Moved
    General Discussion
    2
    3
    1.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      didier
      last edited by

      By api, I can search for entity grants for one user.
      By api, I can search for entity grants for one entity (return entity grants for this entity on other entities).

      But, I do not know how to search all users entity grant for one entity. Can I use an elastic search to do it?

      A 1 Reply Last reply Reply Quote 0
      • A
        Alex Patterson @didier
        last edited by

        @didier just want to make sure my head is in the right place for what you are looking for

        You can query for entities

        curl -v -H 'Authorization: xHDJZOeZ3fbWmUxnx0vw2gNpyIXEcRfVQ-AnXcNo7_IzL5EM4kFBO2VC' \
             'https://local.fusionauth.io/api/entity/search?queryString=name:*entity*'
        

        Result

        {
            "entities": [
                {
                    "clientId": "e3efa4bc-516b-4bf5-bb3e-9eb8aba62a61",
                    "clientSecret": "3fqDmUNpn7ZvesvBaiejHGoSyCDyrhlcy7MOOmLWdRI",
                    "data": {},
                    "id": "e3efa4bc-516b-4bf5-bb3e-9eb8aba62a61",
                    "insertInstant": 1715351523408,
                    "lastUpdateInstant": 1715351523408,
                    "name": "entity1",
                    "tenantId": "1c7aee2d-29c5-a4a7-c48f-91e56a777ea0",
                    "type": {
                        "data": {},
                        "id": "00c934d5-15b8-4bbf-a8cd-01b9ad048ae5",
                        "insertInstant": 1715351513399,
                        "jwtConfiguration": {
                            "enabled": false,
                            "timeToLiveInSeconds": 60
                        },
                        "lastUpdateInstant": 1715351513399,
                        "name": "alex-entity-type",
                        "permissions": [
                            {
                                "data": {},
                                "id": "0fe89220-0fd4-4f30-b127-1b23c9f6b75a",
                                "insertInstant": 1715351513400,
                                "isDefault": false,
                                "lastUpdateInstant": 1715351513400,
                                "name": "ALex"
                            }
                        ]
                    }
                },
                {
                    "clientId": "48d8814f-1914-4a3d-9a55-3db4e34ba24d",
                    "clientSecret": "L9gT2dHHtEFS7-TBRIvRyKtnaV2Qu-oWP2aJKrQjgzk",
                    "data": {},
                    "id": "48d8814f-1914-4a3d-9a55-3db4e34ba24d",
                    "insertInstant": 1715351532089,
                    "lastUpdateInstant": 1715351532089,
                    "name": "entity2",
                    "tenantId": "1c7aee2d-29c5-a4a7-c48f-91e56a777ea0",
                    "type": {
                        "data": {},
                        "id": "00c934d5-15b8-4bbf-a8cd-01b9ad048ae5",
                        "insertInstant": 1715351513399,
                        "jwtConfiguration": {
                            "enabled": false,
                            "timeToLiveInSeconds": 60
                        },
                        "lastUpdateInstant": 1715351513399,
                        "name": "alex-entity-type",
                        "permissions": [
                            {
                                "data": {},
                                "id": "0fe89220-0fd4-4f30-b127-1b23c9f6b75a",
                                "insertInstant": 1715351513400,
                                "isDefault": false,
                                "lastUpdateInstant": 1715351513400,
                                "name": "ALex"
                            }
                        ]
                    }
                }
            ],
            "nextResults": "eyJscyI6WyIxLjI4NzY4MiIsImVudGl0eTIiLCI0OGQ4ODE0Zi0xOTE0LTRhM2QtOWE1NS0zZGI0ZTM0YmEyNGQiXSwicXMiOiJuYW1lOiplbnRpdHkqIn0",
            "total": 2
        }
        

        Then any/all entities that you want to get grants for you can call

        curl -v -H 'Authorization: xHDJZOeZ3fbWmUxnx0vw2gNpyIXEcRfVQ-AnXcNo7_IzL5EM4kFBO2VC' \
             'https://local.fusionauth.io/api/entity/e3efa4bc-516b-4bf5-bb3e-9eb8aba62a61/grant'
        

        Result gives you back all associated users that have this granted.

        {
            "grants": [
                {
                    "data": {},
                    "entity": {
                        "clientId": "e3efa4bc-516b-4bf5-bb3e-9eb8aba62a61",
                        "clientSecret": "3fqDmUNpn7ZvesvBaiejHGoSyCDyrhlcy7MOOmLWdRI",
                        "data": {},
                        "id": "e3efa4bc-516b-4bf5-bb3e-9eb8aba62a61",
                        "insertInstant": 1715351523408,
                        "lastUpdateInstant": 1715351523408,
                        "name": "entity1",
                        "tenantId": "1c7aee2d-29c5-a4a7-c48f-91e56a777ea0",
                        "type": {
                            "data": {},
                            "id": "00c934d5-15b8-4bbf-a8cd-01b9ad048ae5",
                            "insertInstant": 1715351513399,
                            "jwtConfiguration": {
                                "enabled": false,
                                "timeToLiveInSeconds": 60
                            },
                            "lastUpdateInstant": 1715351513399,
                            "name": "alex-entity-type",
                            "permissions": [
                                {
                                    "data": {},
                                    "id": "0fe89220-0fd4-4f30-b127-1b23c9f6b75a",
                                    "insertInstant": 1715351513400,
                                    "isDefault": false,
                                    "lastUpdateInstant": 1715351513400,
                                    "name": "ALex"
                                }
                            ]
                        }
                    },
                    "id": "e87a00c3-e116-464d-83d3-cdfde0e27efc",
                    "insertInstant": 1715353110056,
                    "lastUpdateInstant": 1715353110056,
                    "permissions": [
                        "ALex"
                    ],
                    "userId": "847506b4-186e-4ee0-be24-e87c579a8625"
                },
                {
                    "data": {},
                    "entity": {
                        "clientId": "e3efa4bc-516b-4bf5-bb3e-9eb8aba62a61",
                        "clientSecret": "3fqDmUNpn7ZvesvBaiejHGoSyCDyrhlcy7MOOmLWdRI",
                        "data": {},
                        "id": "e3efa4bc-516b-4bf5-bb3e-9eb8aba62a61",
                        "insertInstant": 1715351523408,
                        "lastUpdateInstant": 1715351523408,
                        "name": "entity1",
                        "tenantId": "1c7aee2d-29c5-a4a7-c48f-91e56a777ea0",
                        "type": {
                            "data": {},
                            "id": "00c934d5-15b8-4bbf-a8cd-01b9ad048ae5",
                            "insertInstant": 1715351513399,
                            "jwtConfiguration": {
                                "enabled": false,
                                "timeToLiveInSeconds": 60
                            },
                            "lastUpdateInstant": 1715351513399,
                            "name": "alex-entity-type",
                            "permissions": [
                                {
                                    "data": {},
                                    "id": "0fe89220-0fd4-4f30-b127-1b23c9f6b75a",
                                    "insertInstant": 1715351513400,
                                    "isDefault": false,
                                    "lastUpdateInstant": 1715351513400,
                                    "name": "ALex"
                                }
                            ]
                        }
                    },
                    "id": "6c2cced6-22a9-49c9-984c-e55b47d6a5a5",
                    "insertInstant": 1715351571320,
                    "lastUpdateInstant": 1715351571320,
                    "permissions": [
                        "ALex"
                    ],
                    "userId": "556e3f28-b9fe-4c62-bd6e-02ef3dec1c43"
                }
            ]
        }
        

        Would that work?

        1 Reply Last reply Reply Quote 0
        • D
          didier
          last edited by

          Ok. I see "userId" property. Not easy to undertand !

          1 Reply Last reply Reply Quote 0
          • First post
            Last post