mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-07 12:30:06 +00:00
fix: removed getAuthCode function
This commit is contained in:
@@ -486,7 +486,7 @@ export default class SASjs {
|
|||||||
])
|
])
|
||||||
|
|
||||||
if (this.sasjsConfig.serverType === ServerType.Sasjs)
|
if (this.sasjsConfig.serverType === ServerType.Sasjs)
|
||||||
return await this.sasJSApiClient!.getAccessToken(authCode)
|
return await this.sasJSApiClient!.getAccessToken(clientId, authCode)
|
||||||
|
|
||||||
return await this.sasViyaApiClient!.getAccessToken(
|
return await this.sasViyaApiClient!.getAccessToken(
|
||||||
clientId,
|
clientId,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { ExecutionQuery } from './types'
|
|||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
|
import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
|
||||||
import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs'
|
import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs'
|
||||||
import { getAuthCodeForSasjs } from './auth/getAuthCodeForSasjs'
|
|
||||||
import { parseWeboutResponse } from './utils'
|
import { parseWeboutResponse } from './utils'
|
||||||
import { getTokens } from './auth/getTokens'
|
import { getTokens } from './auth/getTokens'
|
||||||
|
|
||||||
@@ -100,8 +99,11 @@ export class SASjsApiClient {
|
|||||||
* @param clientId - the client ID to authenticate with.
|
* @param clientId - the client ID to authenticate with.
|
||||||
* @param authCode - the auth code received from the server.
|
* @param authCode - the auth code received from the server.
|
||||||
*/
|
*/
|
||||||
public async getAccessToken(authCode: string): Promise<SASjsAuthResponse> {
|
public async getAccessToken(
|
||||||
return getAccessTokenForSasjs(this.requestClient, authCode)
|
clientId: string,
|
||||||
|
authCode: string
|
||||||
|
): Promise<SASjsAuthResponse> {
|
||||||
|
return getAccessTokenForSasjs(this.requestClient, clientId, authCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,16 +113,6 @@ export class SASjsApiClient {
|
|||||||
public async refreshTokens(refreshToken: string): Promise<SASjsAuthResponse> {
|
public async refreshTokens(refreshToken: string): Promise<SASjsAuthResponse> {
|
||||||
return refreshTokensForSasjs(this.requestClient, refreshToken)
|
return refreshTokensForSasjs(this.requestClient, refreshToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a login authenticate and returns an auth code for the given client.
|
|
||||||
* @param username - a string representing the username.
|
|
||||||
* @param password - a string representing the password.
|
|
||||||
* @param clientId - the client ID to authenticate with.
|
|
||||||
*/
|
|
||||||
public async getAuthCode(username: string, password: string) {
|
|
||||||
return getAuthCodeForSasjs(this.requestClient, username, password)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo move to sasjs/utils
|
// todo move to sasjs/utils
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ import { ServerType } from '@sasjs/utils/types'
|
|||||||
import { RequestClient } from '../request/RequestClient'
|
import { RequestClient } from '../request/RequestClient'
|
||||||
import { LoginOptions, LoginResult } from '../types/Login'
|
import { LoginOptions, LoginResult } from '../types/Login'
|
||||||
import { serialize } from '../utils'
|
import { serialize } from '../utils'
|
||||||
import { getAccessTokenForSasjs } from './getAccessTokenForSasjs'
|
|
||||||
import { getAuthCodeForSasjs } from './getAuthCodeForSasjs'
|
|
||||||
import { openWebPage } from './openWebPage'
|
import { openWebPage } from './openWebPage'
|
||||||
import { verifySas9Login } from './verifySas9Login'
|
import { verifySas9Login } from './verifySas9Login'
|
||||||
import { verifySasViyaLogin } from './verifySasViyaLogin'
|
import { verifySasViyaLogin } from './verifySasViyaLogin'
|
||||||
|
|||||||
@@ -9,10 +9,12 @@ import { RequestClient } from '../request/RequestClient'
|
|||||||
*/
|
*/
|
||||||
export async function getAccessTokenForSasjs(
|
export async function getAccessTokenForSasjs(
|
||||||
requestClient: RequestClient,
|
requestClient: RequestClient,
|
||||||
|
clientId: string,
|
||||||
authCode: string
|
authCode: string
|
||||||
) {
|
) {
|
||||||
const url = '/SASjsApi/auth/token'
|
const url = '/SASjsApi/auth/token'
|
||||||
const data = {
|
const data = {
|
||||||
|
clientId,
|
||||||
code: authCode
|
code: authCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import { prefixMessage } from '@sasjs/utils/error'
|
|
||||||
import { RequestClient } from '../request/RequestClient'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a login authenticate and returns an auth code for the given client.
|
|
||||||
* @param requestClient - the pre-configured HTTP request client
|
|
||||||
* @param username - a string representing the username.
|
|
||||||
* @param password - a string representing the password.
|
|
||||||
* @param clientId - the client ID to authenticate with.
|
|
||||||
*/
|
|
||||||
export const getAuthCodeForSasjs = async (
|
|
||||||
requestClient: RequestClient,
|
|
||||||
username: string,
|
|
||||||
password: string
|
|
||||||
) => {
|
|
||||||
const url = '/SASjsApi/auth/authorize'
|
|
||||||
const data = { username, password }
|
|
||||||
|
|
||||||
const { code: authCode } = await requestClient
|
|
||||||
.post<{ code: string }>(url, data, undefined)
|
|
||||||
.then((res) => res.result)
|
|
||||||
.catch((err) => {
|
|
||||||
throw prefixMessage(
|
|
||||||
err,
|
|
||||||
'Error while authenticating with provided username, password and clientId. '
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
return authCode
|
|
||||||
}
|
|
||||||
@@ -22,11 +22,15 @@ describe('getAccessTokenForSasjs', () => {
|
|||||||
Promise.resolve({ result: mockSasjsAuthResponse, etag: '' })
|
Promise.resolve({ result: mockSasjsAuthResponse, etag: '' })
|
||||||
)
|
)
|
||||||
|
|
||||||
await getAccessTokenForSasjs(requestClient, authConfig.refresh_token)
|
await getAccessTokenForSasjs(
|
||||||
|
requestClient,
|
||||||
|
authConfig.client,
|
||||||
|
authConfig.refresh_token
|
||||||
|
)
|
||||||
|
|
||||||
expect(requestClient.post).toHaveBeenCalledWith(
|
expect(requestClient.post).toHaveBeenCalledWith(
|
||||||
'/SASjsApi/auth/token',
|
'/SASjsApi/auth/token',
|
||||||
{ code: authConfig.refresh_token },
|
{ clientId: authConfig.client, code: authConfig.refresh_token },
|
||||||
undefined
|
undefined
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -47,6 +51,7 @@ describe('getAccessTokenForSasjs', () => {
|
|||||||
|
|
||||||
const error = await getAccessTokenForSasjs(
|
const error = await getAccessTokenForSasjs(
|
||||||
requestClient,
|
requestClient,
|
||||||
|
authConfig.client,
|
||||||
authConfig.refresh_token
|
authConfig.refresh_token
|
||||||
).catch((e) => e)
|
).catch((e) => e)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user