|
37 | 37 | import datetime |
38 | 38 |
|
39 | 39 | from twitchio.types_.responses import ( |
| 40 | + AuthorizationByUserResponseData, |
40 | 41 | UserActiveExtensionsResponseData, |
41 | 42 | UserExtensionsResponseData, |
42 | 43 | UserPanelComponentItem, |
|
75 | 76 | from .models.subscriptions import BroadcasterSubscriptions, UserSubscription |
76 | 77 | from .models.teams import ChannelTeam |
77 | 78 |
|
78 | | -__all__ = ("ActiveExtensions", "Extension", "PartialUser", "User") |
| 79 | +__all__ = ("ActiveExtensions", "Extension", "PartialUser", "User", "UserAuthorisation") |
79 | 80 |
|
80 | 81 |
|
81 | 82 | class PartialUser: |
@@ -3211,6 +3212,20 @@ async def update(self, description: str | None = None) -> User: |
3211 | 3212 | data = await self._http.put_user(token_for=self.id, description=description) |
3212 | 3213 | return User(data["data"][0], http=self._http) |
3213 | 3214 |
|
| 3215 | + async def fetch_auth(self) -> UserAuthorisation: |
| 3216 | + """|coro| |
| 3217 | +
|
| 3218 | + Fetches the user's authentication information. |
| 3219 | +
|
| 3220 | + Returns |
| 3221 | + ------- |
| 3222 | + UserAuthorisation |
| 3223 | + UserAuthorisation object. |
| 3224 | + """ |
| 3225 | + |
| 3226 | + data = await self._http.get_auth_by_user(user_ids=[self.id]) |
| 3227 | + return UserAuthorisation(data["data"][0], http=self._http) |
| 3228 | + |
3214 | 3229 | def fetch_block_list(self, *, first: int = 20, max_results: int | None = None) -> HTTPAsyncIterator[PartialUser]: |
3215 | 3230 | """|aiter| |
3216 | 3231 |
|
@@ -4087,3 +4102,29 @@ async def follow_info(self) -> ChannelFollowerEvent | None: |
4087 | 4102 | user_id=self, broadcaster_id=self.channel, token_for=self.channel, max_results=1 |
4088 | 4103 | ) |
4089 | 4104 | return await anext(data.followers, None) |
| 4105 | + |
| 4106 | + |
| 4107 | +class UserAuthorisation: |
| 4108 | + """A class that contains authorisation information for a user against a Client ID / Twitch application. |
| 4109 | +
|
| 4110 | + Attributes |
| 4111 | + ----------- |
| 4112 | + user: PartialUser |
| 4113 | + The user having authorised checked. |
| 4114 | + scopes: Scopes |
| 4115 | + The scopes the user has granted to the Client ID / application. |
| 4116 | + authorised: bool |
| 4117 | + Whether the user has authorised the Client ID / application. |
| 4118 | + """ |
| 4119 | + |
| 4120 | + __slots__ = ("authorised", "scopes", "user") |
| 4121 | + |
| 4122 | + def __init__(self, data: AuthorizationByUserResponseData, *, http: HTTPClient) -> None: |
| 4123 | + from .authentication import Scopes |
| 4124 | + |
| 4125 | + self.user: PartialUser = PartialUser(data["user_id"], data["user_login"], data["user_name"], http=http) |
| 4126 | + self.scopes: Scopes = Scopes(data["scopes"]) |
| 4127 | + self.authorised: bool = bool(data["has_authorized"]) |
| 4128 | + |
| 4129 | + def __repr__(self) -> str: |
| 4130 | + return f"<UserAuthorisation user={self.user} authorised={self.authorised}>" |
0 commit comments