Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Mariatta
Copy link
Member

  • add get_jwt
  • add get_installation_access_token
  • add PyJWT and cryptography dependencies, needed to construct JWT

Hoping for inclusion in 4.1.0, and to get early feedback

Closes #71

@Mariatta
Copy link
Member Author

I'm planning to prepare an online GitHub App tutorial and I'm kinda wanting for this to be included to gidgethub in time before I record the tutorial. I will try to find time to write the tests this weekend.

@Mariatta Mariatta force-pushed the issue-71 branch 2 times, most recently from 4193ec9 to 457776d Compare April 16, 2020 22:14
- add get_jwt
- add get_installation_access_token
- add PyJWT and cryptography dependencies, needed to construct JWT

Hoping for inclusion in 4.1.0

Closes gidgethub#71
@Mariatta Mariatta marked this pull request as ready for review April 16, 2020 23:00
@Mariatta Mariatta requested a review from brettcannon April 17, 2020 00:22
@Mariatta
Copy link
Member Author

If possible I'd like to have this released soon.

I need this functionality for MY PyCon tutorial that is due onApril 24. (But it would be great if I can record my tutorial this weekend 🙏🏻)

Copy link
Collaborator

@brettcannon brettcannon left a comment

Choose a reason for hiding this comment

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

A bunch of little things I trust you to touch up before merging. 😄

gidgethub/app.py Outdated

async def get_installation_access_token(
gh: GitHubAPI, *, installation_id: str, app_id: str, private_key: str
) -> Any:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is calling a specific endpoint that has an expected value, maybe we should type this as Dict[str, str]?

Copy link
Member Author

Choose a reason for hiding this comment

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

This returns whatever gh.post returns, which is Any. When I tried to change this to Dict[str, str], it complained because it doesn't match gh.post's return type.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, you probably would have to cast it.

@brettcannon
Copy link
Collaborator

BTW once you get this landed and the release out I want to set this project up on github.com/brettcannon/release-often so that we automate releases. 😁 (I would do it now but I haven't tested it against a flit project yet and I don't want to hold you up for your tutorial.)

from gidgethub.abc import GitHubAPI


def get_jwt(*, app_id: str, private_key: str) -> str:
Copy link
Member Author

Choose a reason for hiding this comment

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

I realized that there are other endpoints that require JWT, so I changed this from private to public. I've also adjusted the documentation.

import pytest

from gidgethub import (
app as gh_app,
Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason app is clashing with pytest-tornasync fixture, so I had to rename this to gh_app in tests.
I could also call the module apps instead of app if that's better? (just like actions with s)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Naming it 'apps' is fine by me.

@Mariatta
Copy link
Member Author

@brettcannon mind re-reviewing one last time? I made get_jwt public and added it to the documentation.

gidgethub/app.py Outdated
Comment on lines 23 to 28
"""Obtain a GitHub App's installation access token.
Return a dictionary containing access token and expiration time.
Doc: https://developer.github.com/v3/apps/#create-a-new-installation-token
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Obtain a GitHub App's installation access token.
Return a dictionary containing access token and expiration time.
Doc: https://developer.github.com/v3/apps/#create-a-new-installation-token
"""Obtain a GitHub App's installation access token.
Returns a dictionary containing access token and expiration time
(https://developer.github.com/v3/apps/#create-a-new-installation-token).

@Mariatta Mariatta merged commit 5a7bcf1 into gidgethub:master Apr 19, 2020
@Mariatta Mariatta deleted the issue-71 branch April 19, 2020 04:21
requires = [
"uritemplate>=3.0.1",
"PyJWT>=1.7.1",
"cryptography>=2.9"

Choose a reason for hiding this comment

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

It's not a direct dependency, why do you specify it here?

requires = ["uritemplate>=3.0.1"]
requires = [
"uritemplate>=3.0.1",
"PyJWT>=1.7.1",

Choose a reason for hiding this comment

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

It should've been PyJWT[crypto] as per their docs:
Screenshot_2020-04-19-08-52-35-032_com android chrome

Copy link
Collaborator

Choose a reason for hiding this comment

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

I opened #116 to track this.

from gidgethub.abc import GitHubAPI


def get_jwt(*, app_id: str, private_key: str) -> str:

Choose a reason for hiding this comment

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

In octomachinery, I used to have it as a function but then I implemented an object that represents a private key with fingerprint pinning and it turned out that it's handy to have it as a method:
https://github.com/sanitizers/octomachinery/blob/6b41c1df510f8bbf090ea290941261396e2cb559/octomachinery/github/models/private_key.py

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.

Provide a common way to generate JWT

3 participants