oidc-prepare-authentication-api.asciidoc 6.3 KB

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