From 4615555898a450be91de9b7be09555df4b159632 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 4 Mar 2022 19:42:44 +0100 Subject: [PATCH 01/11] Adding a scope to spotify --- api/src/Api/OIDC.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/Api/OIDC.hs b/api/src/Api/OIDC.hs index fd96da9..c9da523 100644 --- a/api/src/Api/OIDC.hs +++ b/api/src/Api/OIDC.hs @@ -62,7 +62,7 @@ urlHandler Spotify (Just r) = do clientId <- liftIO $ envAsString "SPOTIFY_CLIENT_ID" "" backRedirect <- liftIO $ envAsString "BACK_URL" "" throwError $ err302 { errHeaders = - [("Location", B8.pack $ "https://accounts.spotify.com/authorize?response_type=code&scope=user-library-read&client_id=" ++ clientId ++ "&redirect_uri=" ++ backRedirect ++ "auth/redirect" ++ "&state=" ++ r)] } + [("Location", B8.pack $ "https://accounts.spotify.com/authorize?response_type=code&scope=user-library-read user-library-write&client_id=" ++ clientId ++ "&redirect_uri=" ++ backRedirect ++ "auth/redirect" ++ "&state=" ++ r)] } urlHandler Github (Just r) = do clientId <- liftIO $ envAsString "GITHUB_CLIENT_ID" "" backRedirect <- liftIO $ envAsString "BACK_URL" "" From e21e49456aa4af6b1e6e79b726610c32b251337d Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 4 Mar 2022 21:47:50 +0100 Subject: [PATCH 02/11] Adding more scopes for spotify --- api/src/Api/OIDC.hs | 3 ++- worker/src/services/spotify.ts | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/src/Api/OIDC.hs b/api/src/Api/OIDC.hs index c9da523..6b11a72 100644 --- a/api/src/Api/OIDC.hs +++ b/api/src/Api/OIDC.hs @@ -62,7 +62,8 @@ urlHandler Spotify (Just r) = do clientId <- liftIO $ envAsString "SPOTIFY_CLIENT_ID" "" backRedirect <- liftIO $ envAsString "BACK_URL" "" throwError $ err302 { errHeaders = - [("Location", B8.pack $ "https://accounts.spotify.com/authorize?response_type=code&scope=user-library-read user-library-write&client_id=" ++ clientId ++ "&redirect_uri=" ++ backRedirect ++ "auth/redirect" ++ "&state=" ++ r)] } + [("Location", B8.pack $ "https://accounts.spotify.com/authorize?response_type=code&scope=user-library-read user-library-modify streaming playlist-modify-private playlist-read-collaborative playlist-read-private playlist-modify-public user-modify-playback-state user-read-private&client_id=" ++ clientId ++ "&redirect_uri=" ++ backRedirect ++ "auth/redirect" ++ "&state=" ++ r)] } + urlHandler Github (Just r) = do clientId <- liftIO $ envAsString "GITHUB_CLIENT_ID" "" backRedirect <- liftIO $ envAsString "BACK_URL" "" diff --git a/worker/src/services/spotify.ts b/worker/src/services/spotify.ts index 8be3082..c2d3820 100644 --- a/worker/src/services/spotify.ts +++ b/worker/src/services/spotify.ts @@ -73,7 +73,11 @@ export class Spotify extends BaseService { async playTrack(params: any): Promise { await this._refreshIfNeeded(); let track = await this._searchTrack(params['artist'], params['track']); - await this._spotify.play({uris: [track.uri]}); + try { + await this._spotify.play({uris: [track.uri]}); + } catch (e) { + throw new Error("Spotify premium is required."); + } return { URL: track.uri, ARTIST: track.artists?.[0].name, From 28194d32ad0b68f3801bff08713636b114f5aea1 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 4 Mar 2022 23:54:06 +0100 Subject: [PATCH 03/11] Using spotify ids instead of search --- api/services/spotify.json | 124 ++++----------------------------- worker/src/services/spotify.ts | 58 ++++----------- 2 files changed, 26 insertions(+), 156 deletions(-) diff --git a/api/services/spotify.json b/api/services/spotify.json index 99aba86..33c337a 100644 --- a/api/services/spotify.json +++ b/api/services/spotify.json @@ -80,45 +80,15 @@ }, "params": [ { - "name": "artist", + "name": "trackUri", "type": "string", "description": { - "en": "Artist of the song to play", - "fr": "Interprète de la musique à jouer" - } - }, - { - "name": "track", - "type": "string", - "description": { - "en": "Title of the song to play", - "fr": "Titre de la musique à jouer" + "en": "Url of a track", + "fr": "Url d'une musique'" } } ], - "returns": [ - { - "name": "URL", - "description": { - "en": "URL of the song", - "fr": "URL de la musique" - } - }, - { - "name": "ARTIST", - "description": { - "en": "Artist of the song", - "fr": "Interprête de la musique" - } - }, - { - "name": "TRACK", - "description": { - "en": "Title of the song", - "fr": "Titre de la musique" - } - } - ] + "returns": [] }, { "name": "Spotify_Pause", @@ -145,45 +115,15 @@ }, "params": [ { - "name": "artist", + "name": "trackUri", "type": "string", "description": { - "en": "Artist of the song to add", - "fr": "Interprète de la musique à ajouter" - } - }, - { - "name": "track", - "type": "string", - "description": { - "en": "Title of the song to add", - "fr": "Titre de la musique à ajouter" + "en": "Url of a track", + "fr": "Url d'une musique'" } } ], - "returns": [ - { - "name": "URL", - "description": { - "en": "URL of the added song", - "fr": "URL de la musique ajoutée" - } - }, - { - "name": "ARTIST", - "description": { - "en": "Artist of the added song", - "fr": "Interprète de la musique ajoutée" - } - }, - { - "name": "TRACK", - "description": { - "en": "Title of the added song", - "fr": "Titre de la musique ajoutée" - } - } - ] + "returns": [] }, { "name": "Spotify_AddToPlaylist", @@ -197,53 +137,15 @@ }, "params": [ { - "name": "artist", + "name": "trackUri", "type": "string", "description": { - "en": "Artist of the song to add", - "fr": "Interprète de la musique à ajouter" - } - }, - { - "name": "track", - "type": "string", - "description": { - "en": "Title of the song to add", - "fr": "Titre de la musique à ajouter" - } - }, - { - "name": "playlist", - "type": "string", - "description": { - "en": "Name of the playlist", - "fr": "Nom de la playlist dans laquelle ajouter la musique" + "en": "Url of a track", + "fr": "Url d'une musique'" } } ], - "returns": [ - { - "name": "URL", - "description": { - "en": "URL of the added song", - "fr": "URL de la musique ajoutée" - } - }, - { - "name": "ARTIST", - "description": { - "en": "Artist of the added song", - "fr": "Interprète de la musique ajoutée" - } - }, - { - "name": "TRACK", - "description": { - "en": "Title of the added song", - "fr": "Titre de la musique ajoutée" - } - } - ] + "returns": [] } ] -} \ No newline at end of file +} diff --git a/worker/src/services/spotify.ts b/worker/src/services/spotify.ts index c2d3820..b7d64b4 100644 --- a/worker/src/services/spotify.ts +++ b/worker/src/services/spotify.ts @@ -53,36 +53,15 @@ export class Spotify extends BaseService { }); } - private async _searchTrack(artistName: string, trackName: string) { - await this._refreshIfNeeded(); - let searchResult = await this._spotify.searchTracks(`artist=${artistName}&track=${trackName}`); - if (searchResult.body.tracks.total == 0) - throw new Error(`Spotify API: '${trackName}' by ${artistName}: no such track`); - return searchResult.body.tracks.items[0]; - } - - private async _searchPlaylist(playlistName: string) { - await this._refreshIfNeeded(); - let searchResult = await this._spotify.searchPlaylists(`name=${playlistName}&type=playlist`); - if (searchResult.body.playlists.total == 0) - throw new Error(`Spotify API: '${playlistName}': no such playlist`); - return searchResult.body.playlists.items[0]; - } - - @reaction(ReactionType.PlayTrack, ['artist', 'track']) + @reaction(ReactionType.PlayTrack, ['trackUri']) async playTrack(params: any): Promise { await this._refreshIfNeeded(); - let track = await this._searchTrack(params['artist'], params['track']); - try { - await this._spotify.play({uris: [track.uri]}); - } catch (e) { - throw new Error("Spotify premium is required."); - } - return { - URL: track.uri, - ARTIST: track.artists?.[0].name, - TRACK: track.name, - }; + // try { + await this._spotify.play({uris: [params.trackUri]}); + // } catch (e) { + // throw new Error("Spotify premium is required."); + // } + return {}; } @reaction(ReactionType.Pause, []) @@ -92,29 +71,18 @@ export class Spotify extends BaseService { return {}; } - @reaction(ReactionType.AddTrackToLibrary, ['artist', 'track']) + @reaction(ReactionType.AddTrackToLibrary, ['trackUri']) async addTrackToLibrary(params: any): Promise { await this._refreshIfNeeded(); - let track = await this._searchTrack(params['artist'], params['track']); - await this._spotify.addToMySavedTracks([track.id]); - return { - URL: track.uri, - ARTIST: track.artists?.[0].name, - TRACK: track.name, - }; + await this._spotify.addToMySavedTracks([params.trackUri]); + return {}; } - @reaction(ReactionType.AddToPlaylist, ['artist', 'track', 'playlist']) + @reaction(ReactionType.AddToPlaylist, ['trackUri', 'playlistUri']) async addToPlaylist(params: any): Promise { await this._refreshIfNeeded(); - let playlist = await this._searchPlaylist( params['playlist']); - let track = await this._searchTrack(params['artist'], params['track']); - await this._spotify.addTracksToPlaylist(playlist.id, [track.uri]); - return { - URL: track.uri, - ARTIST: track.artists?.[0].name, - TRACK: track.name, - }; + await this._spotify.addTracksToPlaylist(params.playlistUri, [params.trackUri]); + return {}; } } From 3cb4896fb8941f5c0e9dae0f1d77d0a48c13d66d Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 5 Mar 2022 01:30:45 +0100 Subject: [PATCH 04/11] Handling multiple sumbstitutions on worker patterns --- api/services/spotify.json | 8 ++++++++ worker/src/runner.ts | 2 +- worker/src/services/spotify.ts | 8 ++------ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/services/spotify.json b/api/services/spotify.json index 33c337a..abbc15f 100644 --- a/api/services/spotify.json +++ b/api/services/spotify.json @@ -143,6 +143,14 @@ "en": "Url of a track", "fr": "Url d'une musique'" } + }, + { + "name": "playlistUri", + "type": "string", + "description": { + "en": "Id of the playlist", + "fr": "Id de la playlist dans laquelle ajouter la musique" + } } ], "returns": [] diff --git a/worker/src/runner.ts b/worker/src/runner.ts index af0943f..d439372 100644 --- a/worker/src/runner.ts +++ b/worker/src/runner.ts @@ -27,7 +27,7 @@ export class Runner { for (let [key, value] of Object.entries(params)) { let newValue = value; if (typeof value == "string") { - newValue = value.replace(/{(\w*)(?:@(\d))?}/, (_, name, index) => { + newValue = value.replace(/{(\w*)(?:@(\d))?}/g, (_, name, index) => { if (index) return this._history[parseInt(index)][name] return this._history[this._history.length - 1][name] diff --git a/worker/src/services/spotify.ts b/worker/src/services/spotify.ts index b7d64b4..ce1944e 100644 --- a/worker/src/services/spotify.ts +++ b/worker/src/services/spotify.ts @@ -56,16 +56,12 @@ export class Spotify extends BaseService { @reaction(ReactionType.PlayTrack, ['trackUri']) async playTrack(params: any): Promise { await this._refreshIfNeeded(); - // try { - await this._spotify.play({uris: [params.trackUri]}); - // } catch (e) { - // throw new Error("Spotify premium is required."); - // } + await this._spotify.play({uris: [params.trackUri]}); return {}; } @reaction(ReactionType.Pause, []) - async pause(params: any): Promise { + async pause(_: any): Promise { await this._refreshIfNeeded(); await this._spotify.pause(); return {}; From 606cd07ef79b551ede260a3407787825a8386abd Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 5 Mar 2022 11:26:37 +0100 Subject: [PATCH 05/11] Handling token refresh for spotify and google --- worker/src/models/pipeline.ts | 2 +- worker/src/services/spotify.ts | 17 ++++++++++++++++- worker/src/services/youtube.ts | 16 +++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/worker/src/models/pipeline.ts b/worker/src/models/pipeline.ts index b24ffe5..cf8705c 100644 --- a/worker/src/models/pipeline.ts +++ b/worker/src/models/pipeline.ts @@ -96,7 +96,7 @@ export class Pipeline { export class Token { accessToken: string; refreshToken: string; - expiresIn: string; + expiresAt: string; }; export class Reaction { diff --git a/worker/src/services/spotify.ts b/worker/src/services/spotify.ts index ce1944e..de27122 100644 --- a/worker/src/services/spotify.ts +++ b/worker/src/services/spotify.ts @@ -7,12 +7,14 @@ import { Pipeline, PipelineEnv, PipelineType, ReactionType, ServiceType } from " @service(ServiceType.Spotify) export class Spotify extends BaseService { + private _pipeline: Pipeline; private _spotify; constructor(pipeline: Pipeline) { super(); if (!("Spotify" in pipeline.userData)) throw new Error("User is not authenticated via Spotify"); + this._pipeline = pipeline; this._spotify = new SpotifyWebApi({ accessToken: pipeline.userData["Spotify"].accessToken, refreshToken: pipeline.userData["Spotify"].refreshToken, @@ -22,7 +24,20 @@ export class Spotify extends BaseService { } private async _refreshIfNeeded(): Promise { - + if (Date.parse(this._pipeline.userData["Spotify"].expiresAt) >= Date.now() + 100_000) + return; + const ret = await this._spotify.refreshAccessToken(); + fetch(`${process.env["WORKER_API_URL"]}/spotify/${this._pipeline.userId}?WORKER_API_KEY=${process.env["WORKER_API_KEY"]}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + accessToken: ret.body.access_token, + refreshToken: ret.body.refresh_token, + expiresAt: new Date(Date.now() + ret.body.expires_in), + }), + }); } @action(PipelineType.OnSpotifyAddToPlaylist, ["playlistId"]) diff --git a/worker/src/services/youtube.ts b/worker/src/services/youtube.ts index ade2b6c..9af0a1a 100644 --- a/worker/src/services/youtube.ts +++ b/worker/src/services/youtube.ts @@ -22,9 +22,19 @@ export class Youtube extends BaseService { refresh_token: pipeline.userData["Google"].refreshToken, access_token: pipeline.userData["Google"].accessToken, }); - // client.on("tokens", x => { - // - // }); + client.on("tokens", x => { + fetch(`${process.env["WORKER_API_URL"]}/google/${pipeline.userId}?WORKER_API_KEY=${process.env["WORKER_API_KEY"]}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + accessToken: x.access_token, + refreshToken: x.refresh_token, + expires: x.expiry_date, + }), + }); + }); this._youtube = new youtube_v3.Youtube({ auth: client, }); From 95d9fd5d49877c7ed8e515b2787aa671e37c695d Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 5 Mar 2022 14:29:23 +0100 Subject: [PATCH 06/11] Fixing expiresAt in the model --- worker/src/models/pipeline.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/src/models/pipeline.ts b/worker/src/models/pipeline.ts index cf8705c..fbf200e 100644 --- a/worker/src/models/pipeline.ts +++ b/worker/src/models/pipeline.ts @@ -132,7 +132,7 @@ export const pipelineFromApi = (data: any): Pipeline => { { accessToken: x.accessToken, refreshToken: x.refreshToken, - expiresIn: x.expiresIn + expiresAt: x.expiresAt } as Token ])), }; From 051528a7d9222cae96529879d70bfc5379997616 Mon Sep 17 00:00:00 2001 From: GitBluub Date: Sat, 5 Mar 2022 14:55:53 +0100 Subject: [PATCH 07/11] feat: expiresAt in external token --- api/src/Api/Worker.hs | 3 ++- api/src/Core/OIDC.hs | 35 +++++++++++++++++++++++++++-------- api/src/Core/User.hs | 3 ++- api/src/Utils.hs | 2 +- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/api/src/Api/Worker.hs b/api/src/Api/Worker.hs index 27fa3ed..4c2810c 100644 --- a/api/src/Api/Worker.hs +++ b/api/src/Api/Worker.hs @@ -30,6 +30,7 @@ import Repository.User (updateTokens, getTokensByUserId, delTokens) import GHC.Generics (Generic) import Data.Int (Int64) import Data.Text (Text) +import Data.Time (UTCTime) data WorkerUserData = WorkerUserData @@ -47,7 +48,7 @@ newtype ErrorBody = ErrorBody { error :: Text } data RefreshBody = RefreshBody { accessToken :: Text , refreshToken :: Text - , expiresIn :: Int64 + , expiresIn :: UTCTime } $(deriveJSON defaultOptions ''WorkerUserData) diff --git a/api/src/Core/OIDC.hs b/api/src/Core/OIDC.hs index 15affb2..eb296b4 100644 --- a/api/src/Core/OIDC.hs +++ b/api/src/Core/OIDC.hs @@ -6,13 +6,14 @@ import qualified Data.ByteString.Char8 as B8 import qualified Data.HashMap.Strict as HM import App (AppM) -import Core.User (ExternalToken (ExternalToken), Service (Github, Discord, Spotify, Google, Twitter, Anilist)) +import Core.User (ExternalToken (ExternalToken, expiresAt), Service (Github, Discord, Spotify, Google, Twitter, Anilist)) import Data.Aeson.Types (Object, Value (String)) import Data.Text (Text, pack, unpack) import Network.HTTP.Simple (JSONException, addRequestHeader, getResponseBody, httpJSONEither, parseRequest, setRequestMethod, setRequestQueryString, setRequestBodyURLEncoded) import System.Environment.MrEnv (envAsBool, envAsInt, envAsInteger, envAsString) -import Utils (lookupObjString) +import Utils (lookupObjString, lookupObjInt) import Data.ByteString.Base64 +import Data.Time (getCurrentTime, addUTCTime) data OAuth2Conf = OAuth2Conf { oauthClientId :: String , oauthClientSecret :: String @@ -55,11 +56,14 @@ getGithubTokens code = do ] request' response <- httpJSONEither request + currTime <- getCurrentTime return $ case (getResponseBody response :: Either JSONException Object) of Left _ -> Nothing Right obj -> do access <- lookupObjString obj "access_token" - Just $ ExternalToken (pack access) "" 0 Github + expiresIn <- lookupObjInt obj "expires_in" + let expiresAt = addUTCTime (fromInteger . fromIntegral $ expiresIn) currTime + Just $ ExternalToken (pack access) "" expiresAt Github -- DISCORD getDiscordConfig :: IO OAuth2Conf @@ -86,12 +90,15 @@ getDiscordTokens code = do ] request' response <- httpJSONEither request + currTime <- getCurrentTime return $ case (getResponseBody response :: Either JSONException Object) of Left _ -> Nothing Right obj -> do access <- lookupObjString obj "access_token" refresh <- lookupObjString obj "refresh_token" - Just $ ExternalToken (pack access) (pack refresh) 0 Discord + expiresIn <- lookupObjInt obj "expires_in" + let expiresAt = addUTCTime (fromInteger . fromIntegral $ expiresIn) currTime + Just $ ExternalToken (pack access) (pack refresh) expiresAt Discord -- GOOGLE getGoogleConfig :: IO OAuth2Conf @@ -118,12 +125,15 @@ getGoogleTokens code = do ] request' response <- httpJSONEither request + currTime <- getCurrentTime return $ case (getResponseBody response :: Either JSONException Object) of Left _ -> Nothing Right obj -> do access <- lookupObjString obj "access_token" refresh <- lookupObjString obj "refresh_token" - Just $ ExternalToken (pack access) (pack refresh) 0 Google + expiresIn <- lookupObjInt obj "expires_in" + let expiresAt = addUTCTime (fromInteger . fromIntegral $ expiresIn) currTime + Just $ ExternalToken (pack access) (pack refresh) expiresAt Google -- SPOTIFY getSpotifyConfig :: IO OAuth2Conf @@ -151,12 +161,15 @@ getSpotifyTokens code = do ] request' response <- httpJSONEither request + currTime <- getCurrentTime return $ case (getResponseBody response :: Either JSONException Object) of Left _ -> Nothing Right obj -> do access <- lookupObjString obj "access_token" refresh <- lookupObjString obj "refresh_token" - Just $ ExternalToken (pack access) (pack refresh) 0 Spotify + expiresIn <- lookupObjInt obj "expires_in" + let expiresAt = addUTCTime (fromInteger . fromIntegral $ expiresIn) currTime + Just $ ExternalToken (pack access) (pack refresh) expiresAt Spotify -- TWITTER getTwitterConfig :: IO OAuth2Conf @@ -184,12 +197,15 @@ getTwitterTokens code = do ] request' response <- httpJSONEither request + currTime <- getCurrentTime return $ case (getResponseBody response :: Either JSONException Object) of Left _ -> Nothing Right obj -> do access <- lookupObjString obj "access_token" refresh <- lookupObjString obj "refresh_token" - Just $ ExternalToken (pack access) (pack refresh) 0 Twitter + expiresIn <- lookupObjInt obj "expires_in" + let expiresAt = addUTCTime (fromInteger . fromIntegral $ expiresIn) currTime + Just $ ExternalToken (pack access) (pack refresh) expiresAt Twitter -- ANILIST getAnilistConfig :: IO OAuth2Conf @@ -216,12 +232,15 @@ getAnilistTokens code = do ] request' response <- httpJSONEither request + currTime <- getCurrentTime return $ case (getResponseBody response :: Either JSONException Object) of Left _ -> Nothing Right obj -> do access <- lookupObjString obj "access_token" refresh <- lookupObjString obj "refresh_token" - Just $ ExternalToken (pack access) (pack refresh) 0 Anilist + expiresIn <- lookupObjInt obj "expires_in" + let expiresAt = addUTCTime (fromInteger . fromIntegral $ expiresIn) currTime + Just $ ExternalToken (pack access) (pack refresh) expiresAt Anilist diff --git a/api/src/Core/User.hs b/api/src/Core/User.hs index 3e2f59a..3a7f7b2 100644 --- a/api/src/Core/User.hs +++ b/api/src/Core/User.hs @@ -20,6 +20,7 @@ import Servant (AuthProtect, FromHttpApiData) import Servant.API (FromHttpApiData (parseUrlPiece)) import Servant.Server.Experimental.Auth (AuthServerData) import Servant.Auth.JWT (ToJWT, FromJWT) +import Data.Time (UTCTime) newtype UserId = UserId {toInt64 :: Int64} deriving newtype (DBEq, DBType, Eq, Show, Num, FromJSON, ToJSON, FromHttpApiData) @@ -41,7 +42,7 @@ instance FromHttpApiData Service where data ExternalToken = ExternalToken { accessToken :: Text , refreshToken :: Text - , expiresIn :: Int64 + , expiresAt :: UTCTime , service :: Service } deriving (Eq, Show, Generic) diff --git a/api/src/Utils.hs b/api/src/Utils.hs index 16a04be..7a35ef2 100644 --- a/api/src/Utils.hs +++ b/api/src/Utils.hs @@ -33,7 +33,7 @@ lookupObjString obj key = case Data.HashMap.Strict.lookup key obj of lookupObjInt :: Object -> Text -> Maybe Int64 lookupObjInt obj key = case Data.HashMap.Strict.lookup key obj of - Just (Number x) -> toBoundedInteger $ x + Just (Number x) -> toBoundedInteger x _ -> Nothing uncurry3 :: (a -> b -> c -> d) -> (a, b, c) -> d From f5c2996b931e868f85dcbd75644de7900f8a8a6a Mon Sep 17 00:00:00 2001 From: GitBluub Date: Sat, 5 Mar 2022 14:58:56 +0100 Subject: [PATCH 08/11] fix: github no expires in --- api/src/Core/OIDC.hs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/src/Core/OIDC.hs b/api/src/Core/OIDC.hs index eb296b4..2a74b5d 100644 --- a/api/src/Core/OIDC.hs +++ b/api/src/Core/OIDC.hs @@ -61,9 +61,7 @@ getGithubTokens code = do Left _ -> Nothing Right obj -> do access <- lookupObjString obj "access_token" - expiresIn <- lookupObjInt obj "expires_in" - let expiresAt = addUTCTime (fromInteger . fromIntegral $ expiresIn) currTime - Just $ ExternalToken (pack access) "" expiresAt Github + Just $ ExternalToken (pack access) "" currTime Github -- DISCORD getDiscordConfig :: IO OAuth2Conf From d2dd7dfdbe1394d79c2664e317f1d77006dff545 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 5 Mar 2022 15:15:29 +0100 Subject: [PATCH 09/11] Fixing spotify add to playlist --- worker/src/services/spotify.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/src/services/spotify.ts b/worker/src/services/spotify.ts index de27122..bbe618b 100644 --- a/worker/src/services/spotify.ts +++ b/worker/src/services/spotify.ts @@ -92,7 +92,7 @@ export class Spotify extends BaseService { @reaction(ReactionType.AddToPlaylist, ['trackUri', 'playlistUri']) async addToPlaylist(params: any): Promise { await this._refreshIfNeeded(); - await this._spotify.addTracksToPlaylist(params.playlistUri, [params.trackUri]); + await this._spotify.addTracksToPlaylist(params.playlistUri, ["spotify:track:" + params.trackUri]); return {}; } From 9892c3c8523ad1e2e1ccfdd9ecb0f1abd83e5285 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 5 Mar 2022 15:55:33 +0100 Subject: [PATCH 10/11] Update api/src/Api/Worker.hs --- api/src/Api/Worker.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/Api/Worker.hs b/api/src/Api/Worker.hs index 4c2810c..486522f 100644 --- a/api/src/Api/Worker.hs +++ b/api/src/Api/Worker.hs @@ -48,7 +48,7 @@ newtype ErrorBody = ErrorBody { error :: Text } data RefreshBody = RefreshBody { accessToken :: Text , refreshToken :: Text - , expiresIn :: UTCTime + , expiresAt :: UTCTime } $(deriveJSON defaultOptions ''WorkerUserData) From 5cccd9ca23de6252992f5c5d49790acae8cc8a9b Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 5 Mar 2022 15:55:52 +0100 Subject: [PATCH 11/11] Update worker/src/services/youtube.ts --- worker/src/services/youtube.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/src/services/youtube.ts b/worker/src/services/youtube.ts index 9af0a1a..cd3f2b6 100644 --- a/worker/src/services/youtube.ts +++ b/worker/src/services/youtube.ts @@ -31,7 +31,7 @@ export class Youtube extends BaseService { body: JSON.stringify({ accessToken: x.access_token, refreshToken: x.refresh_token, - expires: x.expiry_date, + expiresAt: x.expiry_date, }), }); });