Skip to content

Commit

Permalink
login bug solved
Browse files Browse the repository at this point in the history
  • Loading branch information
ganning127 committed Jun 25, 2024
1 parent 6faedde commit c46435c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
53 changes: 43 additions & 10 deletions airavata-local-agent/main/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ ipcMain.on('ci-logon-logout', (event) => {
ipcMain.on('ci-logon-login', async (event) => {

console.log("Logging in with CI logon");
log.warn('__dirname:', __dirname);
log.warn("Logging in with CI logon");
var authWindow = createWindow('authWindow', {
width: 1200,
Expand All @@ -124,18 +123,52 @@ ipcMain.on('ci-logon-login', async (event) => {
authWindow.loadURL('https://md.cybershuttle.org/auth/redirect_login/cilogon/');

authWindow.show();
/*
setTimeout(async () => {
const tokens = await getToken(url);
if (tokens.length > 0) {
const [accessToken, refreshToken] = tokens;
console.log("Tokens", accessToken, refreshToken);
event.sender.send('ci-logon-success', accessToken, refreshToken);
// authWindow.loadURL('https://md.cybershuttle.org/auth/redirect_login/cilogon/');
}
}, 5000);
*/
// after we hit https://md.cybershuttle.org/auth/callback, once we get the next URL that starts with md.cybershuttle.org, we can send the info back to the user

let hitUrl = false;
authWindow.webContents.on('will-redirect', async (e, url) => {
if (url.startsWith("https://md.cybershuttle.org/auth/callback/")) {
const tokens = await getToken(url);

if (tokens.length > 0) {
const [accessToken, refreshToken] = tokens;
console.log("Tokens", accessToken, refreshToken);
event.sender.send('ci-logon-success', accessToken, refreshToken);
}
authWindow.close();
authWindow.loadURL('https://md.cybershuttle.org/auth/redirect_login/cilogon/');
// hitUrl = true;

setTimeout(async () => {
const tokens = await getToken(url);

if (tokens.length > 0) {
const [accessToken, refreshToken] = tokens;
console.log("Tokens", accessToken, refreshToken);
event.sender.send('ci-logon-success', accessToken, refreshToken);
authWindow.close();
// authWindow.loadURL('https://md.cybershuttle.org/auth/redirect_login/cilogon/');

}
}, 5000);

authWindow.hide();
}

// if (hitUrl && url.startsWith("https://md.cybershuttle.org/")) {
// const tokens = await getToken(url);

// if (tokens.length > 0) {
// const [accessToken, refreshToken] = tokens;
// event.sender.send('ci-logon-success', accessToken, refreshToken);
// // authWindow.hide();
// }
// }
});
});

Expand Down
9 changes: 6 additions & 3 deletions airavata-local-agent/renderer/pages/login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const Login = () => {

useEffect(() => {
if (localStorage.getItem("ciLoginAuto") === "true") {
setLoading(true);
localStorage.removeItem("ciLoginAuto");
window.auth.ciLogonLogin();
}
Expand Down Expand Up @@ -89,9 +90,11 @@ const Login = () => {
<Heading size='md' textAlign="left" color='blue.500'>

Log in with your existing organizational login</Heading>
<Button colorScheme='blue' w='full' mt={4} onClick={handleCiLogin}> {
loading && <Spinner mr={2} />
}Login with Existing Institution Credentials</Button>
<Button colorScheme='blue' w='full' mt={4} onClick={handleCiLogin}
isDisabled={loading}
> {
loading && <Spinner mr={2} />
}Login with CILogon</Button>
</Box>

{/* <Box shadow='md' rounded='md' p={4} mt={8}>
Expand Down

0 comments on commit c46435c

Please sign in to comment.