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

feat(server): added sasjs server support

This commit is contained in:
Saad Jutt
2021-12-05 18:31:36 +05:00
parent 81d959c7c1
commit 712d1549c7
6 changed files with 47 additions and 31 deletions

View File

@@ -21,7 +21,9 @@ export class AuthManager {
this.logoutUrl =
this.serverType === ServerType.Sas9
? '/SASLogon/logout?'
: '/SASLogon/logout.do?'
: this.serverType === ServerType.SasViya
? '/SASLogon/logout.do?'
: '/SASjsApi/auth/logout'
}
/**
@@ -185,15 +187,15 @@ export class AuthManager {
* - a string `userName` and
* - a form `loginForm` if not loggedin.
*/
public async checkSession(): Promise<{
public async checkSession(accessToken?: string): Promise<{
isLoggedIn: boolean
userName: string
loginForm?: any
}> {
const { isLoggedIn, userName } = await this.fetchUserName()
const { isLoggedIn, userName } = await this.fetchUserName(accessToken)
let loginForm = null
if (!isLoggedIn) {
if (!isLoggedIn && this.serverType !== ServerType.Sasjs) {
//We will logout to make sure cookies are removed and login form is presented
//Residue can happen in case of session expiration
await this.logOut()
@@ -218,19 +220,19 @@ export class AuthManager {
return await this.getLoginForm(formResponse)
}
private async fetchUserName(): Promise<{
private async fetchUserName(accessToken?: string): Promise<{
isLoggedIn: boolean
userName: string
}> {
//For VIYA we will send request on API endpoint. Which is faster then pinging SASJobExecution.
//For SAS9 we will send request on SASStoredProcess
const url =
this.serverType === ServerType.SasViya
? `${this.serverUrl}/identities/users/@currentUser`
: `${this.serverUrl}/SASStoredProcess`
: this.serverType === ServerType.Sas9
? `${this.serverUrl}/SASStoredProcess`
: `${this.serverUrl}/SASjsApi/session`
const { result: loginResponse } = await this.requestClient
.get<string>(url, undefined, 'text/plain')
.get<string>(url, accessToken, 'text/plain')
.catch((err: any) => {
return { result: 'authErr' }
})
@@ -257,6 +259,9 @@ export class AuthManager {
.map((name: string) => name.slice(0, 3).toLowerCase())
.join('')
case ServerType.Sasjs:
return response?.username
default:
console.error('Server Type not found in extractUserName function')
return ''
@@ -307,7 +312,10 @@ export class AuthManager {
/**
* Logs out of the configured SAS server.
*/
public logOut() {
public logOut(accessToken?: string) {
if (this.serverType === ServerType.Sasjs) {
return this.requestClient.post(this.logoutUrl, undefined, accessToken)
}
this.requestClient.clearCsrfTokens()
return this.requestClient.get(this.logoutUrl, undefined).then(() => true)
}