連携ログインができないのなどを修正 (#6162)
* 連携ログインができないのを修正 * Cookie名変更, セッションに * igiはやっぱり非セッションCookieで * 2回目以降Discordログインできなくなるのを修正
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user