| 1 | from typing import Any, Optional, Union, List, Dict |
| 2 | |
| 3 | from .base import AuthenticationBase |
| 4 | |
| 5 | import json |
| 6 | |
| 7 | |
| 8 | class BackChannelLogin(AuthenticationBase): |
| 9 | """Back-Channel Login endpoint""" |
| 10 | |
| 11 | def back_channel_login( |
| 12 | self, |
| 13 | binding_message: str, |
| 14 | login_hint: str, |
| 15 | scope: str, |
| 16 | authorization_details: Optional[Union[str, List[Dict]]] = None, |
| 17 | requested_expiry: Optional[int] = None, |
| 18 | **kwargs |
| 19 | ) -> Any: |
| 20 | """Send a Back-Channel Login. |
| 21 | |
| 22 | Args: |
| 23 | binding_message (str): Human-readable string displayed on both the device calling /bc-authorize and the user’s |
| 24 | authentication device to ensure the user is approves the correct request. |
| 25 | |
| 26 | login_hint (str): JSON string containing user details for authentication in the iss_sub format.Ensure |
| 27 | serialization before passing. |
| 28 | |
| 29 | scope(str): "openid" is a required scope.Multiple scopes are separated |
| 30 | with whitespace. |
| 31 | |
| 32 | authorization_details (str, list of dict, optional): JSON string or a list of dictionaries representing |
| 33 | Rich Authorization Requests (RAR) details to include in the CIBA request. |
| 34 | |
| 35 | requested_expiry (int, optional): Number of seconds the authentication request is valid for. |
| 36 | Auth0 defaults to 300 seconds (5 mins) if not provided. |
| 37 | |
| 38 | **kwargs: Other fields to send along with the request. |
| 39 | |
| 40 | Returns: |
| 41 | auth_req_id, expires_in, interval |
| 42 | """ |
| 43 | |
| 44 | data = { |
| 45 | "client_id": self.client_id, |
| 46 | "binding_message": binding_message, |
| 47 | "login_hint": login_hint, |
| 48 | "scope": scope, |
| 49 | **kwargs, |
| 50 | } |
| 51 | |
| 52 | if authorization_details is not None: |
| 53 | if isinstance(authorization_details, str): |
| 54 | data["authorization_details"] = authorization_details |
| 55 | elif isinstance(authorization_details, list): |
| 56 | data["authorization_details"] = json.dumps(authorization_details) |
| 57 | |
| 58 | if requested_expiry is not None: |
| 59 | if not isinstance(requested_expiry, int) or requested_expiry <= 0: |
| 60 | raise ValueError("requested_expiry must be a positive integer") |
| 61 | data["requested_expiry"] = str(requested_expiry) |
| 62 | |
| 63 | data.update(kwargs) |
| 64 | |
| 65 | return self.authenticated_post( |
| 66 | f"{self.protocol}://{self.domain}/bc-authorize", |
| 67 | data = data, |
| 68 | headers={"Content-Type": "application/x-www-form-urlencoded"}, |
| 69 | ) |