get-user-profile.asciidoc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. [role="xpack"]
  2. [[security-api-get-user-profile]]
  3. === Get user profiles API
  4. ++++
  5. <titleabbrev>Get user profiles</titleabbrev>
  6. ++++
  7. NOTE: The user profile feature is designed only for use by {kib} and
  8. Elastic’s {observability}, {ents}, and {elastic-sec} solutions. Individual
  9. users and external applications should not call this API directly. Elastic reserves
  10. the right to change or remove this feature in future releases without prior notice.
  11. Retrieves user profiles using a list of unique profile ID.
  12. [[security-api-get-user-profile-request]]
  13. ==== {api-request-title}
  14. `GET /_security/profile/<uid>`
  15. [[security-api-get-user-profile-prereqs]]
  16. ==== {api-prereq-title}
  17. To use this API, you must have _at least_ the `read_security`
  18. <<privileges-list-cluster,cluster privilege>> (or a greater privilege
  19. such as `manage_user_profile` or `manage_security`).
  20. [[security-api-get-user-profile-desc]]
  21. ==== {api-description-title}
  22. The get user profile API returns the user profile document matching a specified
  23. `uid`, which is generated when
  24. <<security-api-activate-user-profile,activating a user profile>>.
  25. [[security-api-get-user-profile-path-params]]
  26. ==== {api-path-parms-title}
  27. `uid`::
  28. (Required, string) The unique identifier for the user profile. You can specify multiple IDs as
  29. a comma-separated list.
  30. [[security-api-get-user-profile-query-params]]
  31. ==== {api-query-parms-title}
  32. `data`::
  33. (Optional, string) Comma-separated list of filters for the `data` field of
  34. the profile document. To return all content, use `data=*`. To return a
  35. subset of content, use `data=<key>` to retrieve the content nested under the
  36. specified `<key>`. Defaults to returning no content.
  37. [[security-api-get-user-profile-response-body]]
  38. ==== {api-response-body-title}
  39. A successful call returns the JSON representation of the user profile
  40. and its internal versioning numbers. The API returns an empty object
  41. if no profile document is found for the provided `uid`.
  42. The content of the `data` field is not returned by default to avoid deserializing
  43. a potential large payload.
  44. [[security-api-get-user-profile-example]]
  45. ==== {api-examples-title}
  46. [source,console]
  47. ----
  48. GET /_security/profile/u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0
  49. ----
  50. // TEST[setup:user_profiles]
  51. The API returns the following response for a `uid` matching `u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0`:
  52. [source,console-result]
  53. ----
  54. {
  55. "profiles": [
  56. {
  57. "uid": "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0",
  58. "enabled": true,
  59. "last_synchronized": 1642650651037,
  60. "user": {
  61. "username": "jacknich",
  62. "roles": [
  63. "admin", "other_role1"
  64. ],
  65. "realm_name": "native",
  66. "full_name": "Jack Nicholson",
  67. "email": "jacknich@example.com"
  68. },
  69. "labels": {
  70. "direction": "north"
  71. },
  72. "data": {}, <1>
  73. "_doc": {
  74. "_primary_term": 88,
  75. "_seq_no": 66
  76. }
  77. }
  78. ]
  79. }
  80. ----
  81. // TESTRESPONSE[s/1642650651037/$body.profiles.0.last_synchronized/]
  82. // TESTRESPONSE[s/88/$body.profiles.0._doc._primary_term/]
  83. // TESTRESPONSE[s/66/$body.profiles.0._doc._seq_no/]
  84. <1> No content is returned in the `data` field by default.
  85. The following request retrieves a subset of `data` that's nested under the
  86. key `app1`, along with the user's profile:
  87. [source,console]
  88. ----
  89. GET /_security/profile/u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0?data=app1.key1
  90. ----
  91. // TEST[continued]
  92. [source,console-result]
  93. ----
  94. {
  95. "profiles": [
  96. {
  97. "uid": "u_79HkWkwmnBH5gqFKwoxggWPjEBOur1zLPXQPEl1VBW0_0",
  98. "enabled": true,
  99. "last_synchronized": 1642650651037,
  100. "user": {
  101. "username": "jacknich",
  102. "roles": [
  103. "admin", "other_role1"
  104. ],
  105. "realm_name": "native",
  106. "full_name": "Jack Nicholson",
  107. "email": "jacknich@example.com"
  108. },
  109. "labels": {
  110. "direction": "north"
  111. },
  112. "data": {
  113. "app1": {
  114. "key1": "value1"
  115. }
  116. },
  117. "_doc": {
  118. "_primary_term": 88,
  119. "_seq_no": 66
  120. }
  121. }
  122. ]
  123. }
  124. ----
  125. // TESTRESPONSE[s/1642650651037/$body.profiles.0.last_synchronized/]
  126. // TESTRESPONSE[s/88/$body.profiles.0._doc._primary_term/]
  127. // TESTRESPONSE[s/66/$body.profiles.0._doc._seq_no/]
  128. If there has been any errors when retrieving the user profiles, they are returned in the `errors` field:
  129. [source,js]
  130. --------------------------------------------------
  131. {
  132. "profiles": [],
  133. "errors": {
  134. "count": 1,
  135. "details": {
  136. "u_FmxQt3gr1BBH5wpnz9HkouPj3Q710XkOgg1PWkwLPBW_5": {
  137. "type": "resource_not_found_exception",
  138. "reason": "profile document not found"
  139. }
  140. }
  141. }
  142. }
  143. --------------------------------------------------
  144. // NOTCONSOLE