Skip to content

Commit 777eb13

Browse files
committed
feat: get access_token 🎉
1 parent cc4f695 commit 777eb13

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

githubapp/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Github Apps API wrapper
3+
This is a wrapper for the Github Apps API. It provides a simple interface to
4+
make requests to the API and return the results as a dictionary.
5+
:copyright: (c) 2022 by the authors and contributors (see AUTHORS).
6+
:license: MIT, see LICENSE for more details.
7+
"""
8+
__title__ = 'githubapp'
9+
__author__ = 'RTa-technology'
10+
__license__ = 'MIT'
11+
__copyright__ = 'Copyright 2022 by the authors and contributors (see AUTHORS)'
12+
__version__ = '0.1.0'
13+
14+
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
15+
16+
from .adapter import Auth, Authentication
17+
18+
from .errors import (BadRequest, Forbidden, HTTPException, InternalServerError,
19+
NotFound, PayloadTooLarge, QuotaExceeded,
20+
ServiceUnavailable, TooManyRequests, URITooLong)
21+
22+
__all__ = [
23+
'Adapter',
24+
'Auth'
25+
]

githubapp/adapter.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class Authentication(metaclass=ABCMeta):
2222
def __init__(self, app_id: int, installation_id: int, client_secret, *, iat: int = 30, exp: int = 30):
2323
self.installation_id = installation_id
24-
self.endpoint = 'https://api.github.com/installations/{}/access_tokens'.format(
24+
self.endpoint = 'https://api.github.com/app/installations/{}/access_tokens'.format(
2525
self.installation_id)
2626
self.algorithm = "RS256"
2727
self.app_id = app_id
@@ -247,9 +247,9 @@ def is_authorization(self, *, _jwt: str = None, client_public: str = None) -> bo
247247
_jwt = self.gen_jwt()
248248
if client_public is None:
249249
client_public = self.gen_pubkey()
250+
250251
try:
251-
decoded_jwt = jwt.decode(_jwt, key=client_public,
252-
audience=self.endpoint, algorithms=self.algorithm)
252+
decoded_jwt = jwt.decode(_jwt, key=client_public, algorithms=self.algorithm)
253253
if decoded_jwt['iss'] == self.app_id:
254254
return True
255255
except:
@@ -278,7 +278,7 @@ def get_access_token_response(self, *, _jwt: bytes = None, **kwargs) -> Optional
278278
_jwt = self.gen_jwt()
279279

280280
headers = {
281-
'Accept': 'application/vnd.github.machine-man-preview+json',
281+
'Accept': 'application/vnd.github.v3+json',
282282
'Authorization': 'Bearer {}'.format(_jwt),
283283
}
284284
if self.is_authorization():
@@ -316,7 +316,7 @@ def get_access_token(self, *, access_token_response: Optional[Union[list, dict]]
316316
"""
317317
if access_token_response is None:
318318
access_token_response = self.get_access_token_response()
319-
return access_token_response['access_token']
319+
return access_token_response["token"]
320320

321321
def get_usage(self) -> None:
322322
return None

setup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name='githubapp',
5+
version='0.1.0',
6+
license='MIT',
7+
description='This is a wrapper for the Github Apps API.',
8+
author='RTa-technology',
9+
packages=["githubapp"],
10+
)

0 commit comments

Comments
 (0)