@@ -31,9 +31,16 @@ class Configuration(object):
3131 The dict value is an API key prefix when generating the auth data.
3232 :param username: Username for HTTP basic authentication
3333 :param password: Password for HTTP basic authentication
34+ { {#hasHttpSignatureMethods} }
35+ :param signing_info: Configuration parameters for the HTTP signature security scheme.
36+ Must be an instance of { {{packageName} }}.signing.HttpSigningConfiguration
37+ { {/hasHttpSignatureMethods} }
3438
39+ { {#hasAuthMethods} }
3540 :Example:
41+ { {#hasApiKeyMethods} }
3642
43+ API Key Authentication Example.
3744 Given the following security scheme in the OpenAPI specification:
3845 components:
3946 securitySchemes:
@@ -49,11 +56,74 @@ class Configuration(object):
4956 )
5057 The following cookie will be added to the HTTP request:
5158 Cookie: JSESSIONID abc123
59+ { {/hasApiKeyMethods} }
60+ { {#hasHttpBasicMethods} }
61+
62+ HTTP Basic Authentication Example.
63+ Given the following security scheme in the OpenAPI specification:
64+ components:
65+ securitySchemes:
66+ http_basic_auth:
67+ type: http
68+ scheme: basic
69+
70+ Configure API client with HTTP basic authentication:
71+ conf = { {{packageName} }}.Configuration(
72+ username='the-user',
73+ password='the-password',
74+ )
75+ { {/hasHttpBasicMethods} }
76+ { {#hasHttpSignatureMethods} }
77+
78+ HTTP Signature Authentication Example.
79+ Given the following security scheme in the OpenAPI specification:
80+ components:
81+ securitySchemes:
82+ http_basic_auth:
83+ type: http
84+ scheme: signature
85+
86+ Configure API client with HTTP signature authentication. Use the 'hs2019' signature scheme,
87+ sign the HTTP requests with the RSA-SSA-PSS signature algorithm, and set the expiration time
88+ of the signature to 5 minutes after the signature has been created.
89+ Note you can use the constants defined in the { {{packageName} }}.signing module, and you can
90+ also specify arbitrary HTTP headers to be included in the HTTP signature, except for the
91+ 'Authorization' header, which is used to carry the signature.
92+
93+ One may be tempted to sign all headers by default, but in practice it rarely works.
94+ This is beccause explicit proxies, transparent proxies, TLS termination endpoints or
95+ load balancers may add/modify/remove headers. Include the HTTP headers that you know
96+ are not going to be modified in transit.
97+
98+ conf = { {{packageName} }}.Configuration(
99+ signing_info = { {{packageName} }}.signing.HttpSigningConfiguration(
100+ key_id = 'my-key-id',
101+ private_key_path = 'rsa.pem',
102+ signing_scheme = signing.SCHEME_HS2019,
103+ signing_algorithm = signing.ALGORITHM_RSASSA_PSS,
104+ signed_headers = [signing.HEADER_REQUEST_TARGET,
105+ signing.HEADER_CREATED,
106+ signing.HEADER_EXPIRES,
107+ signing.HEADER_HOST,
108+ signing.HEADER_DATE,
109+ signing.HEADER_DIGEST,
110+ 'Content-Type',
111+ 'User-Agent'
112+ ],
113+ signature_max_validity = datetime.timedelta(minutes=5)
114+ )
115+ )
116+ { {/hasHttpSignatureMethods} }
117+ { {/hasAuthMethods} }
52118 """
53119
54120 def __init__(self, host="{ {{basePath} }}",
55121 api_key=None, api_key_prefix=None,
56- username=None, password=None):
122+ username=None, password=None,
123+ { {#hasHttpSignatureMethods} }
124+ signing_info=None,
125+ { {/hasHttpSignatureMethods} }
126+ ):
57127 """Constructor
58128 """
59129 self.host = host
@@ -82,14 +152,21 @@ class Configuration(object):
82152 self.password = password
83153 """Password for HTTP basic authentication
84154 """
155+ { {#hasHttpSignatureMethods} }
156+ if signing_info is not None:
157+ signing_info.host = host
158+ self.signing_info = signing_info
159+ """The HTTP signing configuration
160+ """
161+ { {/hasHttpSignatureMethods} }
85162{ {#hasOAuthMethods} }
86- self.access_token = ""
163+ self.access_token = None
87164 """access token for OAuth/Bearer
88165 """
89166{ {/hasOAuthMethods} }
90167{ {^hasOAuthMethods} }
91168{ {#hasBearerMethods} }
92- self.access_token = ""
169+ self.access_token = None
93170 """access token for OAuth/Bearer
94171 """
95172{ {/hasBearerMethods} }
@@ -297,15 +374,15 @@ class Configuration(object):
297374 }
298375{ {/isApiKey} }
299376{ {#isBasic} }
300- { {^isBasicBearer } }
377+ { {#isBasicBasic } }
301378 if self.username is not None and self.password is not None:
302379 auth['{ {name} }'] = {
303380 ' type' : ' basic' ,
304381 ' in' : ' header' ,
305382 ' key' : ' Authorization' ,
306383 ' value' : self.get_basic_auth_token()
307384 }
308- { {/isBasicBearer } }
385+ { {/isBasicBasic } }
309386 { {#isBasicBearer} }
310387 if self.access_token is not None:
311388 auth['{ {name} }'] = {
@@ -318,6 +395,15 @@ class Configuration(object):
318395 'value': 'Bearer ' + self.access_token
319396 }
320397 { {/isBasicBearer} }
398+ { {#isHttpSignature} }
399+ if self.signing_info is not None:
400+ auth['{ {name} }'] = {
401+ ' type' : ' http-signature' ,
402+ ' in' : ' header' ,
403+ ' key' : ' Authorization' ,
404+ ' value' : None # Signature headers are calculated for every HTTP request
405+ }
406+ { {/isHttpSignature} }
321407{ {/isBasic} }
322408{ {#isOAuth} }
323409 if self.access_token is not None:
0 commit comments