@shun-js/webcc-server 0.6.8 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shun-js/webcc-server",
3
- "version": "0.6.8",
3
+ "version": "0.7.0",
4
4
  "description": "webcc.dev server",
5
5
  "keywords": [
6
6
  "web claude code"
@@ -32,5 +32,5 @@
32
32
  "access": "public",
33
33
  "registry": "https://registry.npmjs.org/"
34
34
  },
35
- "gitHead": "b8d8674e7676cd3d152db0bd6e35c706e87d4c00"
35
+ "gitHead": "7b00c44a58b64b17d54327820cf1d44fa00464dd"
36
36
  }
@@ -35,8 +35,7 @@ exports.githubCallback = async (req, res) => {
35
35
  const methodName = 'githubCallback';
36
36
 
37
37
  // fallback url
38
- // const fallbackUrl = global.QZ_CONFIG.github.fallbackUrl;
39
- const fallbackUrl = 'http://localhost:7008';
38
+ const fallbackUrl = global.QZ_CONFIG.github.fallbackUrl;
40
39
 
41
40
  // check
42
41
  if (!req.cookies) {
@@ -70,6 +69,11 @@ exports.githubCallback = async (req, res) => {
70
69
  }
71
70
 
72
71
  // userinfo
73
- await getGithubUserinfo(queryCode);
72
+ const githubUserinfo = await getGithubUserinfo(req, queryCode);
73
+ if (!githubUserinfo) {
74
+ req.logger.error(methodName, 'githubUserinfo is null');
75
+ res.redirect(fallbackUrl);
76
+ return;
77
+ }
74
78
  res.send('1');
75
79
  };
@@ -12,8 +12,7 @@ exports.getGitHubAuthUrl = () => {
12
12
  const state = uuid();
13
13
  const params = new URLSearchParams({
14
14
  client_id: global.QZ_CONFIG.github.clientID,
15
- // redirect_uri: global.QZ_CONFIG.github.callbackUrl,
16
- redirect_uri: 'http://localhost:7008/github/callback',
15
+ redirect_uri: global.QZ_CONFIG.github.callbackUrl,
17
16
  scope: global.QZ_CONFIG.github.scope,
18
17
  state: state,
19
18
  });
@@ -25,9 +24,12 @@ exports.getGitHubAuthUrl = () => {
25
24
 
26
25
  /**
27
26
  * getGithubUserinfo
27
+ * @param {*} req
28
28
  * @param {*} code
29
29
  */
30
- exports.getGithubUserinfo = async (code) => {
30
+ exports.getGithubUserinfo = async (req, code) => {
31
+ const methodName = 'getGithubUserinfo';
32
+
31
33
  try {
32
34
  // get token
33
35
  const tokenUrl = global.QZ_CONFIG.github.tokenUrl;
@@ -35,18 +37,111 @@ exports.getGithubUserinfo = async (code) => {
35
37
  params: {
36
38
  client_id: global.QZ_CONFIG.github.clientID,
37
39
  client_secret: global.QZ_CONFIG.github.clientSecret,
38
- // redirect_uri: global.QZ_CONFIG.github.callbackUrl,
39
- redirect_uri: 'http://localhost:7008/github/callback',
40
+ redirect_uri: global.QZ_CONFIG.github.callbackUrl,
40
41
  code: code,
41
42
  },
42
43
  headers: {
43
44
  Accept: 'application/json',
44
45
  },
45
46
  };
46
- console.log(tokenConfig);
47
47
  const tokenResponse = await get(tokenUrl, tokenConfig);
48
- console.log(tokenResponse);
48
+
49
+ // check
50
+ if (!tokenResponse) {
51
+ req.logger.error(methodName, 'tokenResponse is null');
52
+ return;
53
+ }
54
+ if (tokenResponse.status !== 200) {
55
+ req.logger.error(methodName, 'tokenResponse.status !== 200', tokenResponse.status);
56
+ return;
57
+ }
58
+ if (!tokenResponse.data) {
59
+ req.logger.error(methodName, 'tokenResponse.data is null');
60
+ return;
61
+ }
62
+ if (!tokenResponse.data.access_token || !tokenResponse.data.token_type) {
63
+ req.logger.error(methodName, 'tokenResponse.data.access_token is null or tokenResponse.data.token_type is null');
64
+ return;
65
+ }
66
+
67
+ // get user
68
+ req.logger.info(methodName, 'get token success');
69
+ const userUrl = global.QZ_CONFIG.github.userUrl;
70
+ const userConfig = {
71
+ headers: {
72
+ Authorization: `${tokenResponse.data.token_type} ${tokenResponse.data.access_token}`,
73
+ Accept: 'application/json',
74
+ },
75
+ };
76
+ const userResponse = await get(userUrl, userConfig);
77
+
78
+ // check
79
+ if (!userResponse) {
80
+ req.logger.error(methodName, 'userResponse is null');
81
+ return;
82
+ }
83
+ if (userResponse.status !== 200) {
84
+ req.logger.error(methodName, 'userResponse.status !== 200', userResponse.status);
85
+ return;
86
+ }
87
+ if (!userResponse.data) {
88
+ req.logger.error(methodName, 'userResponse.data is null');
89
+ return;
90
+ }
91
+ req.logger.info(methodName, 'get user success');
92
+
93
+ // r
94
+ return userResponse.data;
49
95
  } catch (error) {
50
- console.log(error);
96
+ req.logger.error(methodName, 'error', error);
51
97
  }
52
98
  };
99
+
100
+ // {
101
+ // login: 'uikoo9',
102
+ // id: 10345351,
103
+ // node_id: 'MDQ6VXNlcjEwMzQ1MzUx',
104
+ // avatar_url: 'https://avatars.githubusercontent.com/u/10345351?v=4',
105
+ // gravatar_id: '',
106
+ // url: 'https://api.github.com/users/uikoo9',
107
+ // html_url: 'https://github.com/uikoo9',
108
+ // followers_url: 'https://api.github.com/users/uikoo9/followers',
109
+ // following_url: 'https://api.github.com/users/uikoo9/following{/other_user}',
110
+ // gists_url: 'https://api.github.com/users/uikoo9/gists{/gist_id}',
111
+ // starred_url: 'https://api.github.com/users/uikoo9/starred{/owner}{/repo}',
112
+ // subscriptions_url: 'https://api.github.com/users/uikoo9/subscriptions',
113
+ // organizations_url: 'https://api.github.com/users/uikoo9/orgs',
114
+ // repos_url: 'https://api.github.com/users/uikoo9/repos',
115
+ // events_url: 'https://api.github.com/users/uikoo9/events{/privacy}',
116
+ // received_events_url: 'https://api.github.com/users/uikoo9/received_events',
117
+ // type: 'User',
118
+ // user_view_type: 'private',
119
+ // site_admin: false,
120
+ // name: null,
121
+ // company: null,
122
+ // blog: '',
123
+ // location: null,
124
+ // email: 'uikoo9@qq.com',
125
+ // hireable: null,
126
+ // bio: null,
127
+ // twitter_username: null,
128
+ // notification_email: 'uikoo9@qq.com',
129
+ // public_repos: 27,
130
+ // public_gists: 0,
131
+ // followers: 91,
132
+ // following: 4,
133
+ // created_at: '2014-12-30T03:11:05Z',
134
+ // updated_at: '2026-01-29T09:08:41Z',
135
+ // private_gists: 0,
136
+ // total_private_repos: 33,
137
+ // owned_private_repos: 33,
138
+ // disk_usage: 1026748,
139
+ // collaborators: 4,
140
+ // two_factor_authentication: true,
141
+ // plan: {
142
+ // name: 'free',
143
+ // space: 976562499,
144
+ // collaborators: 0,
145
+ // private_repos: 10000
146
+ // }
147
+ // }