mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-08 04:50:06 +00:00
fix: modify the reqgex to handle the loginForm response on latest sas9
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { ServerType } from '@sasjs/utils/types'
|
import { ServerType } from '@sasjs/utils/types'
|
||||||
import { RequestClient } from '../request/RequestClient'
|
import { RequestClient } from '../request/RequestClient'
|
||||||
|
import { NotFoundError } from '../types/errors'
|
||||||
import { LoginOptions, LoginResult, LoginResultInternal } from '../types/Login'
|
import { LoginOptions, LoginResult, LoginResultInternal } from '../types/Login'
|
||||||
import { serialize } from '../utils'
|
import { serialize } from '../utils'
|
||||||
import { extractUserLongNameSas9 } from '../utils/sas9/extractUserLongNameSas9'
|
import { extractUserLongNameSas9 } from '../utils/sas9/extractUserLongNameSas9'
|
||||||
@@ -47,7 +48,8 @@ export class AuthManager {
|
|||||||
return {
|
return {
|
||||||
isLoggedIn: true,
|
isLoggedIn: true,
|
||||||
userName: currentSessionUserName,
|
userName: currentSessionUserName,
|
||||||
userLongName: currentSessionUserLongName
|
userLongName: currentSessionUserLongName,
|
||||||
|
message: 'User is already Logged In!'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +118,8 @@ export class AuthManager {
|
|||||||
return {
|
return {
|
||||||
isLoggedIn: true,
|
isLoggedIn: true,
|
||||||
userName: this.userName,
|
userName: this.userName,
|
||||||
userLongName: this.userLongName
|
userLongName: this.userLongName,
|
||||||
|
message: 'User is already Logged In!'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,10 +158,12 @@ export class AuthManager {
|
|||||||
private async performCASSecurityCheck() {
|
private async performCASSecurityCheck() {
|
||||||
const casAuthenticationUrl = `${this.serverUrl}/SASStoredProcess/j_spring_cas_security_check`
|
const casAuthenticationUrl = `${this.serverUrl}/SASStoredProcess/j_spring_cas_security_check`
|
||||||
|
|
||||||
await this.requestClient.get<string>(
|
await this.requestClient
|
||||||
`/SASLogon/login?service=${casAuthenticationUrl}`,
|
.get<string>(`/SASLogon/login?service=${casAuthenticationUrl}`, undefined)
|
||||||
undefined
|
.catch((err) => {
|
||||||
)
|
// ignore if resource not found error
|
||||||
|
if (!(err instanceof NotFoundError)) throw err
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private async sendLoginRequest(
|
private async sendLoginRequest(
|
||||||
@@ -312,12 +317,13 @@ export class AuthManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getLoginForm(response: any) {
|
private getLoginForm(response: any) {
|
||||||
const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/
|
const pattern: RegExp = /<form.+action="(.*(Logon)|(login)[^"]*).*>/
|
||||||
const matches = pattern.exec(response)
|
const matches = pattern.exec(response)
|
||||||
const formInputs: any = {}
|
const formInputs: any = {}
|
||||||
|
|
||||||
if (matches && matches.length) {
|
if (matches && matches.length) {
|
||||||
this.setLoginUrl(matches)
|
this.setLoginUrl(matches)
|
||||||
|
response = response.replace(/<input/g, '\n<input')
|
||||||
const inputs = response.match(/<input.*"hidden"[^>]*>/g)
|
const inputs = response.match(/<input.*"hidden"[^>]*>/g)
|
||||||
|
|
||||||
if (inputs) {
|
if (inputs) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export const isLogInRequired = (response: string): boolean => {
|
export const isLogInRequired = (response: string): boolean => {
|
||||||
const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/gm
|
const pattern: RegExp = /<form.+action="(.*(Logon)|(login)[^"]*).*>/gm
|
||||||
const matches = pattern.test(response)
|
const matches = pattern.test(response)
|
||||||
return matches
|
return matches
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export interface LoginResult {
|
|||||||
isLoggedIn: boolean
|
isLoggedIn: boolean
|
||||||
userName: string
|
userName: string
|
||||||
userLongName: string
|
userLongName: string
|
||||||
|
message?: string
|
||||||
}
|
}
|
||||||
export interface LoginResultInternal {
|
export interface LoginResultInternal {
|
||||||
isLoggedIn: boolean
|
isLoggedIn: boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user