@sasjs/adapter 4.2.0 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -59,7 +59,7 @@
59
59
  "jest-extended": "2.0.0",
60
60
  "node-polyfill-webpack-plugin": "1.1.4",
61
61
  "path": "0.12.7",
62
- "pem": "1.14.6",
62
+ "pem": "1.14.5",
63
63
  "prettier": "2.7.1",
64
64
  "process": "0.11.10",
65
65
  "rimraf": "3.0.2",
@@ -84,5 +84,5 @@
84
84
  "https": "1.0.0",
85
85
  "tough-cookie": "4.0.0"
86
86
  },
87
- "version": "4.2.0"
87
+ "version": "4.2.2"
88
88
  }
@@ -1,5 +1,6 @@
1
1
  import { ServerType } from '@sasjs/utils/types'
2
2
  import { RequestClient } from '../request/RequestClient'
3
+ import { NotFoundError } from '../types/errors'
3
4
  import { LoginOptions, LoginResult, LoginResultInternal } from '../types/Login'
4
5
  import { serialize } from '../utils'
5
6
  import { extractUserLongNameSas9 } from '../utils/sas9/extractUserLongNameSas9'
@@ -42,6 +43,9 @@ export class AuthManager {
42
43
  } = await this.fetchUserName()
43
44
 
44
45
  if (isLoggedInAlready) {
46
+ const logger = process.logger || console
47
+ logger.log('login was not attempted as a valid session already exists')
48
+
45
49
  await this.loginCallback()
46
50
 
47
51
  return {
@@ -109,6 +113,9 @@ export class AuthManager {
109
113
  } = await this.checkSession()
110
114
 
111
115
  if (isLoggedInAlready) {
116
+ const logger = process.logger || console
117
+ logger.log('login was not attempted as a valid session already exists')
118
+
112
119
  await this.loginCallback()
113
120
 
114
121
  this.userName = loginParams.username
@@ -131,6 +138,10 @@ export class AuthManager {
131
138
  loginResponse = await this.sendLoginRequest(newLoginForm, loginParams)
132
139
  }
133
140
 
141
+ // Sometimes due to redirection on SAS9 and SASViya we don't get the login response that says
142
+ // You have signed in. Therefore, we have to make an extra request for checking session to
143
+ // ensure either user is logged in or not.
144
+
134
145
  const res = await this.checkSession()
135
146
  isLoggedIn = res.isLoggedIn
136
147
  this.userLongName = res.userLongName
@@ -155,10 +166,12 @@ export class AuthManager {
155
166
  private async performCASSecurityCheck() {
156
167
  const casAuthenticationUrl = `${this.serverUrl}/SASStoredProcess/j_spring_cas_security_check`
157
168
 
158
- await this.requestClient.get<string>(
159
- `/SASLogon/login?service=${casAuthenticationUrl}`,
160
- undefined
161
- )
169
+ await this.requestClient
170
+ .get<string>(`/SASLogon/login?service=${casAuthenticationUrl}`, undefined)
171
+ .catch((err) => {
172
+ // ignore if resource not found error
173
+ if (!(err instanceof NotFoundError)) throw err
174
+ })
162
175
  }
163
176
 
164
177
  private async sendLoginRequest(
@@ -312,12 +325,13 @@ export class AuthManager {
312
325
  }
313
326
 
314
327
  private getLoginForm(response: any) {
315
- const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/
328
+ const pattern: RegExp = /<form.+action="(.*(Logon|login)[^"]*).*>/
316
329
  const matches = pattern.exec(response)
317
330
  const formInputs: any = {}
318
331
 
319
332
  if (matches && matches.length) {
320
333
  this.setLoginUrl(matches)
334
+ response = response.replace(/<input/g, '\n<input')
321
335
  const inputs = response.match(/<input.*"hidden"[^>]*>/g)
322
336
 
323
337
  if (inputs) {
@@ -1,5 +1,5 @@
1
1
  export const isLogInRequired = (response: string): boolean => {
2
- const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/gm
2
+ const pattern: RegExp = /<form.+action="(.*(Logon)|(login)[^"]*).*>/gm
3
3
  const matches = pattern.test(response)
4
4
  return matches
5
5
  }