Skip to content

Commit

Permalink
Merge branch 'release/v1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kobalab committed Feb 14, 2024
2 parents 2fa0288 + 1966101 commit 0b4ffe3
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 5 deletions.
6 changes: 5 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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 の出力を追加
Expand Down
9 changes: 9 additions & 0 deletions bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ 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`, (req, res, next)=>{
if (req.query.error) res.redirect(302, back);
else next(); },
passport.authenticate('google',
{ successRedirect: back }));
}
app.post(`${base}/logout`, (req, res)=>{
req.session.destroy();
res.clearCookie('MAJIANG');
Expand Down
2 changes: 1 addition & 1 deletion lib/game.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Majiang.Server.Game
* game
*/
"use strict";

Expand Down
17 changes: 17 additions & 0 deletions lib/passport.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
90 changes: 88 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kobalab/majiang-server",
"version": "1.0.1",
"version": "1.1.0",
"description": "麻雀サーバー",
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 0b4ffe3

Please sign in to comment.