oidc-prepare-authentication-api.asciidoc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. [role="xpack"]
  2. [[security-api-oidc-prepare-authentication]]
  3. === OpenID Connect prepare authentication API
  4. ++++
  5. <titleabbrev>OpenID Connect prepare authentication</titleabbrev>
  6. ++++
  7. .New API reference
  8. [sidebar]
  9. --
  10. For the most up-to-date API details, refer to {api-es}/group/endpoint-security[Security APIs].
  11. --
  12. Creates an oAuth 2.0 authentication request as a URL string based on the
  13. configuration of the respective OpenID Connect authentication realm in {es}.
  14. [[security-api-oidc-prepare-authentication-request]]
  15. ==== {api-request-title}
  16. `POST /_security/oidc/prepare`
  17. //[[security-api-oidc-prepare-authentication-prereqs]]
  18. //==== {api-prereq-title}
  19. [[security-api-oidc-prepare-authentication-desc]]
  20. ==== {api-description-title}
  21. The response of this API is a URL pointing to the Authorization Endpoint of the
  22. configured OpenID Connect Provider and can be used to redirect the browser of
  23. the user in order to continue the authentication process.
  24. {es} exposes all the necessary OpenID Connect related functionality via the
  25. OpenID Connect APIs. These APIs are used internally by {kib} in order to provide
  26. OpenID Connect based authentication, but can also be used by other, custom web
  27. applications or other clients. See also
  28. <<security-api-oidc-authenticate,OpenID Connect authenticate API>>
  29. and <<security-api-oidc-logout,OpenID Connect logout API>>.
  30. [[security-api-oidc-prepare-authentication-request-body]]
  31. ==== {api-request-body-title}
  32. The following parameters can be specified in the body of the request:
  33. `realm`::
  34. (Optional, string) The name of the OpenID Connect realm in {es} the configuration of which should
  35. be used in order to generate the authentication request. Cannot be specified
  36. when `iss` is specified. One of `realm`, `iss` is required.
  37. `state`::
  38. (Optional, string) Value used to maintain state between the authentication request and the
  39. response, typically used as a Cross-Site Request Forgery mitigation. If the
  40. caller of the API doesn't provide a value, {es} will generate one with
  41. sufficient entropy itself and return it in the response.
  42. `nonce`::
  43. (Optional, string) Value used to associate a Client session with an ID Token and to mitigate
  44. replay attacks. If the caller of the API doesn't provide a value, {es} will
  45. generate one with sufficient entropy itself and return it in the response.
  46. `iss`::
  47. (Optional, string) In the case of a 3rd Party initiated Single Sign On, this is the Issuer
  48. Identifier for the OP that the RP is to send the Authentication Request to.
  49. Cannot be specified when `realm` is specified. One of `realm`, `iss` is required.
  50. `login_hint`::
  51. (Optional, string) In the case of a 3rd Party initiated Single Sign On, a string value to be
  52. included in the authentication request, as the `login_hint` parameter. This
  53. parameter is not valid when `realm` is specified
  54. [[security-api-oidc-prepare-authentication-example]]
  55. ==== {api-examples-title}
  56. The following example generates an authentication request for the OpenID Connect
  57. Realm `oidc1`:
  58. [source,console]
  59. --------------------------------------------------
  60. POST /_security/oidc/prepare
  61. {
  62. "realm" : "oidc1"
  63. }
  64. --------------------------------------------------
  65. The following example output of the response contains the URI pointing to the Authorization Endpoint of the OpenID Connect Provider with all the parameters of
  66. the Authentication Request, as HTTP GET parameters:
  67. [source,console-result]
  68. --------------------------------------------------
  69. {
  70. "redirect" : "http://127.0.0.1:8080/c2id-login?scope=openid&response_type=id_token&redirect_uri=https%3A%2F%2Fmy.fantastic.rp%2Fcb&state=4dbrihtIAt3wBTwo6DxK-vdk-sSyDBV8Yf0AjdkdT5I&nonce=WaBPH0KqPVdG5HHdSxPRjfoZbXMCicm5v1OiAj0DUFM&client_id=elasticsearch-rp",
  71. "state" : "4dbrihtIAt3wBTwo6DxK-vdk-sSyDBV8Yf0AjdkdT5I",
  72. "nonce" : "WaBPH0KqPVdG5HHdSxPRjfoZbXMCicm5v1OiAj0DUFM",
  73. "realm" : "oidc1"
  74. }
  75. --------------------------------------------------
  76. // TESTRESPONSE[s/http:.*elasticsearch-rp/\$\{body.redirect\}/]
  77. // TESTRESPONSE[s/4dbrihtIAt3wBTwo6DxK-vdk-sSyDBV8Yf0AjdkdT5I/\$\{body.state\}/]
  78. // TESTRESPONSE[s/WaBPH0KqPVdG5HHdSxPRjfoZbXMCicm5v1OiAj0DUFM/\$\{body.nonce\}/]
  79. The following example generates an authentication request for the OpenID Connect
  80. Realm `oidc1`, where the values for the state and the nonce have been generated
  81. by the client:
  82. [source,console]
  83. --------------------------------------------------
  84. POST /_security/oidc/prepare
  85. {
  86. "realm" : "oidc1",
  87. "state" : "lGYK0EcSLjqH6pkT5EVZjC6eIW5YCGgywj2sxROO",
  88. "nonce" : "zOBXLJGUooRrbLbQk5YCcyC8AXw3iloynvluYhZ5"
  89. }
  90. --------------------------------------------------
  91. The following example output of the response contains the URI pointing to the Authorization Endpoint of the OpenID Connect Provider with all the parameters of
  92. the Authentication Request, as HTTP GET parameters:
  93. [source,console-result]
  94. --------------------------------------------------
  95. {
  96. "redirect" : "http://127.0.0.1:8080/c2id-login?scope=openid&response_type=id_token&redirect_uri=https%3A%2F%2Fmy.fantastic.rp%2Fcb&state=lGYK0EcSLjqH6pkT5EVZjC6eIW5YCGgywj2sxROO&nonce=zOBXLJGUooRrbLbQk5YCcyC8AXw3iloynvluYhZ5&client_id=elasticsearch-rp",
  97. "state" : "lGYK0EcSLjqH6pkT5EVZjC6eIW5YCGgywj2sxROO",
  98. "nonce" : "zOBXLJGUooRrbLbQk5YCcyC8AXw3iloynvluYhZ5",
  99. "realm" : "oidc1"
  100. }
  101. --------------------------------------------------
  102. // TESTRESPONSE[s/http:.*elasticsearch-rp/\$\{body.redirect\}/]
  103. The following example generates an authentication request for a 3rd party
  104. initiated single sign on, specifying the issuer that should be used for matching
  105. the appropriate OpenID Connect Authentication realm:
  106. [source,console]
  107. --------------------------------------------------
  108. POST /_security/oidc/prepare
  109. {
  110. "iss" : "http://127.0.0.1:8080",
  111. "login_hint": "this_is_an_opaque_string"
  112. }
  113. --------------------------------------------------
  114. The following example output of the response contains the URI pointing to the Authorization Endpoint of the OpenID Connect Provider with all the parameters of
  115. the Authentication Request, as HTTP GET parameters:
  116. [source,console-result]
  117. --------------------------------------------------
  118. {
  119. "redirect" : "http://127.0.0.1:8080/c2id-login?login_hint=this_is_an_opaque_string&scope=openid&response_type=id_token&redirect_uri=https%3A%2F%2Fmy.fantastic.rp%2Fcb&state=4dbrihtIAt3wBTwo6DxK-vdk-sSyDBV8Yf0AjdkdT5I&nonce=WaBPH0KqPVdG5HHdSxPRjfoZbXMCicm5v1OiAj0DUFM&client_id=elasticsearch-rp",
  120. "state" : "4dbrihtIAt3wBTwo6DxK-vdk-sSyDBV8Yf0AjdkdT5I",
  121. "nonce" : "WaBPH0KqPVdG5HHdSxPRjfoZbXMCicm5v1OiAj0DUFM",
  122. "realm" : "oidc1"
  123. }
  124. --------------------------------------------------
  125. // TESTRESPONSE[s/4dbrihtIAt3wBTwo6DxK-vdk-sSyDBV8Yf0AjdkdT5I/\$\{body.state\}/]
  126. // TESTRESPONSE[s/WaBPH0KqPVdG5HHdSxPRjfoZbXMCicm5v1OiAj0DUFM/\$\{body.nonce\}/]