From 001e487a3166d248fcedce6dd41ad280fe0118f1 Mon Sep 17 00:00:00 2001 From: Satoshi Kobayashi Date: Mon, 12 Feb 2024 11:35:47 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/game.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/game.js b/lib/game.js index 0a8621b..353fd3d 100644 --- a/lib/game.js +++ b/lib/game.js @@ -1,5 +1,5 @@ /* - * Majiang.Server.Game + * game */ "use strict"; From 9bc127b9239964eccd3c26dd028a87ea1f8554ec Mon Sep 17 00:00:00 2001 From: Satoshi Kobayashi Date: Tue, 13 Feb 2024 22:58:58 +0800 Subject: [PATCH 2/5] =?UTF-8?q?passport-google-oauth20=20=E3=82=92?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=B9=E3=83=88=E3=83=BC=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 86 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 87 insertions(+) diff --git a/package-lock.json b/package-lock.json index 743b43f..f883017 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "express": "^4.18.2", "express-session": "^1.18.0", "passport": "^0.7.0", + "passport-google-oauth20": "^2.0.0", "passport-hatena-oauth": "^1.0.0", "passport-local": "^1.0.0", "session-file-store": "^1.5.0", @@ -133,6 +134,14 @@ "node": "^4.5.0 || >= 5.9" } }, + "node_modules/base64url": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz", + "integrity": "sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/bn.js": { "version": "4.12.0", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", @@ -759,6 +768,17 @@ "url": "https://github.com/sponsors/jaredhanson" } }, + "node_modules/passport-google-oauth20": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/passport-google-oauth20/-/passport-google-oauth20-2.0.0.tgz", + "integrity": "sha512-KSk6IJ15RoxuGq7D1UKK/8qKhNfzbLeLrG3gkLZ7p4A6DBCcv7xpyQwuXtWdpyR0+E0mwkpjY1VfPOhxQrKzdQ==", + "dependencies": { + "passport-oauth2": "1.x.x" + }, + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/passport-hatena-oauth": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/passport-hatena-oauth/-/passport-hatena-oauth-1.0.0.tgz", @@ -798,6 +818,30 @@ "url": "https://github.com/sponsors/jaredhanson" } }, + "node_modules/passport-oauth2": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/passport-oauth2/-/passport-oauth2-1.8.0.tgz", + "integrity": "sha512-cjsQbOrXIDE4P8nNb3FQRCCmJJ/utnFKEz2NX209f7KOHPoX18gF7gBzBbLLsj2/je4KrgiwLLGjf0lm9rtTBA==", + "dependencies": { + "base64url": "3.x.x", + "oauth": "0.10.x", + "passport-strategy": "1.x.x", + "uid2": "0.0.x", + "utils-merge": "1.x.x" + }, + "engines": { + "node": ">= 0.4.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/jaredhanson" + } + }, + "node_modules/passport-oauth2/node_modules/oauth": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/oauth/-/oauth-0.10.0.tgz", + "integrity": "sha512-1orQ9MT1vHFGQxhuy7E/0gECD3fd2fCC+PIX+/jgmU/gI3EpRocXtmtvxCO5x3WZ443FLTLFWNDjl5MPJf9u+Q==" + }, "node_modules/passport-strategy": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz", @@ -1143,6 +1187,11 @@ "node": ">= 0.8" } }, + "node_modules/uid2": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/uid2/-/uid2-0.0.4.tgz", + "integrity": "sha512-IevTus0SbGwQzYh3+fRsAMTVVPOoIVufzacXcHPmdlle1jUpq7BRL+mw3dgeLanvGZdwwbWhRV6XrcFNdBmjWA==" + }, "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", @@ -1341,6 +1390,11 @@ "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz", "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==" }, + "base64url": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/base64url/-/base64url-3.0.1.tgz", + "integrity": "sha512-ir1UPr3dkwexU7FdV8qBBbNDRUhMmIekYMFZfi+C/sLNnRESKPl23nB9b2pltqfOQNnGzsDdId90AEtG5tCx4A==" + }, "bn.js": { "version": "4.12.0", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", @@ -1813,6 +1867,14 @@ "utils-merge": "^1.0.1" } }, + "passport-google-oauth20": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/passport-google-oauth20/-/passport-google-oauth20-2.0.0.tgz", + "integrity": "sha512-KSk6IJ15RoxuGq7D1UKK/8qKhNfzbLeLrG3gkLZ7p4A6DBCcv7xpyQwuXtWdpyR0+E0mwkpjY1VfPOhxQrKzdQ==", + "requires": { + "passport-oauth2": "1.x.x" + } + }, "passport-hatena-oauth": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/passport-hatena-oauth/-/passport-hatena-oauth-1.0.0.tgz", @@ -1839,6 +1901,25 @@ "utils-merge": "1.x.x" } }, + "passport-oauth2": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/passport-oauth2/-/passport-oauth2-1.8.0.tgz", + "integrity": "sha512-cjsQbOrXIDE4P8nNb3FQRCCmJJ/utnFKEz2NX209f7KOHPoX18gF7gBzBbLLsj2/je4KrgiwLLGjf0lm9rtTBA==", + "requires": { + "base64url": "3.x.x", + "oauth": "0.10.x", + "passport-strategy": "1.x.x", + "uid2": "0.0.x", + "utils-merge": "1.x.x" + }, + "dependencies": { + "oauth": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/oauth/-/oauth-0.10.0.tgz", + "integrity": "sha512-1orQ9MT1vHFGQxhuy7E/0gECD3fd2fCC+PIX+/jgmU/gI3EpRocXtmtvxCO5x3WZ443FLTLFWNDjl5MPJf9u+Q==" + } + } + }, "passport-strategy": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/passport-strategy/-/passport-strategy-1.0.0.tgz", @@ -2097,6 +2178,11 @@ "random-bytes": "~1.0.0" } }, + "uid2": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/uid2/-/uid2-0.0.4.tgz", + "integrity": "sha512-IevTus0SbGwQzYh3+fRsAMTVVPOoIVufzacXcHPmdlle1jUpq7BRL+mw3dgeLanvGZdwwbWhRV6XrcFNdBmjWA==" + }, "undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", diff --git a/package.json b/package.json index b15f289..d6b1738 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "express": "^4.18.2", "express-session": "^1.18.0", "passport": "^0.7.0", + "passport-google-oauth20": "^2.0.0", "passport-hatena-oauth": "^1.0.0", "passport-local": "^1.0.0", "session-file-store": "^1.5.0", From f74744ae7611a14452105e46858c77aa32e705ee Mon Sep 17 00:00:00 2001 From: Satoshi Kobayashi Date: Tue, 13 Feb 2024 23:00:16 +0800 Subject: [PATCH 3/5] =?UTF-8?q?Google=E3=81=AEOAuth=E8=AA=8D=E8=A8=BC?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/server.js | 6 ++++++ lib/passport.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/bin/server.js b/bin/server.js index 37c86b5..dcd22c5 100755 --- a/bin/server.js +++ b/bin/server.js @@ -53,6 +53,12 @@ if (auth && fs.existsSync(path.join(auth, 'hatena.json'))) { app.get(`${base}/auth/hatena`, passport.authenticate('hatena', { successRedirect: back })); } +if (auth && fs.existsSync(path.join(auth, 'google.json'))) { + app.post(`${base}/auth/google`, passport.authenticate('google', + { scope: ['profile'] })); + app.get(`${base}/auth/google`, passport.authenticate('google', + { successRedirect: back })); +} app.post(`${base}/logout`, (req, res)=>{ req.session.destroy(); res.clearCookie('MAJIANG'); diff --git a/lib/passport.js b/lib/passport.js index f2df8ae..b5714cd 100644 --- a/lib/passport.js +++ b/lib/passport.js @@ -40,6 +40,23 @@ module.exports = function(auth) { } )); } + + if (fs.existsSync(path.join(auth, 'google.json'))) { + + const google = require('passport-google-oauth20'); + + passport.use(new google.Strategy( + require(path.join(auth, 'google.json')), + (accessToken, refreshToken, profile, cb)=>{ + let user = { + uid: profile.id + '@google', + name: profile.displayName, + icon: profile.photos[0].value + }; + cb(null, user); + } + )); + } } return passport; From 878d335d043b904469a7d4bdcbb798f726aee794 Mon Sep 17 00:00:00 2001 From: Satoshi Kobayashi Date: Wed, 14 Feb 2024 10:28:04 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E8=AA=8D=E8=A8=BC=E3=82=AD=E3=83=A3?= =?UTF-8?q?=E3=83=B3=E3=82=BB=E3=83=AB=E6=99=82=E3=81=AB=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E7=94=BB=E9=9D=A2=E3=81=AB=E6=88=BB=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/server.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/server.js b/bin/server.js index dcd22c5..5b024ce 100755 --- a/bin/server.js +++ b/bin/server.js @@ -56,7 +56,10 @@ if (auth && fs.existsSync(path.join(auth, 'hatena.json'))) { if (auth && fs.existsSync(path.join(auth, 'google.json'))) { app.post(`${base}/auth/google`, passport.authenticate('google', { scope: ['profile'] })); - app.get(`${base}/auth/google`, passport.authenticate('google', + app.get(`${base}/auth/google`, (req, res, next)=>{ + if (req.query.error) res.redirect(302, back); + else next(); }, + passport.authenticate('google', { successRedirect: back })); } app.post(`${base}/logout`, (req, res)=>{ From 196610178a46c08321b6b00a83844d700dcc03b4 Mon Sep 17 00:00:00 2001 From: Satoshi Kobayashi Date: Wed, 14 Feb 2024 10:46:12 +0800 Subject: [PATCH 5/5] v1.1.0 / 2024-02-14 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Google認証に対応 --- ChangeLog.md | 6 +++++- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 0a35b7a..84d6951 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,4 +1,8 @@ -## v1.0.1 / 2024-02-12 +## v1.1.0 / 2024-02-14 + + - Google認証に対応 + +### v1.0.1 / 2024-02-12 - 回線切断時にルームから退出するよう変更 - status_log の出力を追加 diff --git a/package-lock.json b/package-lock.json index f883017..c145907 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kobalab/majiang-server", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@kobalab/majiang-server", - "version": "1.0.1", + "version": "1.1.0", "license": "MIT", "dependencies": { "@kobalab/majiang-core": "^1.2.0", diff --git a/package.json b/package.json index d6b1738..41fe76d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kobalab/majiang-server", - "version": "1.0.1", + "version": "1.1.0", "description": "麻雀サーバー", "publishConfig": { "access": "public"