Parse an OAuth authorization header into a list of 2-tuples.
(headers)
| 88 | |
| 89 | |
| 90 | def _parse_authorization_header(headers): |
| 91 | """Parse an OAuth authorization header into a list of 2-tuples.""" |
| 92 | authorization_header = headers.get("Authorization") |
| 93 | if not authorization_header: |
| 94 | return [], None |
| 95 | |
| 96 | auth_scheme = "oauth " |
| 97 | if authorization_header.lower().startswith(auth_scheme): |
| 98 | items = parse_http_list(authorization_header[len(auth_scheme) :]) |
| 99 | try: |
| 100 | items = parse_keqv_list(items).items() |
| 101 | auth_params = [(unescape(k), unescape(v)) for k, v in items] |
| 102 | realm = dict(auth_params).get("realm") |
| 103 | return auth_params, realm |
| 104 | except (IndexError, ValueError): |
| 105 | pass |
| 106 | raise ValueError("Malformed authorization header") |
| 107 | |
| 108 | |
| 109 | def _parse_oauth_params(query_params, body_params, auth_params): |