oidc-prepare-authentication-api.asciidoc 6.5 KB

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