Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions discordoauth2/async_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def fetch_identify(self) -> dict:
return await response.json()
elif response.status == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status == 429:
raise Exceptions.RateLimited(
Expand All @@ -54,7 +54,7 @@ async def fetch_connections(self) -> list[dict]:
return await response.json()
elif response.status == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status == 429:
raise Exceptions.RateLimited(
Expand All @@ -78,7 +78,7 @@ async def fetch_guilds(self) -> list[dict]:
return await response.json()
elif response.status == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status == 429:
raise Exceptions.RateLimited(
Expand All @@ -104,7 +104,7 @@ async def fetch_guild_member(self, guild_id: int) -> dict:
return await response.json()
elif response.status == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status == 404:
raise Exceptions.HTTPException(
Expand Down Expand Up @@ -133,10 +133,10 @@ async def join_guild(

guild_id: The guild ID to add the user to
user_id: The ID of the user. Retrievable with `PartialAccessToken.fetch_identify()['id']`
nick: The nickname to give the user apon joining. Bot must also have `MANAGE_NICKNAMES`
role_ids: A list of role IDs to give the user apon joining (bypasses Membership Screening). Bot must also have `MANAGE_ROLES`
mute: Wether the user is muted in voice channels apon joining. Bot must also have `MUTE_MEMBERS`
deaf: Wether the user is deaf in voice channels apon joining. Bot must also have `DEAFEN_MEMBERS`
nick: The nickname to give the user upon joining. Bot must also have `MANAGE_NICKNAMES`
role_ids: A list of role IDs to give the user upon joining (bypasses Membership Screening). Bot must also have `MANAGE_ROLES`
mute: Wether the user is muted in voice channels upon joining. Bot must also have `MUTE_MEMBERS`
deaf: Wether the user is deaf in voice channels upon joining. Bot must also have `DEAFEN_MEMBERS`
"""
async with aiohttp.ClientSession() as session:
async with session.put(
Expand Down Expand Up @@ -187,7 +187,7 @@ async def fetch_metadata(self):
return await response.json()
elif response.status == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status == 429:
raise Exceptions.RateLimited(
Expand Down Expand Up @@ -234,7 +234,7 @@ def metadataTypeHook(item):
return await response.json()
elif response.status == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status == 429:
raise Exceptions.RateLimited(
Expand All @@ -258,7 +258,7 @@ async def clear_metadata(self):
return await response.json()
elif response.status == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status == 429:
raise Exceptions.RateLimited(
Expand Down Expand Up @@ -320,7 +320,7 @@ async def update_linked_roles_metadata(self, metadata: list[dict]):
return await response.json()
elif response.status == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status == 429:
raise Exceptions.RateLimited(
Expand All @@ -333,7 +333,7 @@ async def update_linked_roles_metadata(self, metadata: list[dict]):
)

def from_access_token(self, access_token: str) -> AsyncPartialAccessToken:
"""Creates a `PartialAccessToken` from a access token string.
"""Creates a `PartialAccessToken` from an access token string.

access_token: access token from `PartialAccessToken.token`
"""
Expand All @@ -342,7 +342,7 @@ def from_access_token(self, access_token: str) -> AsyncPartialAccessToken:
async def exchange_code(self, code: str) -> AsyncAccessToken:
"""Converts a code from the redirect url into a `AccessToken`

code: `code` paramater from OAuth2 redirect URL
code: `code` parameter from OAuth2 redirect URL
"""
async with aiohttp.ClientSession() as session:
async with session.post(
Expand Down Expand Up @@ -402,7 +402,7 @@ async def refresh_token(self, refresh_token: str) -> AsyncAccessToken:
f"Unexpected HTTP {response.status}"
)

async def client_credentails_grant(
async def client_credentials_grant(
self, scope: list[str]
) -> AsyncAccessToken:
"""Creates an `AccessToken` on behalf of the application's owner. If the owner is a team, then only `identify` and `applications.commands.update` are allowed.
Expand Down Expand Up @@ -467,6 +467,7 @@ def generate_uri(
scope: Union[str, list[str]],
state: Optional[str] = None,
skip_prompt: Optional[bool] = False,
integration_type: Optional[Literal["guild", "user"]] = "user",
response_type: Optional[Literal["code", "token"]] = "code",
guild_id: Optional[Union[int, str]] = None,
disable_guild_select: Optional[bool] = None,
Expand All @@ -493,4 +494,6 @@ def generate_uri(
"disable_guild_select": disable_guild_select,
"permissions": permissions,
}
if "applications.commands" in scope:
params["integration_type"] = 0 if integration_type == "guild" else 1
return f"https://discord.com/oauth2/authorize?{parse.urlencode({key: value for key, value in params.items() if value is not None})}"
35 changes: 19 additions & 16 deletions discordoauth2/sync_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def fetch_identify(self) -> dict:
return response.json()
elif response.status_code == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status_code == 429:
raise Exceptions.RateLimited(
Expand All @@ -50,7 +50,7 @@ def fetch_connections(self) -> list[dict]:
return response.json()
elif response.status_code == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status_code == 429:
raise Exceptions.RateLimited(
Expand All @@ -74,7 +74,7 @@ def fetch_guilds(self) -> list[dict]:
return response.json()
elif response.status_code == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status_code == 429:
raise Exceptions.RateLimited(
Expand All @@ -100,7 +100,7 @@ def fetch_guild_member(self, guild_id: int) -> dict:
return response.json()
elif response.status_code == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status_code == 404:
raise Exceptions.HTTPException(f"user is not in this guild.")
Expand All @@ -127,10 +127,10 @@ def join_guild(

guild_id: The guild ID to add the user to
user_id: The ID of the user. Retrievable with `PartialAccessToken.fetch_identify()['id']`
nick: The nickname to give the user apon joining. Bot must also have `MANAGE_NICKNAMES`
role_ids: A list of role IDs to give the user apon joining (bypasses Membership Screening). Bot must also have `MANAGE_ROLES`
mute: Wether the user is muted in voice channels apon joining. Bot must also have `MUTE_MEMBERS`
deaf: Wether the user is deaf in voice channels apon joining. Bot must also have `DEAFEN_MEMBERS`
nick: The nickname to give the user upon joining. Bot must also have `MANAGE_NICKNAMES`
role_ids: A list of role IDs to give the user upon joining (bypasses Membership Screening). Bot must also have `MANAGE_ROLES`
mute: Wether the user is muted in voice channels upon joining. Bot must also have `MUTE_MEMBERS`
deaf: Wether the user is deaf in voice channels upon joining. Bot must also have `DEAFEN_MEMBERS`
"""
response = requests.put(
f"https://discord.com/api/v10/guilds/{guild_id}/members/{user_id}",
Expand All @@ -150,7 +150,7 @@ def join_guild(
return response.json()
elif response.status_code == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status_code == 403:
raise Exceptions.Forbidden(
Expand All @@ -177,7 +177,7 @@ def fetch_metadata(self):
return response.json()
elif response.status_code == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status_code == 429:
raise Exceptions.RateLimited(
Expand Down Expand Up @@ -224,7 +224,7 @@ def metadataTypeHook(item):
return response.json()
elif response.status_code == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status_code == 429:
raise Exceptions.RateLimited(
Expand All @@ -248,7 +248,7 @@ def clear_metadata(self):
return response.json()
elif response.status_code == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status_code == 429:
raise Exceptions.RateLimited(
Expand Down Expand Up @@ -307,7 +307,7 @@ def update_linked_roles_metadata(self, metadata: list[dict]):
)

def from_access_token(self, access_token: str) -> PartialAccessToken:
"""Creates a `PartialAccessToken` from a access token string.
"""Creates a `PartialAccessToken` from an access token string.

access_token: access token from `PartialAccessToken.token`
"""
Expand All @@ -316,7 +316,7 @@ def from_access_token(self, access_token: str) -> PartialAccessToken:
def exchange_code(self, code: str) -> AccessToken:
"""Converts a code from the redirect url into a `AccessToken`

code: `code` paramater from OAuth2 redirect URL
code: `code` parameter from OAuth2 redirect URL
"""
response = requests.post(
"https://discord.com/api/v10/oauth2/token",
Expand Down Expand Up @@ -376,7 +376,7 @@ def refresh_token(self, refresh_token: str) -> AccessToken:
f"Unexpected HTTP {response.status_code}"
)

def client_credentails_grant(self, scope: list[str]) -> AccessToken:
def client_credentials_grant(self, scope: list[str]) -> AccessToken:
"""Creates an `AccessToken` on behalf of the application's owner. If the owner is a team, then only `identify` and `applications.commands.update` are allowed.

scope: list of string scopes to authorize.
Expand Down Expand Up @@ -421,7 +421,7 @@ def revoke_token(self, token: str, token_type: str = None):
return
elif response.status_code == 401:
raise Exceptions.Forbidden(
f"this AccessToken does not have the nessasary scope."
f"this AccessToken does not have the necessary scope."
)
elif response.status_code == 429:
raise Exceptions.RateLimited(
Expand All @@ -438,6 +438,7 @@ def generate_uri(
scope: Union[str, list[str]],
state: Optional[str] = None,
skip_prompt: Optional[bool] = False,
integration_type: Optional[Literal["guild", "user"]] = "user",
response_type: Optional[Literal["code", "token"]] = "code",
guild_id: Optional[Union[int, str]] = None,
disable_guild_select: Optional[bool] = None,
Expand All @@ -464,4 +465,6 @@ def generate_uri(
"disable_guild_select": disable_guild_select,
"permissions": permissions,
}
if "applications.commands" in scope:
params["integration_type"] = 0 if integration_type == "guild" else 1
return f"https://discord.com/oauth2/authorize?{parse.urlencode({key: value for key, value in params.items() if value is not None})}"
14 changes: 7 additions & 7 deletions docs/source/access_token.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ AccessToken

.. attribute:: webhook

A `parital webhook object <https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure>`__ if they was a ``webhook.incoming`` scope.
A `partial webhook object <https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure>`__ if they was a ``webhook.incoming`` scope.

:type: dict

Expand Down Expand Up @@ -94,7 +94,7 @@ AccessToken
:param str nick: The nickname the member should have when they join.
:param list[int] role_ids: a List of role IDs to assign them when they join.
:param bool mute: Wether they should be server muted when they join.
:param bool deaf: Wether they should be server deafend when they join.
:param bool deaf: Wether they should be server deafened when they join.

:returns: dict
:raises discordoauth2.exceptions.HTTPException: The request failed
Expand Down Expand Up @@ -122,8 +122,8 @@ AccessToken

.. versionadded:: 1.1

:param str platform_name: Text that appears at the top of the app connection box, usally denoting the platform's name.
:param str platform_username: Text that appears under the platform name, large, and usally denoting the user's name on the platform.
:param str platform_name: Text that appears at the top of the app connection box, usually denoting the platform's name.
:param str platform_username: Text that appears under the platform name, large, and usually denoting the user's name on the platform.
:param dict metadata: List of keys and values to set the user's metadata. Supported types: :class:`bool`, :class:`datetime.datetime`, :class:`int`

:returns: dict
Expand Down Expand Up @@ -227,7 +227,7 @@ AccessToken
:param str nick: The nickname the member should have when they join.
:param list[int] role_ids: a List of role IDs to assign them when they join.
:param bool mute: Wether they should be server muted when they join.
:param bool deaf: Wether they should be server deafend when they join.
:param bool deaf: Wether they should be server deafened when they join.

:returns: dict
:raises discordoauth2.exceptions.HTTPException: The request failed
Expand All @@ -251,8 +251,8 @@ AccessToken

.. versionadded:: 1.1

:param str platform_name: Text that appears at the top of the app connection box, usally denoting the platform's name.
:param str platform_username: Text that appears under the platform name, large, and usally denoting the user's name on the platform.
:param str platform_name: Text that appears at the top of the app connection box, usually denoting the platform's name.
:param str platform_username: Text that appears under the platform name, large, and usually denoting the user's name on the platform.
:param dict metadata: List of keys and values to set the user's metadata. Supported types: :class:`bool`, :class:`datetime.datetime`, :class:`int`

:returns: dict
Expand Down
Loading