mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-16 00:20:06 +00:00
fix(auth): auto submit auth form if needed
This commit is contained in:
@@ -141,10 +141,17 @@ describe('AuthManager', () => {
|
|||||||
loginForm: { name: 'test' }
|
loginForm: { name: 'test' }
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
mockedAxios.post.mockImplementation(() =>
|
mockedAxios.post.mockImplementationOnce(() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
data: mockLoginAuthoriseRequiredResponse,
|
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) => {
|
private handleError = async (e: any, callback: any) => {
|
||||||
const response = e.response as AxiosResponse
|
const response = e.response as AxiosResponse
|
||||||
if (e instanceof AuthorizeError) {
|
if (e instanceof AuthorizeError) {
|
||||||
const res = await this.get(e.confirmUrl, undefined, 'text/plain')
|
const res = await this.httpClient.get(e.confirmUrl, {
|
||||||
if (isAuthorizeFormRequired(res.result as string)) {
|
responseType: 'text',
|
||||||
await this.authorize(res.result as string)
|
headers: { 'Content-Type': 'text/plain', Accept: '*/*' }
|
||||||
|
})
|
||||||
|
|
||||||
|
if (isAuthorizeFormRequired(res?.data as string)) {
|
||||||
|
await this.authorize(res.data as string)
|
||||||
}
|
}
|
||||||
return await callback()
|
return await callback()
|
||||||
}
|
}
|
||||||
@@ -386,6 +390,16 @@ const throwIfError = (response: AxiosResponse) => {
|
|||||||
throw new LoginRequiredError()
|
throw new LoginRequiredError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof response.data === 'string' &&
|
||||||
|
isAuthorizeFormRequired(response.data)
|
||||||
|
) {
|
||||||
|
throw new AuthorizeError(
|
||||||
|
'Authorization required',
|
||||||
|
response.request.responseURL
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof response.data === 'string' &&
|
typeof response.data === 'string' &&
|
||||||
isLogInRequired(response.data) &&
|
isLogInRequired(response.data) &&
|
||||||
|
|||||||
Reference in New Issue
Block a user