1
0
mirror of https://github.com/sasjs/adapter.git synced 2025-12-11 01:14:36 +00:00

fix: removed getAuthCode function

This commit is contained in:
Saad Jutt
2022-05-11 19:22:01 +05:00
parent 10c72e6483
commit b8ea618f1e
6 changed files with 15 additions and 48 deletions

View File

@@ -486,7 +486,7 @@ export default class 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(
clientId,

View File

@@ -3,7 +3,6 @@ import { ExecutionQuery } from './types'
import { RequestClient } from './request/RequestClient'
import { getAccessTokenForSasjs } from './auth/getAccessTokenForSasjs'
import { refreshTokensForSasjs } from './auth/refreshTokensForSasjs'
import { getAuthCodeForSasjs } from './auth/getAuthCodeForSasjs'
import { parseWeboutResponse } from './utils'
import { getTokens } from './auth/getTokens'
@@ -100,8 +99,11 @@ export class SASjsApiClient {
* @param clientId - the client ID to authenticate with.
* @param authCode - the auth code received from the server.
*/
public async getAccessToken(authCode: string): Promise<SASjsAuthResponse> {
return getAccessTokenForSasjs(this.requestClient, authCode)
public async getAccessToken(
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> {
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

View File

@@ -2,8 +2,6 @@ import { ServerType } from '@sasjs/utils/types'
import { RequestClient } from '../request/RequestClient'
import { LoginOptions, LoginResult } from '../types/Login'
import { serialize } from '../utils'
import { getAccessTokenForSasjs } from './getAccessTokenForSasjs'
import { getAuthCodeForSasjs } from './getAuthCodeForSasjs'
import { openWebPage } from './openWebPage'
import { verifySas9Login } from './verifySas9Login'
import { verifySasViyaLogin } from './verifySasViyaLogin'

View File

@@ -9,10 +9,12 @@ import { RequestClient } from '../request/RequestClient'
*/
export async function getAccessTokenForSasjs(
requestClient: RequestClient,
clientId: string,
authCode: string
) {
const url = '/SASjsApi/auth/token'
const data = {
clientId,
code: authCode
}

View File

@@ -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
}

View File

@@ -22,11 +22,15 @@ describe('getAccessTokenForSasjs', () => {
Promise.resolve({ result: mockSasjsAuthResponse, etag: '' })
)
await getAccessTokenForSasjs(requestClient, authConfig.refresh_token)
await getAccessTokenForSasjs(
requestClient,
authConfig.client,
authConfig.refresh_token
)
expect(requestClient.post).toHaveBeenCalledWith(
'/SASjsApi/auth/token',
{ code: authConfig.refresh_token },
{ clientId: authConfig.client, code: authConfig.refresh_token },
undefined
)
})
@@ -47,6 +51,7 @@ describe('getAccessTokenForSasjs', () => {
const error = await getAccessTokenForSasjs(
requestClient,
authConfig.client,
authConfig.refresh_token
).catch((e) => e)