From c5bf43de373583e9cd43836c96b321f70e76c026 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Thu, 3 Mar 2022 17:13:59 +0100 Subject: [PATCH] Worker uses the github access token --- api/aeris.cabal | 1 + api/src/Api/OIDC.hs | 2 +- worker/src/services/github.ts | 7 ++++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api/aeris.cabal b/api/aeris.cabal index a95e0c8..3e518b8 100644 --- a/api/aeris.cabal +++ b/api/aeris.cabal @@ -17,6 +17,7 @@ license-file: LICENSE build-type: Simple extra-source-files: README.md + services/anilist.json services/discord.json services/github.json services/spotify.json diff --git a/api/src/Api/OIDC.hs b/api/src/Api/OIDC.hs index 483dbf5..80e3ecd 100644 --- a/api/src/Api/OIDC.hs +++ b/api/src/Api/OIDC.hs @@ -62,7 +62,7 @@ urlHandler Spotify (Just r) = do urlHandler Github (Just r) = do clientId <- liftIO $ envAsString "GITHUB_CLIENT_ID" "" throwError $ err302 { errHeaders = - [("Location", B8.pack $ "https://github.com/login/oauth/authorize?response_type=code&client_id=" ++ clientId ++ "&redirect_uri=" ++ r)] } + [("Location", B8.pack $ "https://github.com/login/oauth/authorize?response_type=code&scope=repo&client_id=" ++ clientId ++ "&redirect_uri=" ++ r)] } servicesHandler :: AuthRes -> AppM [String] servicesHandler (Authenticated (User uid name slug)) = do diff --git a/worker/src/services/github.ts b/worker/src/services/github.ts index 4012405..669a982 100644 --- a/worker/src/services/github.ts +++ b/worker/src/services/github.ts @@ -10,10 +10,11 @@ export class Github extends BaseService { private _github: Octokit; private _websocket: Webhooks; - constructor(_: Pipeline) { + constructor(pipeline: Pipeline) { super(); - ///TODO Get various credentials - this._github = new Octokit(); + if (!("Github" in pipeline.userData)) + throw new Error("User not authenticated via github"); + this._github = new Octokit({auth: pipeline.userData["Github"].accessToken}); this._websocket = new Webhooks({ secret: "bidibi" });