|
| 1 | +# OAuth Bearer Token Authentication |
| 2 | + |
| 3 | +`auth.oauth` implements OAuth Bearer Token authentication as defined |
| 4 | +in [RFC 7628][rfc7628] and [RFC 6750][rfc6750]. |
| 5 | + |
| 6 | +It is not compatible with non-standard XOAUTH2 implementations, such as those |
| 7 | +used by Google and Microsoft. |
| 8 | + |
| 9 | +The provided token can be validated either by the server directly by decoding |
| 10 | +JWT, or by making an introspection request ([RFC 7662][rfc7662]) to the |
| 11 | +authorization server to validate the token and retrieve associated metadata. |
| 12 | + |
| 13 | +## Configuration directives |
| 14 | + |
| 15 | +``` |
| 16 | +auth.oauth [<url>] { |
| 17 | + [debug yes | no] |
| 18 | + [introspection auth | get | post | local] |
| 19 | + [introspection_url <url>] |
| 20 | + [http_header <key> <value>] |
| 21 | + [http_header <key> <value> ...] |
| 22 | + [introspection_timeout 5s] |
| 23 | + [scopes <scope...>] |
| 24 | + [username_attribute <attribute>] |
| 25 | + [active_attribute active] |
| 26 | + [active_value true] |
| 27 | + [jwt_key_id_template <template>] |
| 28 | + [jwt_key_table <table>] |
| 29 | + [jwt_valid_methods <method...>] |
| 30 | + [jwt_issuers <issuer...>] |
| 31 | + [jwt_expiry_leeway <duration>] |
| 32 | + [jwt_audience <table>] |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +### debug _yes|no_ |
| 37 | +Default: no |
| 38 | + |
| 39 | +Enables debug logging. |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +### introspection _auth|get|post|local_ |
| 44 | +Default: auth |
| 45 | + |
| 46 | +Defines the method used to validate the token. The following options are available: |
| 47 | +- `auth`: Add token to the `Authorization` header and make a request to the introspection endpoint. |
| 48 | +- `get`: Make a GET request to the introspection endpoint with the token appended to the URL. |
| 49 | +- `post`: Make a POST request to the introspection endpoint with the token as `token` form-data field. |
| 50 | +- `local`: Validate the token locally by decoding it as a JWT. |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +### introspection_url _<url>_ |
| 55 | +Default: (none) |
| 56 | + |
| 57 | +The URL of the introspection endpoint to validate the token. Required if `introspection_method` is set |
| 58 | +to `auth`, `get`, or `post`. |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +### http_header _<key> <value>_ |
| 63 | +Default: (none) |
| 64 | + |
| 65 | +Additional HTTP headers to include in the introspection request. This can be used to provide server |
| 66 | +credentials or other necessary information to the authorization server. |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +### introspection_timeout _<duration>_ |
| 71 | +Default: 5s |
| 72 | + |
| 73 | +The timeout for the introspection request. If the request takes longer than this duration, authentication |
| 74 | +will fail. |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +### scopes _<scope>_ |
| 79 | +Default: (none) |
| 80 | + |
| 81 | +The required scope(s) for the token. If specified, the token must include all scopes to be |
| 82 | +considered valid. |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +### username_attribute _<attribute>_ |
| 87 | +Default: email |
| 88 | + |
| 89 | +The attribute in the token response that contains the username. This is used to set the username for the |
| 90 | +authenticated user. |
| 91 | + |
| 92 | +If attribute is a list of strings, the first non-empty value will be used as the username. |
| 93 | + |
| 94 | +If client requests a specific username (e.g. via SASL authorization identity), it must match |
| 95 | +the username extracted from the token for authentication to succeed. If attribute is a |
| 96 | +list then the client requested username must match at least one of the values in the list. |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +### active_attribute _<attribute>_ |
| 101 | +Default: not specified |
| 102 | + |
| 103 | +The attribute in the token response that indicates whether the token is active. This is used to determine if the |
| 104 | +token is valid. If not specified, the token is considered active if the introspection request returns |
| 105 | +a successful response. |
| 106 | + |
| 107 | +--- |
| 108 | + |
| 109 | +### active_value _<value>_ |
| 110 | +Default: not specified |
| 111 | + |
| 112 | +The value of the `active_attribute` that indicates the token is active. This is used to determine if the token is |
| 113 | +valid. If not specified, the token is considered active if the `active_attribute` is present and has a truthy value |
| 114 | +(not empty string, non-zero number, or boolean true). |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +### jwt_key_id_template _<template>_ |
| 119 | +Default: `{kid}` |
| 120 | + |
| 121 | +The template used to determine the key for `jwt_key_table` lookup. The template can include placeholders |
| 122 | +for JWT header and body fields: azp, kid, alg. If azp or kid is missing from the token, the placeholder will be |
| 123 | +replaced with `default`. |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +### jwt_key_table _<table>_ |
| 128 | +Default: (none) |
| 129 | + |
| 130 | +The table to use for looking up the key to validate JWT tokens. The lookup key is determined by applying |
| 131 | +the `jwt_key_id_template` to the token's header and body fields. |
| 132 | + |
| 133 | +Most `storage.blob` (including file and s3) can be used here as well as they |
| 134 | +all also implement the `table` interface. |
| 135 | + |
| 136 | +--- |
| 137 | + |
| 138 | +### jwt_valid_methods _<method>_ |
| 139 | +Default: all supported methods. |
| 140 | + |
| 141 | +The allowed signing algorithms for JWT tokens. If specified, the token's `alg` header field must match |
| 142 | +one of these values to be considered valid. |
| 143 | + |
| 144 | +It is not possible to enable `none` algorithm for JWT tokens. |
| 145 | + |
| 146 | +--- |
| 147 | + |
| 148 | +### jwt_issuers _<issuer>_ |
| 149 | +Default: (none) |
| 150 | + |
| 151 | +If specified, the token's `iss` claim must match one of these values to be considered valid. |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +### jwt_expiry_leeway _<duration>_ |
| 156 | +Default: 30s |
| 157 | + |
| 158 | +The leeway to apply when validating the token's `exp` claim. This allows for some clock skew between the |
| 159 | +token issuer and the server. The token is considered valid if the current time is |
| 160 | +before `exp` + `jwt_expiry_leeway`. |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +### jwt_audience _<table>_ |
| 165 | +Default: (none) |
| 166 | + |
| 167 | +If specified, the token's `aud` claim must match one of the values in this table to be considered |
| 168 | +valid. |
| 169 | + |
| 170 | +[rfc7628]: https://tools.ietf.org/html/rfc7628 |
| 171 | +[rfc6750]: https://tools.ietf.org/html/rfc6750 |
| 172 | +[rfc7662]: https://tools.ietf.org/html/rfc7662 |
0 commit comments