(
    *, session: http.AsyncClient, installation_id: str
)
return token_response.token
https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-an-installation
https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-an-installation
https : // developer . github . com / apps / building - github - apps / authenticating - with - github - apps / #authenticating - as - an - installation
async def get_token_for_install(
    *, session: http.AsyncClient, installation_id: str
) -> str:
    """
    https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-an-installation
    """
    token = installation_cache.get(installation_id)
    if token is not None and not token.expired:
        return token.token
    app_token = generate_jwt(
        private_key=conf.PRIVATE_KEY, app_identifier=conf.GITHUB_APP_ID
    )
    throttler = get_thottler_for_installation(
        # this isn't a real installation ID, but it provides rate limiting
        # for our GithubApp instead of the installations we typically act as
        installation_id=APPLICATION_ID
    )
    async with throttler:
        res = await session.post(
            conf.v3_url(f"/app/installations/{installation_id}/access_tokens"),
            headers=dict(
                Accept="application/vnd.github.machine-man-preview+json",
                Authorization=f"Bearer {app_token}",
            ),
        )
    if res.status_code > 300:
        raise Exception(f"Failed to get token, github response: {res.text}")
    token_response = TokenResponse(**res.json())
    installation_cache[installation_id] = token_response
    return token_response.token
async def get_token_for_install ( * , session : http . AsyncClient , installation_id : str ) -> str : token = installation_cache . get ( installation_id ) if token is not None and not token . expired : return token . token app_token = generate_jwt ( private_key = conf . PRIVATE_KEY , app_identifier = conf . GITHUB_APP_ID ) throttler = get_thottler_for_installation ( # this isn't a real installation ID, but it provides rate limiting # for our GithubApp instead of the installations we typically act as installation_id = APPLICATION_ID ) async with throttler : res = await session . post ( conf . v3_url ( f"/app/installations/{installation_id}/access_tokens" ) , headers = dict ( Accept = "application/vnd.github.machine-man-preview+json" , Authorization = f"Bearer {app_token}" , ) , ) if res . status_code > 300 : raise Exception ( f"Failed to get token, github response: {res.text}" ) token_response = TokenResponse ( * * res . json ( ) ) installation_cache [ installation_id ] = token_response return token_response . token