The access token provided is expired, revoked, malformed, or invalid for other reasons. The resource SHOULD respond with the HTTP 401 (Unauthorized) status code. The client MAY request a new access token and retry the protected resource request. :rfc:`6750#section-3.1`
| 17 | |
| 18 | |
| 19 | class InvalidTokenError(OAuth2Error): |
| 20 | """The access token provided is expired, revoked, malformed, or |
| 21 | invalid for other reasons. The resource SHOULD respond with |
| 22 | the HTTP 401 (Unauthorized) status code. The client MAY |
| 23 | request a new access token and retry the protected resource |
| 24 | request. |
| 25 | |
| 26 | :rfc:`6750#section-3.1` |
| 27 | """ |
| 28 | |
| 29 | error = "invalid_token" |
| 30 | description = ( |
| 31 | "The access token provided is expired, revoked, malformed, " |
| 32 | "or invalid for other reasons." |
| 33 | ) |
| 34 | status_code = 401 |
| 35 | |
| 36 | def __init__( |
| 37 | self, |
| 38 | description=None, |
| 39 | uri=None, |
| 40 | status_code=None, |
| 41 | state=None, |
| 42 | realm=None, |
| 43 | extra_attributes=None, |
| 44 | ): |
| 45 | super().__init__(description, uri, status_code, state) |
| 46 | self.realm = realm |
| 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): |
no outgoing calls
no test coverage detected