memcode icon indicating copy to clipboard operation
memcode copied to clipboard

GITHUB_OAUTH_ID not working properly

Open Daniel-CS-Team opened this issue 1 year ago • 5 comments

I try to run memcode as a self-hosted production instance using Docker. I managed to create a somewaht working dockerfile, but I do not get the github oauth to work. Issue is, that the links to github are not constructed properly so that the client_id is not inserted. I added the GITHUB_OAUTH_ID to env.js for the docker build (which is very ugly, as it really should be a runtime environemnt variable). But this does not seem to have any effect.

Dockerfile:

FROM node:8.4.0

WORKDIR /app

COPY ["package.json", "package-lock.json*", "./"]
RUN npm install

COPY "backend/" "./backend"
COPY "frontend/" "./frontend"
COPY "services" "./services"

COPY env.js ./env.js

# Will handle HTTPS on reverse proxy, redirect breaks stuff
RUN sed -i "/^import sslRedirect from 'heroku-ssl-redirect';$/d" backend/beforeMiddleware.js
RUN sed -i "/^router.use(sslRedirect());$/d" backend/beforeMiddleware.js

WORKDIR /app/backend
RUN ../node_modules/.bin/webpack --config ./webpack/production.config.js

WORKDIR /app/frontend
RUN ../node_modules/.bin/webpack --config ./webpack/production.config.js

ENV NODE_ENV=production
WORKDIR /app

CMD ["node", "backend/webpacked/index.js"] 

EXPOSE 3000

Daniel-CS-Team avatar Sep 09 '22 14:09 Daniel-CS-Team

Which links are not constructed properly, these ones?

window.env = {
   githubSignInLink: 'https://github.com/login/oauth/authorize?scope=user:email&client_id=${process.env['GITHUB_OAUTH_ID']}',
   googleSignInLink: 'https://accounts.google.com/o/oauth2/v2/auth?scope=profile%20email&redirect_uri=${escape(process.env['GOOGLE_OAUTH_CALLBACK'])}&response_type=code&client_id=${process.env['GOOGLE_OAUTH_ID']}',
   contactEmail: '[email protected]'
};

Could you try to console.log(process.env) before and after this line https://github.com/lakesare/memcode/blob/master/backend/index.js#L8 to make sure GITHUB_OAUTH_ID is getting inserted?

lakesare avatar Sep 09 '22 14:09 lakesare

Yes exactly. console.log(process.env) shows the correct GITHUB_OAUTH_ID.

But it also shows, that env.js overwrites other environment variables set through docker. I will have to fix that, but I think this is independent of the problem here.

Daniel-CS-Team avatar Sep 09 '22 15:09 Daniel-CS-Team

Have you tried leaving the env.js empty and just setting all environment variables via Docker?

lakesare avatar Sep 09 '22 22:09 lakesare

Have you tried leaving the env.js empty and just setting all environment variables via Docker?

Yes, that resolves the issue of environment variables getting overwritten. (For those interseted: replace COPY env.js ./env.jswith RUN touch env.js in above Dockerfile)

But it does not resolve the issue of the Github-SignIn Link missing the client_id part. The same holds true for the Google SignIn Link. I am no web developer, but I saw in the code, that this part of the link is generated from some template. Maybe at the runtime of this themplate is missing the env-variable?

Daniel-CS-Team avatar Sep 12 '22 06:09 Daniel-CS-Team

I am no web developer, but I saw in the code, that this part of the link is generated from some template.

Not really, this is a simple Js string (equivalent to "hello everyone " + process.env['GITHUB_OAUTH_ID']). So, if you can console.log(process.env['GITHUB_OAUTH_ID']) from /backend/* files, it should certainly work.

lakesare avatar Sep 12 '22 18:09 lakesare