Add authInfo to js.

This commit is contained in:
Yang Luo
2021-10-09 22:15:43 +08:00
parent 08e59796c8
commit fa3681ed75

View File

@ -15,81 +15,60 @@
import * as Util from "./Util"; import * as Util from "./Util";
import {StaticBaseUrl} from "../Setting"; import {StaticBaseUrl} from "../Setting";
const GoogleAuthScope = "profile+email" const authInfo = {
const GoogleAuthUri = "https://accounts.google.com/signin/oauth"; Google: {
const GoogleAuthLogo = `${StaticBaseUrl}/img/social_google.png`; scope: "profile+email",
endpoint: "https://accounts.google.com/signin/oauth",
const GithubAuthScope = "user:email+read:user" },
const GithubAuthUri = "https://github.com/login/oauth/authorize"; GitHub: {
const GithubAuthLogo = `${StaticBaseUrl}/img/social_github.png`; scope: "user:email+read:user",
endpoint: "https://github.com/login/oauth/authorize",
const QqAuthScope = "get_user_info" },
const QqAuthUri = "https://graph.qq.com/oauth2.0/authorize"; QQ: {
const QqAuthLogo = `${StaticBaseUrl}/img/social_qq.png`; scope: "get_user_info",
endpoint: "https://graph.qq.com/oauth2.0/authorize",
const WeChatAuthScope = "snsapi_login" },
const WeChatAuthUri = "https://open.weixin.qq.com/connect/qrconnect"; WeChat: {
const WeChatAuthLogo = `${StaticBaseUrl}/img/social_wechat.png`; scope: "snsapi_login",
endpoint: "https://open.weixin.qq.com/connect/qrconnect",
const FacebookAuthScope = "email,public_profile"; },
const FacebookAuthUri = "https://www.facebook.com/dialog/oauth"; Facebook: {
const FacebookAuthLogo = `${StaticBaseUrl}/img/social_facebook.png`; scope: "email,public_profile",
endpoint: "https://www.facebook.com/dialog/oauth",
// const DingTalkAuthScope = "email,public_profile"; },
const DingTalkAuthUri = "https://oapi.dingtalk.com/connect/oauth2/sns_authorize"; DingTalk: {
const DingTalkAuthLogo = `${StaticBaseUrl}/img/social_dingtalk.png`; scope: "snsapi_login",
endpoint: "https://oapi.dingtalk.com/connect/oauth2/sns_authorize",
const WeiboAuthScope = "email"; },
const WeiboAuthUri = "https://api.weibo.com/oauth2/authorize"; Weibo: {
const WeiboAuthLogo = `${StaticBaseUrl}/img/social_weibo.png`; scope: "email",
endpoint: "https://api.weibo.com/oauth2/authorize",
const GiteeAuthScope = "user_info%20emails"; },
const GiteeAuthUri = "https://gitee.com/oauth/authorize"; Gitee: {
const GiteeAuthLogo = `${StaticBaseUrl}/img/social_gitee.png`; scope: "user_info%20emails",
endpoint: "https://gitee.com/oauth/authorize",
const LinkedInAuthScope = "r_liteprofile%20r_emailaddress"; },
const LinkedInAuthUri = "https://www.linkedin.com/oauth/v2/authorization"; LinkedIn: {
const LinkedInAuthLogo = `${StaticBaseUrl}/img/social_linkedin.png`; scope: "r_liteprofile%20r_emailaddress",
endpoint: "https://www.linkedin.com/oauth/v2/authorization",
const WeComSilentAuthScope = "snsapi_userinfo"; },
const WeComAuthUri = "https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect"; WeCom: {
const WeComSilentAuthUrl = "https://open.weixin.qq.com/connect/oauth2/authorize"; scope: "snsapi_userinfo",
const WeComAuthLogo = `${StaticBaseUrl}/img/social_wecom.png`; endpoint: "https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect",
silentEndpoint: "https://open.weixin.qq.com/connect/oauth2/authorize",
// const LarkAuthScope = ""; },
const LarkAuthUri = "https://open.feishu.cn/open-apis/authen/v1/index"; Lark: {
const LarkAuthLogo = `${StaticBaseUrl}/img/social_lark.png`; // scope: "email",
endpoint: "https://open.feishu.cn/open-apis/authen/v1/index",
const GitLabAuthScope = "read_user+profile"; },
const GitLabAuthUri = "https://gitlab.com/oauth/authorize"; GitLab: {
const GitLabAuthLogo = `${StaticBaseUrl}/img/social_gitlab.png`; scope: "read_user+profile",
endpoint: "https://gitlab.com/oauth/authorize",
},
}
export function getAuthLogo(provider) { export function getAuthLogo(provider) {
if (provider.type === "Google") { return `${StaticBaseUrl}/img/social_${provider.type.toLowerCase()}.png`;
return GoogleAuthLogo;
} else if (provider.type === "GitHub") {
return GithubAuthLogo;
} else if (provider.type === "QQ") {
return QqAuthLogo;
} else if (provider.type === "WeChat") {
return WeChatAuthLogo;
} else if (provider.type === "Facebook") {
return FacebookAuthLogo;
} else if (provider.type === "DingTalk") {
return DingTalkAuthLogo;
} else if (provider.type === "Weibo") {
return WeiboAuthLogo;
} else if (provider.type === "Gitee") {
return GiteeAuthLogo;
} else if (provider.type === "LinkedIn") {
return LinkedInAuthLogo;
} else if (provider.type === "WeCom") {
return WeComAuthLogo;
} else if (provider.type === "Lark") {
return LarkAuthLogo;
} else if (provider.type === "GitLab") {
return GitLabAuthLogo;
}
} }
export function getAuthUrl(application, provider, method) { export function getAuthUrl(application, provider, method) {
@ -97,37 +76,40 @@ export function getAuthUrl(application, provider, method) {
return ""; return "";
} }
const endpoint = authInfo[provider.type].endpoint;
const redirectUri = `${window.location.origin}/callback`; const redirectUri = `${window.location.origin}/callback`;
const scope = authInfo[provider.type].scope;
const state = Util.getQueryParamsToState(application.name, provider.name, method); const state = Util.getQueryParamsToState(application.name, provider.name, method);
if (provider.type === "Google") { if (provider.type === "Google") {
return `${GoogleAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GoogleAuthScope}&response_type=code&state=${state}`; return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
} else if (provider.type === "GitHub") { } else if (provider.type === "GitHub") {
return `${GithubAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GithubAuthScope}&response_type=code&state=${state}`; return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
} else if (provider.type === "QQ") { } else if (provider.type === "QQ") {
return `${QqAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${QqAuthScope}&response_type=code&state=${state}`; return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
} else if (provider.type === "WeChat") { } else if (provider.type === "WeChat") {
return `${WeChatAuthUri}?appid=${provider.clientId}&redirect_uri=${redirectUri}&scope=${WeChatAuthScope}&response_type=code&state=${state}#wechat_redirect`; return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}#wechat_redirect`;
} else if (provider.type === "Facebook") { } else if (provider.type === "Facebook") {
return `${FacebookAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${FacebookAuthScope}&response_type=code&state=${state}`; return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
} else if (provider.type === "DingTalk") { } else if (provider.type === "DingTalk") {
return `${DingTalkAuthUri}?appid=${provider.clientId}&redirect_uri=${redirectUri}&scope=snsapi_login&response_type=code&state=${state}`; return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
} else if (provider.type === "Weibo") { } else if (provider.type === "Weibo") {
return `${WeiboAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${WeiboAuthScope}&response_type=code&state=${state}`; return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
} else if (provider.type === "Gitee") { } else if (provider.type === "Gitee") {
return `${GiteeAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GiteeAuthScope}&response_type=code&state=${state}`; return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
} else if (provider.type === "LinkedIn") { } else if (provider.type === "LinkedIn") {
return `${LinkedInAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${LinkedInAuthScope}&response_type=code&state=${state}`; return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${scope}&response_type=code&state=${state}`;
} else if (provider.type === "WeCom") { } else if (provider.type === "WeCom") {
if (provider.method === "Silent") { if (provider.method === "Silent") {
return `${WeComSilentAuthUrl}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${WeComSilentAuthScope}&response_type=code#wechat_redirect`; return `${authInfo[provider.type].silentEndpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&scope=${scope}&response_type=code#wechat_redirect`;
} else if (provider.method === "Normal") { } else if (provider.method === "Normal") {
return `${WeComAuthUri}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&usertype=member`; return `${endpoint}?appid=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&usertype=member`;
} else { } else {
return `https://error:not-supported-provider-method:${provider.method}`; return `https://error:not-supported-provider-method:${provider.method}`;
} }
} else if (provider.type === "Lark") { } else if (provider.type === "Lark") {
return `${LarkAuthUri}?app_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}`; return `${endpoint}?app_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}`;
} else if (provider.type === "GitLab") { } else if (provider.type === "GitLab") {
return `${GitLabAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${GitLabAuthScope}`; return `${endpoint}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&state=${state}&response_type=code&scope=${scope}`;
} }
} }