1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 01:14:36 +00:00

feat(login): add redirected login mechanism

This commit is contained in:
Krishna Acondy
2021-08-21 21:36:50 +01:00
parent 4f62cd0148
commit 830a907bd1
6 changed files with 71 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
import { ServerType } from '@sasjs/utils/types'
import { RequestClient } from '../request/RequestClient'
import { serialize } from '../utils'
import { delay, serialize } from '../utils'
export class AuthManager {
public userName = ''
@@ -19,6 +19,37 @@ export class AuthManager {
: '/SASLogon/logout.do?'
}
public async redirectedLogIn() {
await this.logOut()
const loginPopup = window.open(
this.loginUrl.replace('.do', ''),
'_blank',
'toolbar=0,location=0,menubar=0,width=500,height=500'
)
let isLoggedIn = false
let startTime = new Date()
let elapsedSeconds = 0
do {
await delay(1000)
isLoggedIn =
document.cookie.includes('Current-User') &&
document.cookie.includes('userId')
elapsedSeconds = (new Date().valueOf() - startTime.valueOf()) / 1000
} while (!isLoggedIn && elapsedSeconds < 5 * 60)
let isAuthorized = false
startTime = new Date()
do {
await delay(1000)
isAuthorized = !loginPopup?.window.location.href.includes('SASLogon')
elapsedSeconds = (new Date().valueOf() - startTime.valueOf()) / 1000
} while (!isAuthorized && elapsedSeconds < 5 * 60)
loginPopup?.close()
return { isLoggedIn: isLoggedIn && isAuthorized, userName: 'test' }
}
/**
* Logs into the SAS server with the supplied credentials.
* @param username - a string representing the username.