If the protected resource request does not include authentication credentials or does not contain an access token that enables access to the protected resource, the resource server MUST include the HTTP "WWW-Authenticate" response header field; it MAY include it in re
(self)
| 47 | self.extra_attributes = extra_attributes or {} |
| 48 | |
| 49 | def get_headers(self): |
| 50 | """If the protected resource request does not include authentication |
| 51 | credentials or does not contain an access token that enables access |
| 52 | to the protected resource, the resource server MUST include the HTTP |
| 53 | "WWW-Authenticate" response header field; it MAY include it in |
| 54 | response to other conditions as well. |
| 55 | |
| 56 | :rfc:`6750#section-3` |
| 57 | """ |
| 58 | headers = super().get_headers() |
| 59 | |
| 60 | extras = [] |
| 61 | if self.realm: |
| 62 | extras.append(f'realm="{self.realm}"') |
| 63 | if self.extra_attributes: |
| 64 | extras.extend( |
| 65 | [f'{k}="{self.extra_attributes[k]}"' for k in self.extra_attributes] |
| 66 | ) |
| 67 | extras.append(f'error="{self.error}"') |
| 68 | error_description = self.get_error_description() |
| 69 | extras.append(f'error_description="{error_description}"') |
| 70 | headers.append(("WWW-Authenticate", "Bearer " + ", ".join(extras))) |
| 71 | return headers |
| 72 | |
| 73 | |
| 74 | class InsufficientScopeError(OAuth2Error): |