Mercurial > prosody-modules
comparison mod_http_oauth2/README.md @ 5975:fe081789f7b5
All community modules: Unify file extention of Markdown files to .md
| author | Menel <menel@snikket.de> |
|---|---|
| date | Tue, 22 Oct 2024 10:26:01 +0200 |
| parents | mod_http_oauth2/README.markdown@761142ee0ff2 |
| children | ab14e7ecb82f |
comparison
equal
deleted
inserted
replaced
| 5974:5a65a632d5b9 | 5975:fe081789f7b5 |
|---|---|
| 1 --- | |
| 2 labels: | |
| 3 - Stage-Alpha | |
| 4 rockspec: | |
| 5 build: | |
| 6 copy_directories: | |
| 7 - html | |
| 8 summary: OAuth 2.0 Authorization Server API | |
| 9 --- | |
| 10 | |
| 11 ## Introduction | |
| 12 | |
| 13 This module implements an [OAuth2](https://oauth.net/2/)/[OpenID Connect | |
| 14 (OIDC)](https://openid.net/connect/) Authorization Server on top of | |
| 15 Prosody's usual internal authentication backend. | |
| 16 | |
| 17 OAuth and OIDC are web standards that allow you to provide clients and | |
| 18 third-party applications limited access to your account, without sharing your | |
| 19 password with them. | |
| 20 | |
| 21 With this module deployed, software that supports OAuth can obtain | |
| 22 "access tokens" from Prosody which can then be used to connect to XMPP | |
| 23 accounts using the [OAUTHBEARER SASL mechanism][rfc7628] or via non-XMPP | |
| 24 interfaces such as [mod_rest]. | |
| 25 | |
| 26 Although this module has been around for some time, it has recently been | |
| 27 significantly extended and largely rewritten to support OAuth/OIDC more fully. | |
| 28 | |
| 29 As of April 2023, it should be considered **alpha** stage. It works, we have | |
| 30 tested it, but it has not yet seen wider review, testing and deployment. At | |
| 31 this stage we recommend it for experimental and test deployments only. For | |
| 32 specific information, see the [deployment notes section](#deployment-notes) | |
| 33 below. | |
| 34 | |
| 35 Known client implementations: | |
| 36 | |
| 37 - [example shell script for mod_rest](https://hg.prosody.im/prosody-modules/file/tip/mod_rest/example/rest.sh) | |
| 38 - *(we need you!)* | |
| 39 | |
| 40 Support for [OAUTHBEARER][rfc7628] has been added to the Lua XMPP | |
| 41 library, [verse](https://code.matthewwild.co.uk/verse). If you know of | |
| 42 additional implementations, or are motivated to work on one, please let | |
| 43 us know! We'd be happy to help (e.g. by providing a test server). | |
| 44 | |
| 45 ## Standards support | |
| 46 | |
| 47 Notable supported standards: | |
| 48 | |
| 49 - [RFC 6749: The OAuth 2.0 Authorization Framework](https://www.rfc-editor.org/rfc/rfc6749) | |
| 50 - [RFC 7009: OAuth 2.0 Token Revocation](https://www.rfc-editor.org/rfc/rfc7009) | |
| 51 - [RFC 7591: OAuth 2.0 Dynamic Client Registration](https://www.rfc-editor.org/rfc/rfc7591.html) | |
| 52 - [RFC 7628: A Set of Simple Authentication and Security Layer (SASL) Mechanisms for OAuth](https://www.rfc-editor.org/rfc/rfc7628) | |
| 53 - [RFC 7636: Proof Key for Code Exchange by OAuth Public Clients](https://www.rfc-editor.org/rfc/rfc7636) | |
| 54 - [RFC 7662: OAuth 2.0 Token Introspection](https://www.rfc-editor.org/rfc/rfc7662) | |
| 55 - [RFC 8628: OAuth 2.0 Device Authorization Grant](https://www.rfc-editor.org/rfc/rfc8628) | |
| 56 - [RFC 9207: OAuth 2.0 Authorization Server Issuer Identification](https://www.rfc-editor.org/rfc/rfc9207.html) | |
| 57 - [OpenID Connect Core 1.0](https://openid.net/specs/openid-connect-core-1_0.html) | |
| 58 - [OpenID Connect Discovery 1.0](https://openid.net/specs/openid-connect-discovery-1_0.html) (_partial, e.g. missing JWKS_) | |
| 59 - [OpenID Connect Dynamic Client Registration 1.0](https://openid.net/specs/openid-connect-registration-1_0.html) | |
| 60 | |
| 61 ## Configuration | |
| 62 | |
| 63 ### Interface | |
| 64 | |
| 65 The module presents a web page to users to allow them to authenticate when | |
| 66 a client requests access. Built-in pages are provided, but you may also theme | |
| 67 or entirely override them. | |
| 68 | |
| 69 This module honours the `site_name` configuration option that is also used by | |
| 70 a number of other modules: | |
| 71 | |
| 72 ```lua | |
| 73 site_name = "My XMPP Server" | |
| 74 ``` | |
| 75 | |
| 76 To provide custom templates, specify the path to the template directory: | |
| 77 | |
| 78 ```lua | |
| 79 oauth2_template_path = "/etc/prosody/custom-oauth2-templates" | |
| 80 ``` | |
| 81 | |
| 82 If you know what features your templates use use you can adjust the | |
| 83 `Content-Security-Policy` header to only allow what is needed: | |
| 84 | |
| 85 ```lua | |
| 86 oauth2_security_policy = "default-src 'self'" -- this is the default | |
| 87 ``` | |
| 88 | |
| 89 ### Token parameters | |
| 90 | |
| 91 The following options configure the lifetime of tokens issued by the module. | |
| 92 The defaults are recommended. | |
| 93 | |
| 94 ```lua | |
| 95 oauth2_access_token_ttl = 3600 -- one hour | |
| 96 oauth2_refresh_token_ttl = 604800 -- one week | |
| 97 ``` | |
| 98 | |
| 99 ### Dynamic client registration | |
| 100 | |
| 101 To allow users to connect any compatible software, you should enable dynamic | |
| 102 client registration. | |
| 103 | |
| 104 Dynamic client registration can be enabled by configuring a JWT key. Algorithm | |
| 105 defaults to *HS256*, lifetime defaults to forever. | |
| 106 | |
| 107 ```lua | |
| 108 oauth2_registration_key = "securely generated JWT key here" | |
| 109 oauth2_registration_algorithm = "HS256" | |
| 110 oauth2_registration_ttl = nil -- unlimited by default | |
| 111 ``` | |
| 112 | |
| 113 Registering a client is described in | |
| 114 [RFC7591](https://www.rfc-editor.org/rfc/rfc7591.html). | |
| 115 | |
| 116 In addition to the requirements in the RFC, the following requirements | |
| 117 are enforced: | |
| 118 | |
| 119 `client_name` | |
| 120 : **MUST** be present, is shown to users in consent screen. | |
| 121 | |
| 122 `client_uri` | |
| 123 : **MUST** be present and **MUST** be a `https://` URL. | |
| 124 | |
| 125 `redirect_uris` | |
| 126 | |
| 127 : **MUST** contain at least one valid URI. Different rules apply | |
| 128 depending on the value of `application_type`, see below. | |
| 129 | |
| 130 `application_type` | |
| 131 | |
| 132 : Optional, defaults to `web`. Determines further restrictions for | |
| 133 `redirect_uris`. The following values are supported: | |
| 134 | |
| 135 `web` *(default)* | |
| 136 : For web clients. With this, `redirect_uris` **MUST** be | |
| 137 `https://` URIs and **MUST** use the same hostname part as the | |
| 138 `client_uri`. | |
| 139 | |
| 140 `native` | |
| 141 : For native e.g. desktop clients etc. `redirect_uris` **MUST** | |
| 142 match one of: | |
| 143 | |
| 144 - Loopback HTTP URI, e.g. `http://127.0.0.1/` or | |
| 145 `http://[::1]` | |
| 146 - Application-specific scheme, e.g. `com.example.app:/` | |
| 147 - The special OOB URI `urn:ietf:wg:oauth:2.0:oob` | |
| 148 | |
| 149 `tos_uri`, `policy_uri` | |
| 150 : Informative URLs pointing to Terms of Service and Service Policy | |
| 151 document **MUST** use the same scheme (i.e. `https://`) and hostname | |
| 152 as the `client_uri`. | |
| 153 | |
| 154 #### Registration Examples | |
| 155 | |
| 156 In short registration works by POST-ing a JSON structure describing your | |
| 157 client to an endpoint: | |
| 158 | |
| 159 ``` bash | |
| 160 curl -sSf https://xmpp.example.net/oauth2/register \ | |
| 161 -H Content-Type:application/json \ | |
| 162 -H Accept:application/json \ | |
| 163 --data ' | |
| 164 { | |
| 165 "client_name" : "My Application", | |
| 166 "client_uri" : "https://app.example.com/", | |
| 167 "redirect_uris" : [ | |
| 168 "https://app.example.com/redirect" | |
| 169 ] | |
| 170 } | |
| 171 ' | |
| 172 ``` | |
| 173 | |
| 174 Another example with more fields: | |
| 175 | |
| 176 ``` bash | |
| 177 curl -sSf https://xmpp.example.net/oauth2/register \ | |
| 178 -H Content-Type:application/json \ | |
| 179 -H Accept:application/json \ | |
| 180 --data ' | |
| 181 { | |
| 182 "application_type" : "native", | |
| 183 "client_name" : "Desktop Chat App", | |
| 184 "client_uri" : "https://app.example.org/", | |
| 185 "contacts" : [ | |
| 186 "support@example.org" | |
| 187 ], | |
| 188 "policy_uri" : "https://app.example.org/about/privacy", | |
| 189 "redirect_uris" : [ | |
| 190 "http://localhost:8080/redirect", | |
| 191 "org.example.app:/redirect" | |
| 192 ], | |
| 193 "scope" : "xmpp", | |
| 194 "software_id" : "32a0a8f3-4016-5478-905a-c373156eca73", | |
| 195 "software_version" : "3.4.1", | |
| 196 "tos_uri" : "https://app.example.org/about/terms" | |
| 197 } | |
| 198 ' | |
| 199 ``` | |
| 200 | |
| 201 ### Supported flows | |
| 202 | |
| 203 - Authorization Code grant, optionally with Proof Key for Code Exchange | |
| 204 - Device Authorization Grant | |
| 205 - Resource owner password grant *(disabled by default)* | |
| 206 - Implicit flow *(disabled by default)* | |
| 207 - Refresh Token grants | |
| 208 | |
| 209 Various flows can be disabled and enabled with | |
| 210 `allowed_oauth2_grant_types` and `allowed_oauth2_response_types`: | |
| 211 | |
| 212 ```lua | |
| 213 -- These examples reflect the defaults | |
| 214 allowed_oauth2_grant_types = { | |
| 215 "authorization_code"; -- authorization code grant | |
| 216 "device_code"; | |
| 217 -- "password"; -- resource owner password grant disabled by default | |
| 218 } | |
| 219 | |
| 220 allowed_oauth2_response_types = { | |
| 221 "code"; -- authorization code flow | |
| 222 -- "token"; -- implicit flow disabled by default | |
| 223 } | |
| 224 ``` | |
| 225 | |
| 226 The [Proof Key for Code Exchange][RFC 7636] mitigation method is | |
| 227 required by default but can be made optional: | |
| 228 | |
| 229 ```lua | |
| 230 oauth2_require_code_challenge = false -- default is true | |
| 231 ``` | |
| 232 | |
| 233 Further, individual challenge methods can be enabled or disabled: | |
| 234 | |
| 235 ```lua | |
| 236 -- These reflects the default | |
| 237 allowed_oauth2_code_challenge_methods = { | |
| 238 -- "plain"; -- insecure but backwards-compatible | |
| 239 "S256"; | |
| 240 } | |
| 241 ``` | |
| 242 | |
| 243 ### Policy documents | |
| 244 | |
| 245 Links to Terms of Service and Service Policy documents can be advertised | |
| 246 for use by OAuth clients: | |
| 247 | |
| 248 ```lua | |
| 249 oauth2_terms_url = "https://example.com/terms-of-service.html" | |
| 250 oauth2_policy_url = "https://example.com/service-policy.pdf" | |
| 251 -- These are unset by default | |
| 252 ``` | |
| 253 | |
| 254 ## Deployment notes | |
| 255 | |
| 256 ### Access management | |
| 257 | |
| 258 This module does not provide an interface for users to manage what they have | |
| 259 granted access to their account! (e.g. to view and revoke clients they have | |
| 260 previously authorized). It is recommended to join this module with | |
| 261 [mod_client_management] to provide such access. However, at the time of writing, | |
| 262 no XMPP clients currently support the protocol used by that module. We plan to | |
| 263 work on additional interfaces in the future. | |
| 264 | |
| 265 ### Scopes | |
| 266 | |
| 267 OAuth supports "scopes" as a way to grant clients limited access. | |
| 268 | |
| 269 There are currently no standard scopes defined for XMPP. This is | |
| 270 something that we intend to change, e.g. by definitions provided in a | |
| 271 future XEP. This means that clients you authorize currently have to | |
| 272 choose between unrestricted access to your account (including the | |
| 273 ability to change your password and lock you out!) and zero access. So, | |
| 274 for now, while using OAuth clients can prevent leaking your password to | |
| 275 them, it is not currently suitable for connecting untrusted clients to | |
| 276 your account. | |
| 277 | |
| 278 As a first step, the `xmpp` scope is supported, and corresponds to | |
| 279 whatever permissions the user would have when logged in over XMPP. | |
| 280 | |
| 281 Further, known Prosody roles can be used as scopes. | |
| 282 | |
| 283 OpenID scopes such as `openid` and `profile` can be used for "Login | |
| 284 with XMPP" without granting access to more than limited profile details. | |
| 285 | |
| 286 ## Compatibility | |
| 287 | |
| 288 Requires Prosody trunk (April 2023), **not** compatible with Prosody 0.12 or | |
| 289 earlier. |
