Skip to content

Commit

Permalink
[Spotify] Add OAuth support via dashboard's generic OAuth handler
Browse files Browse the repository at this point in the history
  • Loading branch information
TrustyJAID committed Apr 8, 2024
1 parent 03ddb22 commit afe9af9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions spotify/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,29 @@ async def get_user_spotify(
yield client
client._token_cv.reset(cv_token)

@commands.Cog.listener()
async def on_oauth_receive(self, user_id: int, payload: dict):
if payload["provider"] != "spotify":
return
if "code" not in payload:
log.error("Received Spotify OAuth without a code parameter %s - %s", user_id, payload)
return

try:
code = payload["code"]
state = payload["state"]
auth = self.temp_cache[int(user_id)]
user_token = await auth.request_token(code=code, state=state)
user = self.bot.get_user(user_id)
await self.save_token(user, user_token)
del self.cog.temp_cache[user.id]
self.dashboard_authed.append(user.id)
except KeyError:
log.error("Recieved Spotify Auth request but the user was not in the cache.")
return
except Exception:
log.exception("Error setting user OAuth in Spotify")

async def get_user_auth(
self,
ctx: commands.Context,
Expand Down

0 comments on commit afe9af9

Please sign in to comment.