diff --git a/chart/values.yaml b/chart/values.yaml index 3fddafb8..ce054d9f 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -15,6 +15,9 @@ wordpressSecret: "" paypalReceiverEmail: "" awsAccessKeyId: "" awsSecretAccessKey: "" +giteaClientId: "" +giteaClientSecret: "" +giteaUrl: "" replicaCount: 1 diff --git a/config/dev.env.js b/config/dev.env.js index f31dba18..363113d9 100644 --- a/config/dev.env.js +++ b/config/dev.env.js @@ -9,4 +9,7 @@ module.exports = merge(prodEnv, { GITEE_CLIENT_ID: '"925ba7c78b85dec984f7877e4aca5cab10ae333c6d68e761bdb0b9dfb8f55672"', GITEE_CLIENT_SECRET: '"f05731066e42d307339dc8ebbb037a103881dafc7207a359a393b87749f1c562"', CLIENT_ID: '"thF3qCGLN39OtafjGnqHyj6n02WwE6xD"', + // GITEA_CLIENT_ID: '"fe30f8f9-b1e8-4531-8f72-c1a5d3912805"', + // GITEA_CLIENT_SECRET: '"lus7oMnb3H6M1hsChndphArE20Txr7erwJLf7SDBQWTw"', + // GITEA_URL: '"https://gitea.test.com"', }) \ No newline at end of file diff --git a/server/conf.js b/server/conf.js index f86e1f54..748621d3 100644 --- a/server/conf.js +++ b/server/conf.js @@ -13,6 +13,9 @@ const giteeClientSecret = process.env.GITEE_CLIENT_SECRET; const googleClientId = process.env.GOOGLE_CLIENT_ID; const googleApiKey = process.env.GOOGLE_API_KEY; const wordpressClientId = process.env.WORDPRESS_CLIENT_ID; +const giteaClientId = process.env.GITEA_CLIENT_ID; +const giteaClientSecret = process.env.GITEA_CLIENT_SECRET; +const giteaUrl = process.env.GITEA_URL; exports.values = { pandocPath, @@ -29,6 +32,9 @@ exports.values = { googleClientId, googleApiKey, wordpressClientId, + giteaClientId, + giteaClientSecret, + giteaUrl, }; exports.publicValues = { @@ -39,4 +45,6 @@ exports.publicValues = { googleApiKey, wordpressClientId, allowSponsorship: !!paypalReceiverEmail, + giteaClientId, + giteaUrl, }; diff --git a/server/gitea.js b/server/gitea.js new file mode 100644 index 00000000..ea7c5b5a --- /dev/null +++ b/server/gitea.js @@ -0,0 +1,41 @@ +const qs = require('qs'); +const request = require('request'); +const conf = require('./conf'); + +function giteaToken(queryParam) { + return new Promise((resolve, reject) => { + request({ + method: 'POST', + url: `${conf.values.giteaUrl}/login/oauth/access_token`, + headers: { + 'content-type': 'application/json', + }, + json: true, + body: { + ...queryParam, + client_id: conf.values.giteaClientId, + client_secret: conf.values.giteaClientSecret, + }, + }, (err, res, body) => { + if (err) { + reject(err); + } + const token = body.access_token; + if (token) { + resolve(body); + } else { + reject(res.statusCode + ',body:' + JSON.stringify(body)); + } + }); + }); +} + +exports.giteaToken = (req, res) => { + giteaToken(req.query) + .then( + tokenBody => res.send(tokenBody), + err => res + .status(400) + .send(err ? err.message || err.toString() : 'bad_code'), + ); +}; diff --git a/server/index.js b/server/index.js index b3ced48e..f6fc873c 100644 --- a/server/index.js +++ b/server/index.js @@ -5,6 +5,7 @@ const path = require('path'); const user = require('./user'); const github = require('./github'); const gitee = require('./gitee'); +const gitea = require('./gitea'); const pdf = require('./pdf'); const pandoc = require('./pandoc'); const conf = require('./conf'); @@ -27,6 +28,7 @@ module.exports = (app) => { app.get('/oauth2/githubToken', github.githubToken); app.get('/oauth2/giteeToken', gitee.giteeToken); + app.get('/oauth2/giteaToken', gitea.giteaToken); app.get('/conf', (req, res) => res.send(conf.publicValues)); app.get('/userInfo', user.userInfo); app.post('/pdfExport', pdf.generate); diff --git a/src/components/modals/providers/GiteaAccountModal.vue b/src/components/modals/providers/GiteaAccountModal.vue index 2bb3f4ea..f22d7b38 100644 --- a/src/components/modals/providers/GiteaAccountModal.vue +++ b/src/components/modals/providers/GiteaAccountModal.vue @@ -5,28 +5,30 @@

将您的Gitea链接到StackEdit中文版

- - - -
- 例如: https://gitea.example.com/ - - ,非https的URL,请跳转到 HTTP链接 添加Gitea。 - -
-
- - - - - -
- 您必须使用重定向url {{redirectUrl}}配置OAuth2应用程序 -
-
- 更多信息 -
-
+