forked from vega/editor-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassport.ts
More file actions
50 lines (42 loc) · 1.61 KB
/
Copy pathpassport.ts
File metadata and controls
50 lines (42 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import passport from 'passport';
import passportGitHub from 'passport-github2';
import { githubOauth } from './index';
import { authUrl, hostUrl } from '../src/urls';
/**
* OAuth strategy to authenticate with GitHub. Reference:
* http://www.passportjs.org/packages/passport-github2/
*/
const GitHubStrategy = passportGitHub.Strategy;
console.log('Configuring GitHub strategy with callback URL:', `${hostUrl}${authUrl.callback}`);
console.log('GitHub client ID is set:', !!githubOauth.GITHUB_CLIENT_ID);
console.log('GitHub client secret is set:', !!githubOauth.GITHUB_CLIENT_SECRET);
/**
* GitHub OAuth strategy configuration.
*
* @param {Strategy} strategy OAuth strategy
* @param {function} callback Callback after successful authentication
*/
passport.use(new GitHubStrategy({
clientID: githubOauth.GITHUB_CLIENT_ID,
clientSecret: githubOauth.GITHUB_CLIENT_SECRET,
callbackURL: `${hostUrl}${authUrl.callback}`,
scope: ['gist'],
}, (accessToken, refreshToken, profile, done) => {
console.log('GitHub OAuth callback received');
if (!profile) {
console.error('No profile received from GitHub');
return done(new Error('Failed to retrieve GitHub profile'));
}
if (!accessToken) {
console.error('No access token received from GitHub');
return done(new Error('No access token provided'));
}
console.log('GitHub OAuth successful for user:', profile.username ?? profile.displayName ?? 'Unknown');
done(null, { ...profile, accessToken });
}));
/**
* Stores the configuration for OAuthentication with passport.
*
* _Exported as `passport` for initializing in `app.ts`._
*/
export default passport;