-
Notifications
You must be signed in to change notification settings - Fork 218
/
Copy pathauthentication-traits.rst
394 lines (300 loc) · 10.8 KB
/
authentication-traits.rst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
.. _authentication-traits:
---------------------
Authentication traits
---------------------
.. smithy-trait:: smithy.api#authDefinition
.. _authDefinition-trait:
``authDefinition`` trait
========================
Summary
A meta-trait that marks a trait as an authentication scheme. Traits
that are marked with this trait are applied to service shapes to
indicate how a client can authenticate with the service.
Trait selector
``[trait|trait]``
Value type
An object with the following properties:
.. list-table::
:header-rows: 1
:widths: 10 23 67
* - Property
- Type
- Description
* - traits
- [:ref:`shape-id`]
- List of shape IDs that auth scheme implementations MUST
understand in order to successfully use the scheme. Each shape
MUST exist and MUST be a trait. Code generators SHOULD ensure
that they support each listed trait.
Every operation in the closure of a service is expected to support the
authentication schemes applied to a service unless the service or operation
is marked with the :ref:`auth-trait`, which is used to change the set of
supported authentication schemes.
The following example defines a service that supports both ``httpBasicAuth``
and the hypothetical ``fooExample`` authentication scheme.
.. code-block:: smithy
$version: "2"
namespace smithy.example
@authDefinition
@trait(selector: "service")
structure fooExample {}
@fooExample
@httpBasicAuth
service WeatherService {
version: "2017-02-11"
}
Because authentication scheme definitions are just specialized shapes, they
can also support configuration settings.
.. code-block:: smithy
$version: "2"
namespace smithy.example
@authDefinition
@trait(selector: "service")
structure algorithmAuth {
algorithm: AlgorithmAuthAlgorithm
}
@private
enum AlgorithmAuthAlgorithm {
SHA2 = "SHA-2"
}
@algorithmAuth(algorithm: "SHA-2")
service WeatherService {
version: "2017-02-11"
}
.. smithy-trait:: smithy.api#httpBasicAuth
.. _httpBasicAuth-trait:
``httpBasicAuth`` trait
=======================
Summary
Indicates that a service supports HTTP Basic Authentication as
defined in :rfc:`2617`.
Trait selector
``service``
Value type
Annotation trait.
.. code-block:: smithy
@httpBasicAuth
service WeatherService {
version: "2017-02-11"
}
.. smithy-trait:: smithy.api#httpDigestAuth
.. _httpDigestAuth-trait:
``httpDigestAuth`` trait
========================
Summary
Indicates that a service supports HTTP Digest Authentication as defined
in :rfc:`2617`.
Trait selector
``service``
Value type
Annotation trait.
.. code-block:: smithy
@httpDigestAuth
service WeatherService {
version: "2017-02-11"
}
.. smithy-trait:: smithy.api#httpBearerAuth
.. _httpBearerAuth-trait:
``httpBearerAuth`` trait
========================
Summary
Indicates that a service supports HTTP Bearer Authentication as defined
in :rfc:`6750`.
Trait selector
``service``
Value type
Annotation trait.
.. code-block:: smithy
@httpBearerAuth
service WeatherService {
version: "2017-02-11"
}
.. smithy-trait:: smithy.api#httpApiKeyAuth
.. _httpApiKeyAuth-trait:
``httpApiKeyAuth`` trait
========================
Summary
Indicates that a service supports HTTP-specific authentication using an
API key sent in a header or query string parameter.
Trait selector
``service``
Value type
Object
The ``httpApiKeyAuth`` trait is an object that supports the following
properties:
.. list-table::
:header-rows: 1
:widths: 10 10 80
* - Property
- Type
- Description
* - name
- ``string``
- **Required**. Defines the name of the HTTP header or query string
parameter that contains the API key.
* - in
- ``string``
- **Required**. Defines the location of where the key is serialized.
This value can be set to ``header`` or ``query``.
* - scheme
- ``string``
- Defines the scheme to use on the ``Authorization`` header value. As
defined in :rfc:`9110#section-11.4`. This scheme SHOULD be one of the
schemes defined in the `IANA Authentication Scheme Registry`_. This can
only be set if the "in" property is set to ``header``.
The following example defines a service that accepts an API key in the "X-Api-Key"
HTTP header:
.. code-block:: smithy
@httpApiKeyAuth(name: "X-Api-Key", in: "header")
service WeatherService {
version: "2017-02-11"
}
The following example defines a service that uses an API key auth scheme through
the HTTP ``Authorization`` header:
.. code-block:: smithy
@httpApiKeyAuth(scheme: "ApiKey", name: "Authorization", in: "header")
service WeatherService {
version: "2017-02-11"
}
.. smithy-trait:: smithy.api#optionalAuth
.. _optionalAuth-trait:
``optionalAuth`` trait
======================
Summary
Indicates that an operation MAY be invoked without authentication,
regardless of any authentication traits applied to the operation.
Trait selector
``operation``
Value type
Annotation trait.
The following example defines a service that uses HTTP digest authentication,
and bound to the service is an operation that supports unauthenticated access.
.. code-block:: smithy
@httpDigestAuth
service WeatherService {
version: "2017-02-11"
operations: [PingServer]
}
@optionalAuth
operation PingServer {}
The following example defines an operation that does not support
*any* authentication. This kind of operation does not require the
``optionalAuth`` trait.
.. code-block:: smithy
@auth([])
operation SomeUnauthenticatedOperation {}
.. smithy-trait:: smithy.api#auth
.. _auth-trait:
``auth`` trait
==============
Summary
Defines the priority ordered authentication schemes supported by a service
or operation. When applied to a service, it defines the default
authentication schemes of every operation in the service. When applied
to an operation, it defines the list of all authentication schemes
supported by the operation, overriding any ``auth`` trait specified
on a service.
Trait selector
``:is(service, operation)``
*Service or operation shapes*
Value type
This trait contains a priority ordered list of unique string values that
reference authentication scheme shape IDs defined on a service
shape.
Operations that are not annotated with the ``auth`` trait inherit the ``auth``
trait of the service they are bound to. If the operation is not annotated with
the ``auth`` trait, and the service it is bound to is also not annotated with
the ``auth`` trait, then the operation is expected to support each of the
:ref:`authentication scheme traits <authDefinition-trait>` applied to the
service. Each entry in the ``auth`` trait is a shape ID that MUST refer to an
authentication scheme trait applied to the service in which it is bound.
.. note::
When a service has multiple authentication scheme traits applied and no
``auth`` trait, the ordering of authentication schemes is alphabetical
based on the absolute shape ID of each authentication scheme trait.
The following example defines all combinations in which ``auth`` can be applied
to services and operations:
* ``ServiceWithNoAuthTrait`` does not use the ``auth`` trait and binds two
operations:
* ``OperationA`` is not annotated with the ``auth`` trait and inherits all
of the authentication scheme applied to the service.
* ``OperationB`` is annotated with the ``auth`` trait and defines an explicit
list of authentication schemes.
* ``ServiceWithAuthTrait`` is annotated with the ``auth`` trait and binds two
operations:
* ``OperationC`` is not annotated with the ``auth`` trait and inherits all
of the authentication schemes applied via the ``auth`` trait on the
service.
* ``OperationD`` is annotated with the ``auth`` trait and defines an explicit
list of authentication schemes.
* ``OperationE`` has authentication disabled by setting the ``auth`` trait
value on the operation to an empty list, ``[]``.
.. note::
Disabling authentication for an operation is distinct from applying the
:ref:`@optionalAuth <optionalAuth-trait>` trait to an operation. An
operation with the ``@optionalAuth`` trait must be callable both with and
without authentication.
.. code-block:: smithy
@httpBasicAuth
@httpDigestAuth
@httpBearerAuth
service ServiceWithNoAuthTrait {
version: "2020-01-29"
operations: [
OperationA
OperationB
]
}
// This operation does not have the @auth trait and is bound to a service
// without the @auth trait. The effective set of authentication schemes it
// supports are: httpBasicAuth, httpDigestAuth and httpBearerAuth
operation OperationA {}
// This operation does have the @auth trait and is bound to a service
// without the @auth trait. The effective set of authentication schemes it
// supports are: httpDigestAuth.
@auth([httpDigestAuth])
operation OperationB {}
@httpBasicAuth
@httpDigestAuth
@httpBearerAuth
@auth([httpBasicAuth, httpDigestAuth])
service ServiceWithAuthTrait {
version: "2020-01-29"
operations: [
OperationC
OperationD
OperationE
]
}
// This operation does not have the @auth trait and is bound to a service
// with the @auth trait. The effective set of authentication schemes it
// supports are: httpBasicAuth, httpDigestAuth
operation OperationC {}
// This operation has the @auth trait and is bound to a service
// with the @auth trait. The effective set of authentication schemes it
// supports are: httpBearerAuth
@auth([httpBearerAuth])
operation OperationD {}
// This operation has the @auth trait and is bound to a service with the
// @auth trait. This operation does not support any authentication schemes.
@auth([])
operation OperationE {}
The following ``auth`` trait is invalid because it references an
authentication scheme trait that is not applied to the service:
.. code-block:: smithy
@httpDigestAuth
@auth([httpBasicAuth]) // <-- Invalid!
service InvalidExample {
version: "2017-02-11"
}
The following operation ``auth`` trait is invalid because it references an
authentication scheme trait that is not applied to the service:
.. code-block:: smithy
@httpDigestAuth
service InvalidExample {
version: "2017-02-11",
operations: [OperationA]
}
@auth([httpBasicAuth]) // <-- Invalid!
operation OperationA {}
.. _IANA Authentication Scheme Registry: https://www.iana.org/assignments/http-authschemes