1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 11:34:18 +00:00
This commit is contained in:
Steffo 2020-08-28 17:36:14 +02:00
parent c6473b66f1
commit 97c9af51b2
8 changed files with 65 additions and 52 deletions

50
poetry.lock generated
View file

@ -122,7 +122,7 @@ humanfriendly = ">=4.7"
[[package]]
name = "cryptography"
version = "3.0"
version = "3.1"
description = "cryptography is a package which provides cryptographic recipes and primitives to Python developers."
category = "main"
optional = false
@ -131,7 +131,6 @@ python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*"
[package.extras]
docs = ["sphinx (>=1.6.5,<1.8.0 || >1.8.0,<3.1.0 || >3.1.0,<3.1.1 || >3.1.1)", "sphinx-rtd-theme"]
docstest = ["doc8", "pyenchant (>=1.6.11)", "twine (>=1.12.0)", "sphinxcontrib-spelling (>=4.0.1)"]
idna = ["idna (>=2.1)"]
pep8test = ["black", "flake8", "flake8-import-order", "pep8-naming"]
ssh = ["bcrypt (>=3.1.5)"]
test = ["pytest (>=3.6.0,<3.9.0 || >3.9.0,<3.9.1 || >3.9.1,<3.9.2 || >3.9.2)", "pretend", "iso8601", "pytz", "hypothesis (>=1.11.4,<3.79.2 || >3.79.2)"]
@ -368,7 +367,7 @@ requests = "*"
[[package]]
name = "royalnet"
version = "5.11.4"
version = "5.11.6"
description = "A multipurpose bot and web framework"
category = "main"
optional = false
@ -711,25 +710,28 @@ coloredlogs = [
{file = "coloredlogs-10.0.tar.gz", hash = "sha256:b869a2dda3fa88154b9dd850e27828d8755bfab5a838a1c97fbc850c6e377c36"},
]
cryptography = [
{file = "cryptography-3.0-cp27-cp27m-macosx_10_10_x86_64.whl", hash = "sha256:ab49edd5bea8d8b39a44b3db618e4783ef84c19c8b47286bf05dfdb3efb01c83"},
{file = "cryptography-3.0-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:124af7255ffc8e964d9ff26971b3a6153e1a8a220b9a685dc407976ecb27a06a"},
{file = "cryptography-3.0-cp27-cp27m-manylinux2010_x86_64.whl", hash = "sha256:51e40123083d2f946794f9fe4adeeee2922b581fa3602128ce85ff813d85b81f"},
{file = "cryptography-3.0-cp27-cp27m-win32.whl", hash = "sha256:dea0ba7fe6f9461d244679efa968d215ea1f989b9c1957d7f10c21e5c7c09ad6"},
{file = "cryptography-3.0-cp27-cp27m-win_amd64.whl", hash = "sha256:8ecf9400d0893836ff41b6f977a33972145a855b6efeb605b49ee273c5e6469f"},
{file = "cryptography-3.0-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:0c608ff4d4adad9e39b5057de43657515c7da1ccb1807c3a27d4cf31fc923b4b"},
{file = "cryptography-3.0-cp27-cp27mu-manylinux2010_x86_64.whl", hash = "sha256:bec7568c6970b865f2bcebbe84d547c52bb2abadf74cefce396ba07571109c67"},
{file = "cryptography-3.0-cp35-abi3-macosx_10_10_x86_64.whl", hash = "sha256:0cbfed8ea74631fe4de00630f4bb592dad564d57f73150d6f6796a24e76c76cd"},
{file = "cryptography-3.0-cp35-abi3-manylinux1_x86_64.whl", hash = "sha256:a09fd9c1cca9a46b6ad4bea0a1f86ab1de3c0c932364dbcf9a6c2a5eeb44fa77"},
{file = "cryptography-3.0-cp35-abi3-manylinux2010_x86_64.whl", hash = "sha256:ce82cc06588e5cbc2a7df3c8a9c778f2cb722f56835a23a68b5a7264726bb00c"},
{file = "cryptography-3.0-cp35-cp35m-win32.whl", hash = "sha256:9367d00e14dee8d02134c6c9524bb4bd39d4c162456343d07191e2a0b5ec8b3b"},
{file = "cryptography-3.0-cp35-cp35m-win_amd64.whl", hash = "sha256:384d7c681b1ab904fff3400a6909261cae1d0939cc483a68bdedab282fb89a07"},
{file = "cryptography-3.0-cp36-cp36m-win32.whl", hash = "sha256:4d355f2aee4a29063c10164b032d9fa8a82e2c30768737a2fd56d256146ad559"},
{file = "cryptography-3.0-cp36-cp36m-win_amd64.whl", hash = "sha256:45741f5499150593178fc98d2c1a9c6722df88b99c821ad6ae298eff0ba1ae71"},
{file = "cryptography-3.0-cp37-cp37m-win32.whl", hash = "sha256:8ecef21ac982aa78309bb6f092d1677812927e8b5ef204a10c326fc29f1367e2"},
{file = "cryptography-3.0-cp37-cp37m-win_amd64.whl", hash = "sha256:4b9303507254ccb1181d1803a2080a798910ba89b1a3c9f53639885c90f7a756"},
{file = "cryptography-3.0-cp38-cp38-win32.whl", hash = "sha256:8713ddb888119b0d2a1462357d5946b8911be01ddbf31451e1d07eaa5077a261"},
{file = "cryptography-3.0-cp38-cp38-win_amd64.whl", hash = "sha256:bea0b0468f89cdea625bb3f692cd7a4222d80a6bdafd6fb923963f2b9da0e15f"},
{file = "cryptography-3.0.tar.gz", hash = "sha256:8e924dbc025206e97756e8903039662aa58aa9ba357d8e1d8fc29e3092322053"},
{file = "cryptography-3.1-cp27-cp27m-macosx_10_10_x86_64.whl", hash = "sha256:969ae512a250f869c1738ca63be843488ff5cc031987d302c1f59c7dbe1b225f"},
{file = "cryptography-3.1-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:b45ab1c6ece7c471f01c56f5d19818ca797c34541f0b2351635a5c9fe09ac2e0"},
{file = "cryptography-3.1-cp27-cp27m-manylinux2010_x86_64.whl", hash = "sha256:247df238bc05c7d2e934a761243bfdc67db03f339948b1e2e80c75d41fc7cc36"},
{file = "cryptography-3.1-cp27-cp27m-win32.whl", hash = "sha256:10c9775a3f31610cf6b694d1fe598f2183441de81cedcf1814451ae53d71b13a"},
{file = "cryptography-3.1-cp27-cp27m-win_amd64.whl", hash = "sha256:9f734423eb9c2ea85000aa2476e0d7a58e021bc34f0a373ac52a5454cd52f791"},
{file = "cryptography-3.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:e7563eb7bc5c7e75a213281715155248cceba88b11cb4b22957ad45b85903761"},
{file = "cryptography-3.1-cp27-cp27mu-manylinux2010_x86_64.whl", hash = "sha256:94191501e4b4009642be21dde2a78bd3c2701a81ee57d3d3d02f1d99f8b64a9e"},
{file = "cryptography-3.1-cp35-abi3-macosx_10_10_x86_64.whl", hash = "sha256:dc3f437ca6353979aace181f1b790f0fc79e446235b14306241633ab7d61b8f8"},
{file = "cryptography-3.1-cp35-abi3-manylinux1_x86_64.whl", hash = "sha256:725875681afe50b41aee7fdd629cedbc4720bab350142b12c55c0a4d17c7416c"},
{file = "cryptography-3.1-cp35-abi3-manylinux2010_x86_64.whl", hash = "sha256:321761d55fb7cb256b771ee4ed78e69486a7336be9143b90c52be59d7657f50f"},
{file = "cryptography-3.1-cp35-abi3-manylinux2014_aarch64.whl", hash = "sha256:2a27615c965173c4c88f2961cf18115c08fedfb8bdc121347f26e8458dc6d237"},
{file = "cryptography-3.1-cp35-cp35m-win32.whl", hash = "sha256:e7dad66a9e5684a40f270bd4aee1906878193ae50a4831922e454a2a457f1716"},
{file = "cryptography-3.1-cp35-cp35m-win_amd64.whl", hash = "sha256:4005b38cd86fc51c955db40b0f0e52ff65340874495af72efabb1bb8ca881695"},
{file = "cryptography-3.1-cp36-abi3-win32.whl", hash = "sha256:cc6096c86ec0de26e2263c228fb25ee01c3ff1346d3cfc219d67d49f303585af"},
{file = "cryptography-3.1-cp36-abi3-win_amd64.whl", hash = "sha256:2e26223ac636ca216e855748e7d435a1bf846809ed12ed898179587d0cf74618"},
{file = "cryptography-3.1-cp36-cp36m-win32.whl", hash = "sha256:7a63e97355f3cd77c94bd98c59cb85fe0efd76ea7ef904c9b0316b5bbfde6ed1"},
{file = "cryptography-3.1-cp36-cp36m-win_amd64.whl", hash = "sha256:4b9e96543d0784acebb70991ebc2dbd99aa287f6217546bb993df22dd361d41c"},
{file = "cryptography-3.1-cp37-cp37m-win32.whl", hash = "sha256:eb80a288e3cfc08f679f95da72d2ef90cb74f6d8a8ba69d2f215c5e110b2ca32"},
{file = "cryptography-3.1-cp37-cp37m-win_amd64.whl", hash = "sha256:180c9f855a8ea280e72a5d61cf05681b230c2dce804c48e9b2983f491ecc44ed"},
{file = "cryptography-3.1-cp38-cp38-win32.whl", hash = "sha256:fa7fbcc40e2210aca26c7ac8a39467eae444d90a2c346cbcffd9133a166bcc67"},
{file = "cryptography-3.1-cp38-cp38-win_amd64.whl", hash = "sha256:548b0818e88792318dc137d8b1ec82a0ab0af96c7f0603a00bb94f896fbf5e10"},
{file = "cryptography-3.1.tar.gz", hash = "sha256:26409a473cc6278e4c90f782cd5968ebad04d3911ed1c402fc86908c17633e08"},
]
dateparser = [
{file = "dateparser-0.7.6-py2.py3-none-any.whl", hash = "sha256:7552c994f893b5cb8fcf103b4cd2ff7f57aab9bfd2619fdf0cf571c0740fd90b"},
@ -919,8 +921,8 @@ riotwatcher = [
{file = "riotwatcher-3.0.0.tar.gz", hash = "sha256:bf8b8eb7e13c794730c18cd7846513cf22295a068204433117ce4d83a25b0fd2"},
]
royalnet = [
{file = "royalnet-5.11.4-py3-none-any.whl", hash = "sha256:c10bdd8fa7573338a4cba6e0c9dd0937e60aef2fc57f9e57e4b6e3dac77a3251"},
{file = "royalnet-5.11.4.tar.gz", hash = "sha256:6175c694bbb445de932c46b0bb0a1bfbcf661c5f7000c216ccdadc47c074d675"},
{file = "royalnet-5.11.6-py3-none-any.whl", hash = "sha256:305ee642700954fcd292d0fc322f0630bb37979d32e1663ab7e62705f4c8d7b6"},
{file = "royalnet-5.11.6.tar.gz", hash = "sha256:30c0a19bda9d0afb3c5b795684825b7c38a458908bc8078c75f6d699eaa636e9"},
]
royalspells = [
{file = "royalspells-3.2.tar.gz", hash = "sha256:2bd4a9a66514532e35c02c3907425af48c7cb292364c4843c795719a82b25dfe"},

View file

@ -2,7 +2,7 @@
[tool.poetry]
name = "royalpack"
version = "5.14.2"
version = "5.14.3"
description = "A Royalnet command pack for the Royal Games community"
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
license = "AGPL-3.0+"

View file

@ -57,9 +57,7 @@ class OsuCommand(LinkerCommand):
async def update(self, session, obj: Osu, change: Callable[[str, Any], Awaitable[None]]):
await obj.refresh_if_expired(client_id=self.client_id,
client_secret=self.client_secret,
base_url=self.base_url,
path=ApiAuthLoginOsuStar.path)
client_secret=self.client_secret)
async with aiohttp.ClientSession(headers={"Authorization": f"Bearer {obj.access_token}"}) as session:
async with session.get("https://osu.ppy.sh/api/v2/me/osu") as response:
m = await response.json()

View file

@ -6,7 +6,7 @@ import itsdangerous
import aiohttp
import aiohttp.client_exceptions
import datetime
from ..types import oauth_refresh
from ..types import oauth_refresh, oauth_auth
from ..tables import Osu
@ -60,11 +60,11 @@ class ApiAuthLoginOsuStar(rca.ApiStar):
user = None
try:
t = await oauth_refresh(url="https://osu.ppy.sh/oauth/token",
client_id=self.client_id,
client_secret=self.client_secret,
redirect_uri=f"{self.base_url}{self.path}",
refresh_code=code)
t = await oauth_auth(url="https://osu.ppy.sh/oauth/token",
client_id=self.client_id,
client_secret=self.client_secret,
redirect_uri=f"{self.base_url}{self.path}",
auth_code=code)
except aiohttp.client_exceptions.ClientResponseError as e:
ru.sentry_exc(e)
raise rca.ForbiddenError("osu! API returned an error in the OAuth token exchange")

View file

@ -60,19 +60,18 @@ class Osu(Updatable):
def mania_pp(self):
return Column(Float)
async def refresh(self, *, client_id, client_secret, base_url, path):
async def refresh(self, *, client_id, client_secret):
j = await oauth_refresh(url="https://osu.ppy.sh/oauth/token",
client_id=client_id,
client_secret=client_secret,
redirect_uri=f"{base_url}{path}",
refresh_code=self.refresh_token)
self.access_token = j["access_token"]
self.refresh_token = j["refresh_token"]
self.expiration_date = datetime.datetime.now() + datetime.timedelta(seconds=j["expires_in"])
async def refresh_if_expired(self, *, client_id, client_secret, base_url, path):
async def refresh_if_expired(self, *, client_id, client_secret):
if datetime.datetime.now() >= self.expiration_date:
await self.refresh(client_id=client_id, client_secret=client_secret, base_url=base_url, path=path)
await self.refresh(client_id=client_id, client_secret=client_secret)
def json(self) -> dict:
return {

View file

@ -11,7 +11,7 @@ from .brawlhallametal import BrawlhallaMetal
from .brawlhallarank import BrawlhallaRank
from .pollmood import PollMood
from .updatable import Updatable
from .oauth_refresh import oauth_refresh
from .oauth import oauth_refresh, oauth_auth
__all__ = [
@ -30,4 +30,5 @@ __all__ = [
"PollMood",
"Updatable",
"oauth_refresh",
"oauth_auth",
]

26
royalpack/types/oauth.py Normal file
View file

@ -0,0 +1,26 @@
import aiohttp
async def oauth_auth(*, url, client_id, client_secret, redirect_uri, auth_code):
async with aiohttp.ClientSession() as session:
async with session.post(url, data={
"client_id": client_id,
"client_secret": client_secret,
"code": auth_code,
"grant_type": "authorization_code",
"redirect_uri": redirect_uri
}) as response:
j = await response.json()
return j
async def oauth_refresh(*, url, client_id, client_secret, refresh_code):
async with aiohttp.ClientSession() as session:
async with session.post(url, data={
"client_id": client_id,
"client_secret": client_secret,
"code": refresh_code,
"grant_type": "refresh_token"
}) as response:
j = await response.json()
return j

View file

@ -1,13 +0,0 @@
import aiohttp
async def oauth_refresh(*, url, client_id, client_secret, redirect_uri, refresh_code):
async with aiohttp.ClientSession() as session:
async with session.post(url, data={
"client_id": client_id,
"client_secret": client_secret,
"code": refresh_code,
"grant_type": "refresh_token"
}) as response:
j = await response.json()
return j