| 51 | self._owns_client = True |
| 52 | |
| 53 | def _headers( |
| 54 | self, *, unauthenticated: bool = False, admin_only: bool = False |
| 55 | ) -> dict[str, str]: |
| 56 | if unauthenticated: |
| 57 | return {"content-type": "application/json"} |
| 58 | self._validate_auth() |
| 59 | h: dict[str, str] = { |
| 60 | "content-type": "application/json", |
| 61 | "app-id": self._app_id, |
| 62 | "Instant-Admin-Version": __version__, |
| 63 | "Instant-Core-Version": __version__, |
| 64 | } |
| 65 | if self._admin_token: |
| 66 | h["authorization"] = f"Bearer {self._admin_token}" |
| 67 | # admin_only skips impersonation so the request uses admin auth. |
| 68 | if not admin_only: |
| 69 | h.update(self._impersonation) |
| 70 | return h |
| 71 | |
| 72 | def _validate_auth(self) -> None: |
| 73 | if self._admin_token: |