mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 09:24:35 +00:00
fix(auth): auto submit auth form if needed
This commit is contained in:
@@ -141,10 +141,17 @@ describe('AuthManager', () => {
|
||||
loginForm: { name: 'test' }
|
||||
})
|
||||
)
|
||||
mockedAxios.post.mockImplementation(() =>
|
||||
mockedAxios.post.mockImplementationOnce(() =>
|
||||
Promise.resolve({
|
||||
data: mockLoginAuthoriseRequiredResponse,
|
||||
config: { url: 'https://test.com/SASLogon/login' }
|
||||
config: { url: 'https://test.com/SASLogon/login' },
|
||||
request: { responseURL: 'https://test.com/OAuth/authorize' }
|
||||
})
|
||||
)
|
||||
|
||||
mockedAxios.get.mockImplementationOnce(() =>
|
||||
Promise.resolve({
|
||||
data: mockLoginAuthoriseRequiredResponse
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
@@ -332,9 +332,13 @@ export class RequestClient implements HttpClient {
|
||||
private handleError = async (e: any, callback: any) => {
|
||||
const response = e.response as AxiosResponse
|
||||
if (e instanceof AuthorizeError) {
|
||||
const res = await this.get(e.confirmUrl, undefined, 'text/plain')
|
||||
if (isAuthorizeFormRequired(res.result as string)) {
|
||||
await this.authorize(res.result as string)
|
||||
const res = await this.httpClient.get(e.confirmUrl, {
|
||||
responseType: 'text',
|
||||
headers: { 'Content-Type': 'text/plain', Accept: '*/*' }
|
||||
})
|
||||
|
||||
if (isAuthorizeFormRequired(res?.data as string)) {
|
||||
await this.authorize(res.data as string)
|
||||
}
|
||||
return await callback()
|
||||
}
|
||||
@@ -386,6 +390,16 @@ const throwIfError = (response: AxiosResponse) => {
|
||||
throw new LoginRequiredError()
|
||||
}
|
||||
|
||||
if (
|
||||
typeof response.data === 'string' &&
|
||||
isAuthorizeFormRequired(response.data)
|
||||
) {
|
||||
throw new AuthorizeError(
|
||||
'Authorization required',
|
||||
response.request.responseURL
|
||||
)
|
||||
}
|
||||
|
||||
if (
|
||||
typeof response.data === 'string' &&
|
||||
isLogInRequired(response.data) &&
|
||||
|
||||
Reference in New Issue
Block a user