PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/attic/v1_registration_login.rst

https://gitlab.com/sim6/matrix-doc
ReStructuredText | 343 lines | 277 code | 66 blank | 0 comment | 0 complexity | f3e4f4a3a4f4574155c70b839cf7ad85 MD5 | raw file
  1. Registration and Login
  2. ----------------------
  3. Clients must register with a homeserver in order to use Matrix. After
  4. registering, the client will be given an access token which must be used in ALL
  5. requests to that homeserver as a query parameter 'access_token'.
  6. If the client has already registered, they need to be able to login to their
  7. account. The homeserver may provide many different ways of logging in, such as
  8. user/password auth, login via a social network (OAuth2), login by confirming a
  9. token sent to their email address, etc. This specification does not define how
  10. homeservers should authorise their users who want to login to their existing
  11. accounts, but instead defines the standard interface which implementations
  12. should follow so that ANY client can login to ANY homeserver. Clients login
  13. using the |login|_ API. Clients register using the |register|_ API.
  14. Registration follows the same general procedure as login, but the path requests
  15. are sent to and the details contained in them are different.
  16. In both registration and login cases, the process takes the form of one or more
  17. stages, where at each stage the client submits a set of data for a given stage
  18. type and awaits a response from the server, which will either be a final
  19. success or a request to perform an additional stage. This exchange continues
  20. until the final success.
  21. In order to determine up-front what the server's requirements are, the client
  22. can request from the server a complete description of all of its acceptable
  23. flows of the registration or login process. It can then inspect the list of
  24. returned flows looking for one for which it believes it can complete all of the
  25. required stages, and perform it. As each homeserver may have different ways of
  26. logging in, the client needs to know how they should login. All distinct login
  27. stages MUST have a corresponding ``type``. A ``type`` is a namespaced string
  28. which details the mechanism for logging in.
  29. A client may be able to login via multiple valid login flows, and should choose
  30. a single flow when logging in. A flow is a series of login stages. The home
  31. server MUST respond with all the valid login flows when requested by a simple
  32. ``GET`` request directly to the ``/login`` or ``/register`` paths::
  33. {
  34. "flows": [
  35. {
  36. "type": "<login type1a>",
  37. "stages": [ "<login type 1a>", "<login type 1b>" ]
  38. },
  39. {
  40. "type": "<login type2a>",
  41. "stages": [ "<login type 2a>", "<login type 2b>" ]
  42. },
  43. {
  44. "type": "<login type3>"
  45. }
  46. ]
  47. }
  48. The client can now select which flow it wishes to use, and begin making
  49. ``POST`` requests to the ``/login`` or ``/register`` paths with JSON body
  50. content containing the name of the stage as the ``type`` key, along with
  51. whatever additional parameters are required for that login or registration type
  52. (see below). After the flow is completed, the client's fully-qualified user
  53. ID and a new access token MUST be returned::
  54. {
  55. "user_id": "@user:matrix.org",
  56. "access_token": "abcdef0123456789"
  57. }
  58. The ``user_id`` key is particularly useful if the homeserver wishes to support
  59. localpart entry of usernames (e.g. "user" rather than "@user:matrix.org"), as
  60. the client may not be able to determine its ``user_id`` in this case.
  61. If the flow has multiple stages to it, the homeserver may wish to create a
  62. session to store context between requests. If a homeserver responds with a
  63. ``session`` key to a request, clients MUST submit it in subsequent requests
  64. until the flow is completed::
  65. {
  66. "session": "<session id>"
  67. }
  68. This specification defines the following login types:
  69. - ``m.login.password``
  70. - ``m.login.oauth2``
  71. - ``m.login.email.code``
  72. - ``m.login.email.url``
  73. - ``m.login.email.identity``
  74. Password-based
  75. ~~~~~~~~~~~~~~
  76. :Type:
  77. ``m.login.password``
  78. :Description:
  79. Login is supported via a username and password.
  80. To respond to this type, reply with::
  81. {
  82. "type": "m.login.password",
  83. "user": "<user_id or user localpart>",
  84. "password": "<password>"
  85. }
  86. The homeserver MUST respond with either new credentials, the next stage of the
  87. login process, or a standard error response.
  88. Captcha-based
  89. ~~~~~~~~~~~~~
  90. :Type:
  91. ``m.login.recaptcha``
  92. :Description:
  93. Login is supported by responding to a captcha (in the case of the Synapse
  94. implementation, Google's Recaptcha library is used).
  95. To respond to this type, reply with::
  96. {
  97. "type": "m.login.recaptcha",
  98. "challenge": "<challenge token>",
  99. "response": "<user-entered text>"
  100. }
  101. .. NOTE::
  102. In Synapse, the Recaptcha parameters can be obtained in Javascript by calling:
  103. Recaptcha.get_challenge();
  104. Recaptcha.get_response();
  105. The homeserver MUST respond with either new credentials, the next stage of the
  106. login process, or a standard error response.
  107. OAuth2-based
  108. ~~~~~~~~~~~~
  109. :Type:
  110. ``m.login.oauth2``
  111. :Description:
  112. Login is supported via OAuth2 URLs. This login consists of multiple requests.
  113. To respond to this type, reply with::
  114. {
  115. "type": "m.login.oauth2",
  116. "user": "<user_id or user localpart>"
  117. }
  118. The server MUST respond with::
  119. {
  120. "uri": <Authorization Request URI OR service selection URI>
  121. }
  122. The homeserver acts as a 'confidential' client for the purposes of OAuth2. If
  123. the uri is a ``sevice selection URI``, it MUST point to a webpage which prompts
  124. the user to choose which service to authorize with. On selection of a service,
  125. this MUST link through to an ``Authorization Request URI``. If there is only 1
  126. service which the homeserver accepts when logging in, this indirection can be
  127. skipped and the "uri" key can be the ``Authorization Request URI``.
  128. The client then visits the ``Authorization Request URI``, which then shows the
  129. OAuth2 Allow/Deny prompt. Hitting 'Allow' returns the ``redirect URI`` with the
  130. auth code. Homeservers can choose any path for the ``redirect URI``. The
  131. client should visit the ``redirect URI``, which will then finish the OAuth2
  132. login process, granting the homeserver an access token for the chosen service.
  133. When the homeserver gets this access token, it verifies that the cilent has
  134. authorised with the 3rd party, and can now complete the login. The OAuth2
  135. ``redirect URI`` (with auth code) MUST respond with either new credentials, the
  136. next stage of the login process, or a standard error response.
  137. For example, if a homeserver accepts OAuth2 from Google, it would return the
  138. Authorization Request URI for Google::
  139. {
  140. "uri": "https://accounts.google.com/o/oauth2/auth?response_type=code&
  141. client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&scope=photos"
  142. }
  143. The client then visits this URI and authorizes the homeserver. The client then
  144. visits the REDIRECT_URI with the auth code= query parameter which returns::
  145. {
  146. "user_id": "@user:matrix.org",
  147. "access_token": "0123456789abcdef"
  148. }
  149. Email-based (code)
  150. ~~~~~~~~~~~~~~~~~~
  151. :Type:
  152. ``m.login.email.code``
  153. :Description:
  154. Login is supported by typing in a code which is sent in an email. This login
  155. consists of multiple requests.
  156. To respond to this type, reply with::
  157. {
  158. "type": "m.login.email.code",
  159. "user": "<user_id or user localpart>",
  160. "email": "<email address>"
  161. }
  162. After validating the email address, the homeserver MUST send an email
  163. containing an authentication code and return::
  164. {
  165. "type": "m.login.email.code",
  166. "session": "<session id>"
  167. }
  168. The second request in this login stage involves sending this authentication
  169. code::
  170. {
  171. "type": "m.login.email.code",
  172. "session": "<session id>",
  173. "code": "<code in email sent>"
  174. }
  175. The homeserver MUST respond to this with either new credentials, the next
  176. stage of the login process, or a standard error response.
  177. Email-based (url)
  178. ~~~~~~~~~~~~~~~~~
  179. :Type:
  180. ``m.login.email.url``
  181. :Description:
  182. Login is supported by clicking on a URL in an email. This login consists of
  183. multiple requests.
  184. To respond to this type, reply with::
  185. {
  186. "type": "m.login.email.url",
  187. "user": "<user_id or user localpart>",
  188. "email": "<email address>"
  189. }
  190. After validating the email address, the homeserver MUST send an email
  191. containing an authentication URL and return::
  192. {
  193. "type": "m.login.email.url",
  194. "session": "<session id>"
  195. }
  196. The email contains a URL which must be clicked. After it has been clicked, the
  197. client should perform another request::
  198. {
  199. "type": "m.login.email.url",
  200. "session": "<session id>"
  201. }
  202. The homeserver MUST respond to this with either new credentials, the next
  203. stage of the login process, or a standard error response.
  204. A common client implementation will be to periodically poll until the link is
  205. clicked. If the link has not been visited yet, a standard error response with
  206. an errcode of ``M_LOGIN_EMAIL_URL_NOT_YET`` should be returned.
  207. Email-based (identity server)
  208. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209. :Type:
  210. ``m.login.email.identity``
  211. :Description:
  212. Login is supported by authorising an email address with an identity server.
  213. Prior to submitting this, the client should authenticate with an identity
  214. server. After authenticating, the session information should be submitted to
  215. the homeserver.
  216. To respond to this type, reply with::
  217. {
  218. "type": "m.login.email.identity",
  219. "threepidCreds": [
  220. {
  221. "sid": "<identity server session id>",
  222. "clientSecret": "<identity server client secret>",
  223. "idServer": "<url of identity server authed with, e.g. 'matrix.org:8090'>"
  224. }
  225. ]
  226. }
  227. N-Factor Authentication
  228. ~~~~~~~~~~~~~~~~~~~~~~~
  229. Multiple login stages can be combined to create N-factor authentication during
  230. login.
  231. This can be achieved by responding with the ``next`` login type on completion
  232. of a previous login stage::
  233. {
  234. "next": "<next login type>"
  235. }
  236. If a homeserver implements N-factor authentication, it MUST respond with all
  237. ``stages`` when initially queried for their login requirements::
  238. {
  239. "type": "<1st login type>",
  240. "stages": [ <1st login type>, <2nd login type>, ... , <Nth login type> ]
  241. }
  242. This can be represented conceptually as::
  243. _______________________
  244. | Login Stage 1 |
  245. | type: "<login type1>" |
  246. | ___________________ |
  247. | |_Request_1_________| | <-- Returns "session" key which is used throughout.
  248. | ___________________ |
  249. | |_Request_2_________| | <-- Returns a "next" value of "login type2"
  250. |_______________________|
  251. |
  252. |
  253. _________V_____________
  254. | Login Stage 2 |
  255. | type: "<login type2>" |
  256. | ___________________ |
  257. | |_Request_1_________| |
  258. | ___________________ |
  259. | |_Request_2_________| |
  260. | ___________________ |
  261. | |_Request_3_________| | <-- Returns a "next" value of "login type3"
  262. |_______________________|
  263. |
  264. |
  265. _________V_____________
  266. | Login Stage 3 |
  267. | type: "<login type3>" |
  268. | ___________________ |
  269. | |_Request_1_________| | <-- Returns user credentials
  270. |_______________________|
  271. Fallback
  272. ~~~~~~~~
  273. Clients cannot be expected to be able to know how to process every single login
  274. type. If a client determines it does not know how to handle a given login type,
  275. it should request a login fallback page::
  276. GET matrix/client/api/v1/login/fallback
  277. This MUST return an HTML page which can perform the entire login process.