Skip to content

Conversation

@chantra
Copy link
Contributor

@chantra chantra commented Mar 23, 2023

add support for get_app endpoint for app authenticated applications

The /app endpoint requires the use of a JWT to be accessed: https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-the-authenticated-app

This change creates a new GithubIntegration and calls the /app
endpoint through it so the requester used uses JWT and not a token.

  • Updated exiting GithubApp testGetAuthenticatedApp to use authentication
  • added test to validate assertion is raised when not called by an authenticated app.

Prior to this, an authenticated application would fail to get access to
its attribute with the following error: https://gist.github.com/chantra/f84e6981e2ab732a5e7acb2978872109

@chantra chantra force-pushed the get_app branch 2 times, most recently from 77393c9 to d8993ab Compare March 23, 2023 23:47
@chantra chantra changed the title add support fpr get_app endpoint for app authenticted applications add support for get_app endpoint for app authenticated applications Mar 23, 2023
The /app endpoint requires the use of a JWT to be accessed: https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-the-authenticated-app

This change creates a new GithubIntegration and calls the `/app`
endpoint through it so the `requester` used uses JWT and not a token.

* Updated exiting GithubApp testGetAuthenticatedApp to use
  authentication
* added test to validate assertion is raised when not called by an
  authenticated app.

Prior to this, an authenticated application would fail to get access to
its attribute with the following error: https://gist.github.com/chantra/f84e6981e2ab732a5e7acb2978872109

Signed-off-by: Manu Bretelle <chantr4@gmail.com>
permissions=self.__app_auth.token_permissions,
)

def get_app(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method should go into GithubIntegration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It is there already. This method here is just a proxy to get from the GitHub object to a GithubIntegration.
Are you fine with the GithubObject accessing directly the requester’s __app_auth to generate a new GithubIntegration? Or adding a app_auth getter so Github object can re-use it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather say GithubIntegration requires some rework to get the authentication, token refresh and Requester init args sorted out: #2461

@chantra
Copy link
Contributor Author

chantra commented Mar 26, 2023 via email

@chantra
Copy link
Contributor Author

chantra commented Mar 27, 2023

Ok, attempted chantra@1154f22

There is an issue with being able to call github.get_app() through as I don't see how we can get the GithubIntegration back to call GithubIntegration.get_app().

Also, I believe, if calling using the Github's requester, then the token will be sent, not the jwt, hence the need to be able to get back to the GithubIntegration form Github.

Another solution is to make get_app non-valid call if the slug is not provided, forcing to use the GithubIntegration object only.

@chantra
Copy link
Contributor Author

chantra commented Apr 3, 2023

@EnricoMi do you have any feedback on my previous comment?

@chantra
Copy link
Contributor Author

chantra commented Apr 22, 2023

@EnricoMi just checking if you have any feedback on my previous comment? thanks

@EnricoMi
Copy link
Collaborator

I think calling the /app endpoint should be moved into GithubIntegration.get_app and Main.get_app should make slug mandatory. This separates the two different endpoints. The former requires a personal access token or app installation token, the latter an application jwt.

Then, together with rework #2461, the following should work:

gh = Github(token)
# calls /apps/{slug} with personal access token
gh.get_app(slug)

gi = GithubIntegration(app_id, private_key, ...)
# calls /app with jwt
gi.get_app()

gh = gi.get_github_for_installation(id, permissions)
# calls /apps/{slug} with installation access token
gh.get_app(slug)

@chantra
Copy link
Contributor Author

chantra commented Apr 24, 2023

Thanks @EnricoMi . I would be happy to do those changes once your branch is merged. Please tag me when it lands so I can check it out and update this PR.

@EnricoMi EnricoMi changed the title add support for get_app endpoint for app authenticated applications Add support for get_app endpoint with app authentication Jun 6, 2023
@EnricoMi
Copy link
Collaborator

EnricoMi commented Jun 8, 2023

@chantra auth rework is merged, go ahead and move /app call into GithubIntegration. Maybe a fresh new PR might be easier.

@chantra
Copy link
Contributor Author

chantra commented Jun 9, 2023

Thanks @EnricoMi

Let me close this PR and start fresh.

@chantra chantra closed this Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants