Skip to content

Commit a6bbbd6

Browse files
domoritzyuvvantalrejaCopilot
authored
fix(auth): update auth to use localStorage (#543)
* feat(auth): enhance postMessage handling and improve cookie settings * fix(auth): Auth Issue fixed * fix(auth): Gist methods updated for new auth integration * fix(auth): Unified auth with local storage * feat(auth): Enhance authentication flow with GitHub access token support * refactor(auth): Implement in-time GitHub token retrieval for API calls * Update config/passport.ts * remove redis * cleanups * More cleanups * Update src/controllers/auth.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fixed lint issues * Removed console logs * Changed to use handle options * simplify, fox import * code style * update typedoc * update eslint * chore: switch to npm * update vscode setting * update express, simplify cors * debug at main url * Send token through URL * redirect to backend * Minor changes --------- Co-authored-by: Yuvvan Talreja <31566676+yuvvantalreja@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 07b0b2d commit a6bbbd6

21 files changed

Lines changed: 5756 additions & 4300 deletions

.env.sample

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,3 @@ GITHUB_CLIENT_SECRET=# client secret of the application
44

55
# Session ID configuration
66
SESSION_SECRET=# secret key for session ID generation
7-
8-
# Redis session store configuration
9-
REDIS_HOST=localhost
10-
REDIS_PORT=6379
11-
REDIS_PASSWORD=

.eslintignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc.json

Lines changed: 0 additions & 48 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
uses: actions/setup-node@v4
1414

1515
- name: Install Node dependencies
16-
run: yarn --frozen-lockfile
16+
run: npm ci
1717

18-
- run: yarn lint
19-
- run: yarn build
18+
- run: npm run lint
19+
- run: npm run build

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
logs
33
*.log
44
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
75

86
# Dependency directories
97
node_modules/

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ https://github.com/vega/editor-backend.
1414
1515
2. Install all dependencies.
1616
```
17-
$ yarn install
17+
$ npm install
1818
```
1919
2020
3. Put configurations in a `.env` file in the root directory.
@@ -29,15 +29,15 @@ https://github.com/vega/editor-backend.
2929
3030
# GitHub OAuth app credentials
3131
GITHUB_CLIENT_ID=a901f0948b144d29fbdf
32-
GITHUB_CLIENT_SECRET=dfdb84ff29fde4eaa160078d13e024530238ebe0
32+
GITHUB_CLIENT_SECRET=8a2269fd225321f19f2a19e7629e3ad63d94df68
3333
3434
# Session ID configuration
3535
SESSION_SECRET=secret
3636
```
3737
3838
5. Run the back-end server.
3939
```
40-
$ yarn start
40+
$ npm start
4141
```
4242
4343
6. Go to the home route (which usually is `http://localhost:3000/`). Otherwise
@@ -56,5 +56,5 @@ Go to https://vega.github.io/editor-backend/.
5656
plugin](https://marketplace.visualstudio.com/items?itemName=stkb.rewrap) to
5757
assist formatting of markdown files. Press <kbd>Alt</kbd> + <kbd>Q</kbd> to
5858
limit lines at 80 characters.
59-
- The project uses ESLint to format the code. Run `yarn format` to fix
59+
- The project uses ESLint to format the code. Run `npm run format` to fix
6060
formatting where it's possible to do so automatically.

config/index.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,6 @@ export const githubOauth = {
2222
GITHUB_CLIENT_SECRET: process.env.GITHUB_CLIENT_SECRET,
2323
};
2424

25-
/**
26-
* Stores the configuration for redis store.
27-
*/
28-
export const redisConfiguration = {
29-
/**
30-
* Host name for redis store.
31-
*/
32-
REDIS_HOST: process.env.REDIS_HOST,
33-
/**
34-
* Host password for redis store.
35-
*/
36-
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
37-
/**
38-
* Port number for redis store.
39-
*/
40-
REDIS_PORT: +process.env.REDIS_PORT,
41-
};
42-
4325
/**
4426
* Secret used to sign the session ID cookie.
4527
*
@@ -60,21 +42,15 @@ export const allowedOrigins: string[] = [
6042
'https://vega.github.io',
6143
'http://localhost:8081',
6244
'http://localhost:8080',
45+
'http://localhost:1234',
6346
'http://0.0.0.0:8080',
6447
];
6548

6649
/**
6750
* Stores the type of environment of project. It is either `development` or
6851
* `production`.
6952
*
70-
* _Exported as `nodeEnv` to differentiate behaviour of app on development and
53+
* _Exported as `nodeEnv` to differentiate behavior of app on development and
7154
* production server._
7255
*/
7356
export const nodeEnv: string = process.env.NODE_ENV;
74-
75-
/**
76-
* Stores the expiry date of the cookie set.
77-
*
78-
* _Exported as `cookieExpiry`_.
79-
*/
80-
export const cookieExpiry: number = 90 * 24 * 60 * 60; // 90 days

config/passport.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,15 @@
11
import passport from 'passport';
22
import passportGitHub from 'passport-github2';
33

4-
import { githubOauth } from './index';
5-
import { authUrl, hostUrl } from '../src/urls';
4+
import { githubOauth } from './index.js';
5+
import { authUrl, hostUrl } from '../src/urls.js';
66

77
/**
88
* OAuth strategy to authenticate with GitHub. Reference:
99
* http://www.passportjs.org/packages/passport-github2/
1010
*/
1111
const GitHubStrategy = passportGitHub.Strategy;
1212

13-
/**
14-
* Serializes user profile returned after authentication.
15-
*
16-
* @param {object} user User profile
17-
* @param {function} done Method called internally by passport.js to resume
18-
* process
19-
*/
20-
passport.serializeUser((user, done) => {
21-
done(null, user);
22-
});
23-
24-
/**
25-
* Deserializes cookie sent to know which user is logged in.
26-
*
27-
* @param {object} user The GitHub profile of the user
28-
* @param {function} done Method called internally by passport.js to resume
29-
* process
30-
*/
31-
passport.deserializeUser((user, done) => {
32-
done(null, user);
33-
});
34-
3513
/**
3614
* GitHub OAuth strategy configuration.
3715
*
@@ -42,7 +20,17 @@ passport.use(new GitHubStrategy({
4220
clientID: githubOauth.GITHUB_CLIENT_ID,
4321
clientSecret: githubOauth.GITHUB_CLIENT_SECRET,
4422
callbackURL: `${hostUrl}${authUrl.callback}`,
23+
scope: ['gist'],
4524
}, (accessToken, refreshToken, profile, done) => {
25+
26+
if (!profile) {
27+
return done(new Error('Failed to retrieve GitHub profile'));
28+
}
29+
30+
if (!accessToken) {
31+
return done(new Error('No access token provided'));
32+
}
33+
4634
done(null, { ...profile, accessToken });
4735
}));
4836

eslint.config.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import eslint from '@eslint/js';
2+
import tseslint from 'typescript-eslint';
3+
4+
export default tseslint.config(
5+
eslint.configs.recommended,
6+
...tseslint.configs.recommended,
7+
{
8+
ignores: ['node_modules/**', 'docs/**'],
9+
},
10+
{
11+
files: ['src/**/*.ts', 'config/*.ts'],
12+
languageOptions: {
13+
parserOptions: {
14+
project: './tsconfig.json',
15+
},
16+
},
17+
rules: {
18+
'arrow-parens': ['error', 'as-needed'],
19+
'arrow-spacing': 'error',
20+
'block-spacing': 'error',
21+
'comma-dangle': ['error', 'always-multiline'],
22+
'comma-spacing': ['error', { before: false, after: true }],
23+
'curly': ['error', 'all'],
24+
'eol-last': ['error', 'always'],
25+
'keyword-spacing': ['error', { before: true, after: true }],
26+
'max-len': ['error', { code: 120 }],
27+
'no-console': ['error', { allow: ['warn', 'error'] }],
28+
'no-dupe-class-members': 'error',
29+
'no-mixed-operators': 'error',
30+
'no-trailing-spaces': 'error',
31+
'no-undef': 'off',
32+
'object-curly-spacing': ['error', 'always'],
33+
'quotes': ['error', 'single'],
34+
'semi': ['error', 'always'],
35+
'space-before-blocks': ['error', 'always'],
36+
'space-in-parens': ['error', 'never'],
37+
'@typescript-eslint/explicit-function-return-type': 'off',
38+
'@typescript-eslint/explicit-member-accessibility': 'off',
39+
'@typescript-eslint/no-explicit-any': 'off',
40+
'@typescript-eslint/no-non-null-assertion': 'off',
41+
'@typescript-eslint/no-use-before-define': 'off',
42+
'@typescript-eslint/no-var-requires': 'off',
43+
},
44+
},
45+
);

0 commit comments

Comments
 (0)