MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / AppAuth

Class AppAuth

github/Auth.py:205–292  ·  view source on GitHub ↗

This class is used to authenticate as a GitHub App. https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app

Source from the content-addressed store, hash-verified

203
204
205class AppAuth(JWT):
206 """
207 This class is used to authenticate as a GitHub App.
208
209 https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app
210
211 """
212
213 @staticmethod
214 def create_jwt_sign(private_key_or_func: str | PrivateKeyGenerator, jwt_algorithm: str) -> DictSignFunction:
215 return JwtSigner(private_key_or_func, jwt_algorithm).jwt_sign
216
217 # v3: move * above private_key
218 def __init__(
219 self,
220 app_id: int | str,
221 private_key: str | PrivateKeyGenerator | None = None,
222 *,
223 sign_func: DictSignFunction | None = None,
224 jwt_expiry: int = Consts.DEFAULT_JWT_EXPIRY,
225 jwt_issued_at: int = Consts.DEFAULT_JWT_ISSUED_AT,
226 ):
227 assert isinstance(app_id, (int, str)), app_id
228 if isinstance(app_id, str):
229 assert len(app_id) > 0, "app_id must not be empty"
230 assert private_key is not None or sign_func is not None, "either private_key or sign_func must be given"
231 assert private_key is None or sign_func is None, "private_key or sign_func cannot both be given"
232 if private_key is not None:
233 assert isinstance(private_key, str) or callable(private_key)
234 if isinstance(private_key, str):
235 assert len(private_key) > 0, "private_key must not be empty"
236 sign_func = AppAuth.create_jwt_sign(private_key, Consts.DEFAULT_JWT_ALGORITHM)
237 assert isinstance(jwt_expiry, int), jwt_expiry
238 assert Consts.MIN_JWT_EXPIRY <= jwt_expiry <= Consts.MAX_JWT_EXPIRY, jwt_expiry
239
240 self._app_id = str(app_id)
241 self._sign_func = sign_func
242 self._jwt_expiry = jwt_expiry
243 self._jwt_issued_at = jwt_issued_at
244
245 @property
246 def app_id(self) -> int | str:
247 return self._app_id
248
249 @property
250 def token(self) -> str:
251 return self.create_jwt()
252
253 def get_installation_auth(
254 self,
255 installation_id: int,
256 token_permissions: dict[str, str] | None = None,
257 requester: Requester | None = None,
258 ) -> AppInstallationAuth:
259 """
260 Creates a github.Auth.AppInstallationAuth instance for an installation.
261
262 :param installation_id: installation id

Callers 5

__init__Method · 0.90
__init__Method · 0.90
PickleClass · 0.90
setUpMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…