MCPcopy
hub / github.com/authlib/authlib / prepare

Method prepare

authlib/oauth1/rfc5849/client_auth.py:161–185  ·  view source on GitHub ↗

Add OAuth parameters to the request. Parameters may be included from the body if the content-type is urlencoded, if no content type is set, a guess is made.

(self, method, uri, headers, body)

Source from the content-addressed store, hash-verified

159 return uri, headers, body
160
161 def prepare(self, method, uri, headers, body):
162 """Add OAuth parameters to the request.
163
164 Parameters may be included from the body if the content-type is
165 urlencoded, if no content type is set, a guess is made.
166 """
167 content_type = to_native(headers.get("Content-Type", ""))
168 if self.signature_type == SIGNATURE_TYPE_BODY:
169 content_type = CONTENT_TYPE_FORM_URLENCODED
170 elif not content_type and extract_params(body):
171 content_type = CONTENT_TYPE_FORM_URLENCODED
172
173 if CONTENT_TYPE_FORM_URLENCODED in content_type:
174 headers["Content-Type"] = CONTENT_TYPE_FORM_URLENCODED
175 if isinstance(body, bytes):
176 body = body.decode()
177 uri, headers, body = self.sign(method, uri, headers, body)
178 elif self.force_include_body:
179 # To allow custom clients to work on non form encoded bodies.
180 uri, headers, body = self.sign(method, uri, headers, body)
181 else:
182 # Omit body data in the signing of non form-encoded requests
183 uri, headers, _ = self.sign(method, uri, headers, b"")
184 body = b""
185 return uri, headers, body
186
187
188def generate_nonce():

Callers

nothing calls this directly

Calls 5

signMethod · 0.95
to_nativeFunction · 0.90
extract_paramsFunction · 0.90
decodeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected