2021-02-14 16:59:08 +08:00
|
|
|
// Copyright 2021 The casbin Authors. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2021-03-21 13:45:55 +08:00
|
|
|
import * as Util from "./Util";
|
2021-02-14 16:59:08 +08:00
|
|
|
|
|
|
|
const GoogleAuthScope = "profile+email"
|
|
|
|
const GoogleAuthUri = "https://accounts.google.com/signin/oauth";
|
|
|
|
const GoogleAuthLogo = "https://cdn.jsdelivr.net/gh/casbin/static/img/social_google.png";
|
|
|
|
|
|
|
|
const GithubAuthScope = "user:email+read:user"
|
|
|
|
const GithubAuthUri = "https://github.com/login/oauth/authorize";
|
|
|
|
const GithubAuthLogo = "https://cdn.jsdelivr.net/gh/casbin/static/img/social_github.png";
|
|
|
|
|
|
|
|
const QqAuthScope = "get_user_info"
|
|
|
|
const QqAuthUri = "https://graph.qq.com/oauth2.0/authorize";
|
|
|
|
const QqAuthLogo = "https://cdn.jsdelivr.net/gh/casbin/static/img/social_qq.png";
|
|
|
|
|
|
|
|
const WeChatAuthScope = "snsapi_login"
|
|
|
|
const WeChatAuthUri = "https://open.weixin.qq.com/connect/qrconnect";
|
|
|
|
const WeChatAuthLogo = "https://cdn.jsdelivr.net/gh/casbin/static/img/social_wechat.png";
|
|
|
|
|
2021-06-06 10:06:54 +08:00
|
|
|
const FacebookAuthScope = "email,public_profile"
|
|
|
|
const FacebookAuthUri = "https://www.facebook.com/dialog/oauth"
|
|
|
|
const FacebookAuthLogo = "https://cdn.jsdelivr.net/gh/casbin/static/img/social_facebook.png"
|
|
|
|
|
2021-06-09 11:15:49 +08:00
|
|
|
// const DingTalkAuthScope = "email,public_profile"
|
|
|
|
const DingTalkAuthUri = "https://oapi.dingtalk.com/connect/oauth2/sns_authorize"
|
|
|
|
const DingTalkAuthLogo = "https://cdn.jsdelivr.net/gh/casbin/static/img/social_dingtalk.png"
|
|
|
|
|
2021-06-10 16:55:31 +08:00
|
|
|
const WeiboAuthScope = "email"
|
|
|
|
const WeiboAuthUri = "https://api.weibo.com/oauth2/authorize"
|
|
|
|
const WeiboAuthLogo = "https://cdn.jsdelivr.net/gh/casbin/static/img/social_weibo.png"
|
2021-06-09 11:15:49 +08:00
|
|
|
|
2021-02-14 16:59:08 +08:00
|
|
|
export function getAuthLogo(provider) {
|
2021-03-28 20:20:40 +08:00
|
|
|
if (provider.type === "Google") {
|
2021-02-14 16:59:08 +08:00
|
|
|
return GoogleAuthLogo;
|
2021-03-28 20:20:40 +08:00
|
|
|
} else if (provider.type === "GitHub") {
|
2021-02-14 16:59:08 +08:00
|
|
|
return GithubAuthLogo;
|
2021-03-28 20:20:40 +08:00
|
|
|
} else if (provider.type === "QQ") {
|
2021-02-14 16:59:08 +08:00
|
|
|
return QqAuthLogo;
|
2021-03-28 20:20:40 +08:00
|
|
|
} else if (provider.type === "WeChat") {
|
2021-02-14 16:59:08 +08:00
|
|
|
return WeChatAuthLogo;
|
2021-06-06 10:06:54 +08:00
|
|
|
} else if (provider.type === "Facebook") {
|
|
|
|
return FacebookAuthLogo;
|
2021-06-09 11:15:49 +08:00
|
|
|
} else if (provider.type === "DingTalk") {
|
|
|
|
return DingTalkAuthLogo;
|
2021-06-10 16:55:31 +08:00
|
|
|
} else if (provider.type === "Weibo") {
|
|
|
|
return WeiboAuthLogo;
|
2021-02-14 16:59:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-14 21:21:42 +08:00
|
|
|
export function getAuthUrl(application, provider, method) {
|
2021-04-19 01:14:41 +08:00
|
|
|
if (application === null || provider === null) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2021-03-21 16:05:00 +08:00
|
|
|
const redirectUri = `${window.location.origin}/callback`;
|
|
|
|
const state = Util.getQueryParamsToState(application.name, provider.name, method);
|
2021-03-28 20:20:40 +08:00
|
|
|
if (provider.type === "Google") {
|
2021-03-21 13:45:55 +08:00
|
|
|
return `${GoogleAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GoogleAuthScope}&response_type=code&state=${state}`;
|
2021-03-28 20:20:40 +08:00
|
|
|
} else if (provider.type === "GitHub") {
|
2021-03-21 13:45:55 +08:00
|
|
|
return `${GithubAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GithubAuthScope}&response_type=code&state=${state}`;
|
2021-03-28 20:20:40 +08:00
|
|
|
} else if (provider.type === "QQ") {
|
2021-03-21 13:45:55 +08:00
|
|
|
return `${QqAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${QqAuthScope}&response_type=code&state=${state}`;
|
2021-03-28 20:20:40 +08:00
|
|
|
} else if (provider.type === "WeChat") {
|
2021-03-21 13:45:55 +08:00
|
|
|
return `${WeChatAuthUri}?appid=${provider.clientId}&redirect_uri=${redirectUri}&scope=${WeChatAuthScope}&response_type=code&state=${state}#wechat_redirect`;
|
2021-06-06 10:06:54 +08:00
|
|
|
} else if (provider.type === "Facebook") {
|
|
|
|
return `${FacebookAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${FacebookAuthScope}&response_type=code&state=${state}`;
|
2021-06-09 11:15:49 +08:00
|
|
|
} else if (provider.type === "DingTalk") {
|
|
|
|
return `${DingTalkAuthUri}?appid=${provider.clientId}&redirect_uri=${redirectUri}&scope=snsapi_login&response_type=code&state=${state}`;
|
2021-06-10 16:55:31 +08:00
|
|
|
} else if (provider.type === "Weibo") {
|
|
|
|
return `${WeiboAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${WeiboAuthScope}&response_type=code&state=${state}`;
|
2021-02-14 16:59:08 +08:00
|
|
|
}
|
|
|
|
}
|