Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/utils/Redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const RedisKey = {
agoraRTCRoomUserToken: (roomUUID: string, uid: string | number): string =>
`agora:rtc:room:${roomUUID}:uid:${uid}`,
agoraRTMUserToken: (userUUID: string): string => `agora:rtm:userUUID:${userUUID}`,
agoraSSOLoginID: (loginID: string): string => `agora:sso:loginID:${loginID}`,
cloudStorageFileInfo: (userUUID: string, fileUUID: string): string =>
`cloudStorage:${userUUID}:${fileUUID}`,
roomInviteCode: (inviteCode: string): string => `room:invite:${inviteCode}`,
Expand Down
12 changes: 0 additions & 12 deletions src/v1/controller/login/Process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ export class LoginProcess extends AbstractController<RequestType, ResponseType>

const userInfo = JSON.parse(userInfoStr);

// Agora SSO
if ("agoraSSOLoginID" in userInfo) {
const thirtyDay = 60 * 60 * 24 * 30;
RedisService.set(
RedisKey.agoraSSOLoginID(userInfo.agoraSSOLoginID),
userInfo.userUUID,
thirtyDay,
).catch(error => {
this.logger.error(error);
});
}

return {
status: Status.Success,
data: userInfo,
Expand Down
2 changes: 0 additions & 2 deletions src/v1/controller/login/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { LoginProcess } from "./Process";
import { ControllerClass } from "../../../abstract/controller";
import { AppleJWT } from "./apple/jwt";
import { AgoraCallback } from "./agora/Callback";
import { CheckAgoraSSOLoginID } from "./agora/Check";
import { GoogleCallback } from "./google/Callback";
import { SendMessage } from "./phone/SendMessage";
import { PhoneLogin } from "./phone/Phone";
Expand All @@ -20,7 +19,6 @@ export const loginRouters: Readonly<Array<ControllerClass<any, any>>> = Object.f
AppleJWT,
GithubCallback,
AgoraCallback,
CheckAgoraSSOLoginID,
GoogleCallback,
SendMessage,
PhoneLogin,
Expand Down
63 changes: 15 additions & 48 deletions src/v1/controller/login/agora/Callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class AgoraCallback extends AbstractController<RequestType> {
public static readonly schema: FastifySchema<RequestType> = {
querystring: {
type: "object",
required: ["state", "code", "loginId"],
required: ["state", "code"],
properties: {
state: {
type: "string",
Expand All @@ -30,19 +30,12 @@ export class AgoraCallback extends AbstractController<RequestType> {
code: {
type: "string",
},
loginId: {
type: "string",
},
},
},
};

public async execute(): Promise<void> {
void this.reply.headers({
"content-type": "text/html",
});

const { state: authUUID, code, loginId: loginID } = this.querystring;
const { state: authUUID, code } = this.querystring;

await LoginAgora.assertHasAuthUUID(authUUID, this.logger);

Expand All @@ -67,71 +60,46 @@ export class AgoraCallback extends AbstractController<RequestType> {
});
}

const { userName, avatarURL } = (await loginAgora.svc.user.nameAndAvatar())!;

await loginAgora.tempSaveUserInfo(authUUID, {
name: userName,
token: await this.reply.jwtSign({
userUUID,
loginSource: LoginPlatform.Agora,
}),
avatar: avatarURL,
agoraSSOLoginID: loginID,
const token = await this.reply.jwtSign({
userUUID,
loginSource: LoginPlatform.Agora,
});

return this.reply.send(AgoraCallback.successHTML());
void this.reply.redirect(`${Website}/login?token=${token}`);
}

public async errorHandler(error: Error): Promise<ResponseError> {
await redisService.set(RedisKey.authFailed(this.querystring.state), error.message, 60 * 60);

this.logger.error("request failed", parseError(error));

void this.reply.headers({
"content-type": "text/html",
});
return this.reply.send(AgoraCallback.failedHTML);
}

private static successHTML(): string {
private static get failedHTML(): string {
return `<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login Success</title>
<title>Login Failed</title>
</head>
<body>
<svg style=max-width:80px;max-height:80px;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) viewBox="0 0 80 80" xmlns="http://www.w3.org/2000/svg">
<path d="M40 0c22.0914 0 40 17.9086 40 40S62.0914 80 40 80 0 62.0914 0 40 17.9086 0 40 0zm0 4C20.1177 4 4 20.1177 4 40s16.1177 36 36 36 36-16.1177 36-36S59.8823 4 40 4zm22.6337 20.5395l2.7326 2.921-32.3889 30.2993L14.61 40.0046l2.78-2.876L33.022 52.24l29.6117-27.7005z" fill="#9FDF76" fill-rule="nonzero" />
<path d="M40 0c22.0914 0 40 17.9086 40 40S62.0914 80 40 80 0 62.0914 0 40 17.9086 0 40 0zm0 4C20.1177 4 4 20.1177 4 40s16.1177 36 36 36 36-16.1177 36-36S59.8823 4 40 4zm21.0572 49.2345l.357.3513-2.8284 2.8284c-10.162-10.162-26.5747-10.2636-36.8617-.3048l-.3099.3048-2.8284-2.8284c11.7085-11.7085 30.619-11.8256 42.4714-.3513zM27 26c2.2091 0 4 1.7909 4 4 0 2.2091-1.7909 4-4 4-2.2091 0-4-1.7909-4-4 0-2.2091 1.7909-4 4-4zm26 0c2.2091 0 4 1.7909 4 4 0 2.2091-1.7909 4-4 4-2.2091 0-4-1.7909-4-4 0-2.2091 1.7909-4 4-4z" fill="#F45454" fill-rule="nonzero" />
</svg>
<div id="text" style=position:fixed;top:60%;left:50%;transform:translate(-50%,-50%)>Login Success. After 3s it will automatically jump to the home page</div>
</body>
<div id="text" style=position:fixed;top:60%;left:50%;transform:translate(-50%,-50%)>Login Failed. After 3s it will automatically jump to the home page</div>
<script>
if (navigator.language.startsWith("zh")) {
document.getElementById("text").textContent = "登录成功,3秒后将自动跳转到首页"
document.getElementById("text").textContent = "登录失败,3秒后将自动跳转到首页"
}

setTimeout(() => {
location.href = "${Website}";
}, 3000);
</script>
</html>
`;
}

private static get failedHTML(): string {
return `<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login Failed</title>
</head>
<body>
<svg style=max-width:80px;max-height:80px;position:fixed;top:50%;left:50%;transform:translate(-50%,-50%) viewBox="0 0 80 80" xmlns="http://www.w3.org/2000/svg">
<path d="M40 0c22.0914 0 40 17.9086 40 40S62.0914 80 40 80 0 62.0914 0 40 17.9086 0 40 0zm0 4C20.1177 4 4 20.1177 4 40s16.1177 36 36 36 36-16.1177 36-36S59.8823 4 40 4zm21.0572 49.2345l.357.3513-2.8284 2.8284c-10.162-10.162-26.5747-10.2636-36.8617-.3048l-.3099.3048-2.8284-2.8284c11.7085-11.7085 30.619-11.8256 42.4714-.3513zM27 26c2.2091 0 4 1.7909 4 4 0 2.2091-1.7909 4-4 4-2.2091 0-4-1.7909-4-4 0-2.2091 1.7909-4 4-4zm26 0c2.2091 0 4 1.7909 4 4 0 2.2091-1.7909 4-4 4-2.2091 0-4-1.7909-4-4 0-2.2091 1.7909-4 4-4z" fill="#F45454" fill-rule="nonzero" />
</svg>
<div id="text" style=position:fixed;top:60%;left:50%;transform:translate(-50%,-50%)>Login Failed</div>
<script>
if (navigator.language.startsWith("zh")) {
document.getElementById("text").textContent = "登录失败"
}
</script>
</body>
</html>
`;
Expand All @@ -142,6 +110,5 @@ interface RequestType {
querystring: {
state: string;
code: string;
loginId: string;
};
}
72 changes: 0 additions & 72 deletions src/v1/controller/login/agora/Check.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/v1/controller/login/platforms/LoginAgora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,6 @@ export class LoginAgora extends AbstractLogin {
const token = await LoginAgora.getToken(code);
return await LoginAgora.getUserInfoByAPI(token);
}

public static async checkLoginID(loginID: string): Promise<boolean> {
const result = await ax.post<{ isValid: boolean }>(
"https://sso-power.agora.io/api/v1/visitor/check-login-id",
{
loginId: loginID,
},
{
headers: {
Authorization: Buffer.from(
`${AgoraLogin.clientId}:${AgoraLogin.clientSecret}`,
).toString("base64"),
},
},
);

return result.data.isValid || false;
}
}

interface RegisterService {
Expand Down