1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-15 16:10:06 +00:00

fix(auth): refresh access tokens if expiring during job status check

This commit is contained in:
Krishna Acondy
2021-06-24 07:20:54 +01:00
parent 56b2ba026a
commit 57ef0647b5
3 changed files with 10 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ import { Context, EditContextInput, ContextAllAttributes } from './types'
import { isUrl } from './utils' import { isUrl } from './utils'
import { prefixMessage } from '@sasjs/utils/error' import { prefixMessage } from '@sasjs/utils/error'
import { RequestClient } from './request/RequestClient' import { RequestClient } from './request/RequestClient'
import { AuthConfig } from '@sasjs/utils/types'
export class ContextManager { export class ContextManager {
private defaultComputeContexts = [ private defaultComputeContexts = [
@@ -328,12 +329,12 @@ export class ContextManager {
public async getExecutableContexts( public async getExecutableContexts(
executeScript: Function, executeScript: Function,
accessToken?: string authConfig?: AuthConfig
) { ) {
const { result: contexts } = await this.requestClient const { result: contexts } = await this.requestClient
.get<{ items: Context[] }>( .get<{ items: Context[] }>(
`${this.serverUrl}/compute/contexts?limit=10000`, `${this.serverUrl}/compute/contexts?limit=10000`,
accessToken authConfig?.access_token
) )
.catch((err) => { .catch((err) => {
throw prefixMessage(err, 'Error while fetching compute contexts.') throw prefixMessage(err, 'Error while fetching compute contexts.')
@@ -350,7 +351,7 @@ export class ContextManager {
`test-${context.name}`, `test-${context.name}`,
linesOfCode, linesOfCode,
context.name, context.name,
accessToken, authConfig,
null, null,
false, false,
true, true,

View File

@@ -132,14 +132,14 @@ export class SASViyaApiClient {
/** /**
* Returns all compute contexts on this server that the user has access to. * Returns all compute contexts on this server that the user has access to.
* @param accessToken - an access token for an authorized user. * @param authConfig - an access token, refresh token, client and secret for an authorized user.
*/ */
public async getExecutableContexts(accessToken?: string) { public async getExecutableContexts(authConfig?: AuthConfig) {
const bindedExecuteScript = this.executeScript.bind(this) const bindedExecuteScript = this.executeScript.bind(this)
return await this.contextManager.getExecutableContexts( return await this.contextManager.getExecutableContexts(
bindedExecuteScript, bindedExecuteScript,
accessToken authConfig
) )
} }

View File

@@ -103,12 +103,12 @@ export default class SASjs {
/** /**
* Gets executable compute contexts. * Gets executable compute contexts.
* @param accessToken - an access token for an authorized user. * @param authConfig - an access token, refresh token, client and secret for an authorized user.
*/ */
public async getExecutableContexts(accessToken: string) { public async getExecutableContexts(authConfig: AuthConfig) {
this.isMethodSupported('getExecutableContexts', ServerType.SasViya) this.isMethodSupported('getExecutableContexts', ServerType.SasViya)
return await this.sasViyaApiClient!.getExecutableContexts(accessToken) return await this.sasViyaApiClient!.getExecutableContexts(authConfig)
} }
/** /**