Create a signed JWT https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-a-github-app :return string: jwt
(self, expiration: int | None = None)
| 268 | return AppInstallationAuth(self, installation_id, token_permissions, requester) |
| 269 | |
| 270 | def create_jwt(self, expiration: int | None = None) -> str: |
| 271 | """ |
| 272 | Create a signed JWT |
| 273 | https://docs.github.com/en/developers/apps/building-github-apps/authenticating-with-github-apps#authenticating-as-a-github-app |
| 274 | |
| 275 | :return string: jwt |
| 276 | """ |
| 277 | if expiration is not None: |
| 278 | assert isinstance(expiration, int), expiration |
| 279 | assert Consts.MIN_JWT_EXPIRY <= expiration <= Consts.MAX_JWT_EXPIRY, expiration |
| 280 | |
| 281 | now = int(time.time()) |
| 282 | payload = { |
| 283 | "iat": now + self._jwt_issued_at, |
| 284 | "exp": now + (expiration if expiration is not None else self._jwt_expiry), |
| 285 | "iss": self._app_id, |
| 286 | } |
| 287 | assert self._sign_func is not None |
| 288 | encrypted = self._sign_func(payload) |
| 289 | |
| 290 | if isinstance(encrypted, bytes): |
| 291 | return encrypted.decode("utf-8") |
| 292 | return encrypted |
| 293 | |
| 294 | |
| 295 | class AppAuthToken(JWT): |
no outgoing calls
no test coverage detected