Unable to obtain access token via GitHub Enterprise
zjpiazza opened this issue · comments
Hello,
I am trying to use gidgethub to build a GitHub App for some automation tasks. I was able to install and test the app on public GitHub without any problems. However, when I tried to port the application over to our company's GH Enterprise instance, I'm getting an exception thrown on the get_installation_access_token method. The response just says: gidgethub.BadRequest: Not Acceptable
If I use the get_jwt function myself and then use Postman or equivalent tool, I am able to POST a request to the access_tokens endpoint and see a token returned to me. Here is the relevant snippet:
@routes.post('/')
async def main(request):
try:
body = await request.read()
event = sansio.Event.from_http(request.headers, body, secret=GH_SECRET)
print('GH delivery ID', event.delivery_id, file=sys.stderr)
if event.event == "ping":
return web.Response(status=200)
async with aiohttp.ClientSession() as session:
gh = gh_aiohttp.GitHubAPI(session, "zachary-piazza", base_url='https://github.hpe.com/api/v3')
access_token = await get_installation_access_token(
gh, installation_id=GH_INSTALLATION_ID, app_id=GH_APP_ID,
private_key=GH_PRIVATE_KEY
)
gh = gh_aiohttp.GitHubAPI(session, "zachary-piazza",
oauth_token=access_token['token'],
cache=cache, base_url='https://github.hpe.com/api/v3')
# Give GitHub some time to reach internal consistency.
await asyncio.sleep(1)
await router.dispatch(event, gh)
try:
print('GH requests remaining:', gh.rate_limit.remaining)
except AttributeError:
pass
return web.Response(status=200)
except Exception as exc:
traceback.print_exc(file=sys.stderr)
return web.Response(status=500)
Am I doing something wrong in my my call to get_installation_access_token? Any help here would be appreciated. Thank you!