Web: Files : Settings : Added OAuth login for services

This commit is contained in:
Ilya Oleshko 2020-11-19 14:05:07 +03:00
parent cdf21f36da
commit a76b6fa439
3 changed files with 48 additions and 4 deletions

View File

@ -134,10 +134,40 @@ class ConnectClouds extends React.Component {
} }
} }
showOAuthModal = (token, serviceData) => {
this.setState({
showAccountSettingDialog: true,
selectedServiceData: {
title: serviceData.title,
provider_key: serviceData.title,
link: serviceData.link,
token,
},
});
};
getOAuthToken = (modal, serviceData) => {
let t = setInterval(() => {
try {
if (modal.json) {
clearInterval(t);
const token = modal.json.response;
modal.close();
this.showOAuthModal(token, serviceData);
}
} catch {
return;
}
}, 1000);
};
onShowService = (e) => { onShowService = (e) => {
const selectedServiceData = e.currentTarget.dataset; const selectedServiceData = e.currentTarget.dataset;
const showAccountSettingDialog = !e.currentTarget.dataset.link; const showAccountSettingDialog = !e.currentTarget.dataset.link;
!showAccountSettingDialog && openConnectWindow(selectedServiceData.title); !showAccountSettingDialog &&
openConnectWindow(selectedServiceData.title).then((modal) =>
this.getOAuthToken(modal, selectedServiceData)
);
this.setState({ this.setState({
showThirdPartyDialog: !this.state.showThirdPartyDialog, showThirdPartyDialog: !this.state.showThirdPartyDialog,

View File

@ -45,7 +45,7 @@ const StyledConnectedDialog = styled.div`
const ConnectedDialog = (props) => { const ConnectedDialog = (props) => {
const { onClose, visible, t, item } = props; const { onClose, visible, t, item } = props;
const { corporate, title, link, auth_key, provider_id, provider_key } = item; const { corporate, title, link, token, provider_id, provider_key } = item;
const [urlValue, setUrlValue] = useState(""); const [urlValue, setUrlValue] = useState("");
const [loginValue, setLoginValue] = useState(""); const [loginValue, setLoginValue] = useState("");
@ -64,7 +64,7 @@ const ConnectedDialog = (props) => {
urlValue, urlValue,
loginValue, loginValue,
passwordValue, passwordValue,
auth_key, token,
isCorporate, isCorporate,
customerTitle, customerTitle,
provider_key, provider_key,

View File

@ -1382,6 +1382,20 @@ const convertServiceName = (serviceName) => {
export function openConnectWindow(serviceName) { export function openConnectWindow(serviceName) {
const service = convertServiceName(serviceName); const service = convertServiceName(serviceName);
return api.files.openConnectWindow(service).then((link) => { return api.files.openConnectWindow(service).then((link) => {
window.open(link, "", "width=1020,height=600"); return oAuthPopup(link);
}); });
} }
export function oAuthPopup(url) {
let newWindow;
try {
let params =
"height=600,width=1020,resizable=0,status=0,toolbar=0,menubar=0,location=1";
newWindow = window.open(url, "Authorization", params);
} catch (err) {
newWindow = window.open(url, "Authorization");
}
return newWindow;
}