連携ログインができないのなどを修正 (#6162)

* 連携ログインができないのを修正

* Cookie名変更, セッションに

* igiはやっぱり非セッションCookieで

* 2回目以降Discordログインできなくなるのを修正
This commit is contained in:
MeiMei
2020-03-20 13:56:22 +09:00
committed by GitHub
parent 1b48e0d6e0
commit 80eedf7449
7 changed files with 28 additions and 38 deletions

View File

@@ -13,7 +13,7 @@ import { ILocalUser } from '../../../models/entities/user';
import { ensure } from '../../../prelude/ensure';
function getUserToken(ctx: Koa.Context) {
return ((ctx.headers['cookie'] || '').match(/i=(\w+)/) || [null, null])[1];
return ((ctx.headers['cookie'] || '').match(/igi=(\w+)/) || [null, null])[1];
}
function compareOrigin(ctx: Koa.Context) {
@@ -113,14 +113,10 @@ router.get('/signin/discord', async ctx => {
response_type: 'code'
};
const expires = 1000 * 60 * 60; // 1h
ctx.cookies.set('signin_with_discord_session_id', sessid, {
ctx.cookies.set('signin_with_discord_sid', sessid, {
path: '/',
domain: config.host,
secure: config.url.startsWith('https'),
httpOnly: true,
expires: new Date(Date.now() + expires),
maxAge: expires
httpOnly: true
});
redis.set(sessid, JSON.stringify(params));
@@ -135,7 +131,7 @@ router.get('/dc/cb', async ctx => {
const oauth2 = await getOAuth2();
if (!userToken) {
const sessid = ctx.cookies.get('signin_with_discord_session_id');
const sessid = ctx.cookies.get('signin_with_discord_sid');
if (!sessid) {
ctx.throw(400, 'invalid session');
@@ -199,7 +195,7 @@ router.get('/dc/cb', async ctx => {
}
const profile = await UserProfiles.createQueryBuilder()
.where('"integrations"->"discord"->"id" = :id', { id: id })
.where(`"integrations"->'discord'->>'id' = :id`, { id: id })
.andWhere('"userHost" IS NULL')
.getOne();
@@ -212,6 +208,7 @@ router.get('/dc/cb', async ctx => {
integrations: {
...profile.integrations,
discord: {
id: id,
accessToken: accessToken,
refreshToken: refreshToken,
expiresDate: expiresDate,