mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 04:20:05 +00:00
chore(*): refactor, move all auth-related code to auth folder
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
export * from './asyncForEach'
|
||||
export * from './compareTimestamps'
|
||||
export * from './convertToCsv'
|
||||
export * from './isAuthorizeFormRequired'
|
||||
export * from './isLoginRequired'
|
||||
export * from './isLoginSuccess'
|
||||
export * from './isRelativePath'
|
||||
export * from './isUri'
|
||||
export * from './isUrl'
|
||||
export * from './makeRequest'
|
||||
export * from './needsRetry'
|
||||
export * from './parseAndSubmitAuthorizeForm'
|
||||
export * from './parseGeneratedCode'
|
||||
export * from './parseSourceCode'
|
||||
export * from './parseSasViyaLog'
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export const isAuthorizeFormRequired = (response: string): boolean => {
|
||||
return /<form.+action="(.*Logon\/oauth\/authorize[^"]*).*>/gm.test(response)
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
export const isLogInRequired = (response: string): boolean => {
|
||||
const pattern: RegExp = /<form.+action="(.*Logon[^"]*).*>/gm
|
||||
const matches = pattern.test(response)
|
||||
return matches
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export const isLogInSuccess = (response: string): boolean =>
|
||||
/You have signed in/gm.test(response)
|
||||
@@ -1,42 +0,0 @@
|
||||
import axios from 'axios'
|
||||
|
||||
export const parseAndSubmitAuthorizeForm = async (
|
||||
response: string,
|
||||
serverUrl: string
|
||||
) => {
|
||||
let authUrl: string | null = null
|
||||
const params: any = {}
|
||||
|
||||
const responseBody = response.split('<body>')[1].split('</body>')[0]
|
||||
const bodyElement = document.createElement('div')
|
||||
bodyElement.innerHTML = responseBody
|
||||
|
||||
const form = bodyElement.querySelector('#application_authorization')
|
||||
authUrl = form ? serverUrl + form.getAttribute('action') : null
|
||||
|
||||
const inputs: any = form?.querySelectorAll('input')
|
||||
|
||||
for (const input of inputs) {
|
||||
if (input.name === 'user_oauth_approval') {
|
||||
input.value = 'true'
|
||||
}
|
||||
|
||||
params[input.name] = input.value
|
||||
}
|
||||
|
||||
const formData = new FormData()
|
||||
|
||||
for (const key in params) {
|
||||
if (params.hasOwnProperty(key)) {
|
||||
formData.append(key, params[key])
|
||||
}
|
||||
}
|
||||
|
||||
if (!authUrl) {
|
||||
throw new Error('Auth Form URL is null or undefined.')
|
||||
}
|
||||
|
||||
return await axios
|
||||
.post(authUrl, formData, { withCredentials: true, responseType: 'text' })
|
||||
.then((response) => response.data)
|
||||
}
|
||||
Reference in New Issue
Block a user