|
| 1 | +from oidcmsg import oidc |
| 2 | +from oidcmsg.exception import MissingRequiredAttribute |
| 3 | +from oidcmsg.message import Message |
| 4 | +from oidcmsg.message import SINGLE_OPTIONAL_INT |
| 5 | +from oidcmsg.message import SINGLE_OPTIONAL_STRING |
| 6 | +from oidcmsg.message import SINGLE_REQUIRED_INT |
| 7 | +from oidcmsg.message import SINGLE_REQUIRED_STRING |
| 8 | + |
| 9 | + |
| 10 | +class AuthorizationRequest(Message): |
| 11 | + c_param = { |
| 12 | + "client_id": SINGLE_REQUIRED_STRING, |
| 13 | + "scope": SINGLE_OPTIONAL_STRING, |
| 14 | + } |
| 15 | + |
| 16 | + |
| 17 | +class AuthorizationResponse(Message): |
| 18 | + c_param = { |
| 19 | + "device_code": SINGLE_REQUIRED_STRING, |
| 20 | + "user_code": SINGLE_REQUIRED_STRING, |
| 21 | + "verification_uri": SINGLE_REQUIRED_STRING, |
| 22 | + "verification_uri_complete": SINGLE_OPTIONAL_STRING, |
| 23 | + "expires_in": SINGLE_REQUIRED_INT, |
| 24 | + "interval": SINGLE_OPTIONAL_INT, |
| 25 | + } |
| 26 | + |
| 27 | + |
| 28 | +class AccessTokenRequest(oidc.AccessTokenRequest): |
| 29 | + def verify(self, **kwargs): |
| 30 | + super(AccessTokenRequest, self).verify(**kwargs) |
| 31 | + |
| 32 | + if "device_code" in self: |
| 33 | + # then both client_id and grant_type MUST be present |
| 34 | + for claim in ["grant_type", "client_id"]: |
| 35 | + if claim not in self: |
| 36 | + raise MissingRequiredAttribute(claim) |
0 commit comments