mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-17 09:00:06 +00:00
fix: while checking session extract username also
This commit is contained in:
582
package-lock.json
generated
582
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -110,7 +110,7 @@ export class AuthManager {
|
|||||||
//For SAS9 we will send request on SASStoredProcess
|
//For SAS9 we will send request on SASStoredProcess
|
||||||
const url =
|
const url =
|
||||||
this.serverType === 'SASVIYA'
|
this.serverType === 'SASVIYA'
|
||||||
? `${this.serverUrl}/identities`
|
? `${this.serverUrl}/identities/users/@currentUser`
|
||||||
: `${this.serverUrl}/SASStoredProcess`
|
: `${this.serverUrl}/SASStoredProcess`
|
||||||
|
|
||||||
const { result: loginResponse } = await this.requestClient
|
const { result: loginResponse } = await this.requestClient
|
||||||
@@ -120,6 +120,10 @@ export class AuthManager {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const isLoggedIn = loginResponse !== 'authErr'
|
const isLoggedIn = loginResponse !== 'authErr'
|
||||||
|
const userName = isLoggedIn
|
||||||
|
? this.extractUserName(loginResponse)
|
||||||
|
: this.userName
|
||||||
|
|
||||||
let loginForm = null
|
let loginForm = null
|
||||||
|
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
@@ -137,11 +141,16 @@ export class AuthManager {
|
|||||||
|
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
isLoggedIn,
|
isLoggedIn,
|
||||||
userName: this.userName,
|
userName: userName ?? this.userName,
|
||||||
loginForm
|
loginForm
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extractUserName = (response: string) =>
|
||||||
|
this.serverType === 'SASVIYA'
|
||||||
|
? response?.match(/<id>[0-1a-zA-Z]*<\/id>/)?.[0].slice(4, -5)
|
||||||
|
: response?.match(/"title":"Log Off [0-1a-zA-Z]*"/)?.[0].slice(17, -1)
|
||||||
|
|
||||||
private getLoginForm(response: any) {
|
private getLoginForm(response: any) {
|
||||||
const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/
|
const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/
|
||||||
const matches = pattern.exec(response)
|
const matches = pattern.exec(response)
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ describe('AuthManager', () => {
|
|||||||
expect(response.isLoggedIn).toBeTruthy()
|
expect(response.isLoggedIn).toBeTruthy()
|
||||||
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
expect(mockedAxios.get).toHaveBeenNthCalledWith(
|
||||||
1,
|
1,
|
||||||
`http://test-server.com/identities`,
|
`http://test-server.com/identities/users/@currentUser`,
|
||||||
{
|
{
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
responseType: 'text',
|
responseType: 'text',
|
||||||
|
|||||||
Reference in New Issue
Block a user