mirror of
https://github.com/sasjs/adapter.git
synced 2025-12-11 01:14:36 +00:00
fix(auth): use token functions from utils library
This commit is contained in:
@@ -3,9 +3,7 @@ import {
|
||||
isRelativePath,
|
||||
isUri,
|
||||
isUrl,
|
||||
fetchLogByChunks,
|
||||
isAccessTokenExpiring,
|
||||
isRefreshTokenExpiring
|
||||
fetchLogByChunks
|
||||
} from './utils'
|
||||
import * as NodeFormData from 'form-data'
|
||||
import {
|
||||
@@ -27,11 +25,18 @@ import {
|
||||
import { formatDataForRequest } from './utils/formatDataForRequest'
|
||||
import { SessionManager } from './SessionManager'
|
||||
import { ContextManager } from './ContextManager'
|
||||
import { timestampToYYYYMMDDHHMMSS } from '@sasjs/utils/time'
|
||||
import { Logger, LogLevel } from '@sasjs/utils/logger'
|
||||
import {
|
||||
timestampToYYYYMMDDHHMMSS,
|
||||
isAccessTokenExpiring,
|
||||
isRefreshTokenExpiring,
|
||||
Logger,
|
||||
LogLevel,
|
||||
SasAuthResponse,
|
||||
MacroVar,
|
||||
AuthConfig
|
||||
} from '@sasjs/utils'
|
||||
import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
|
||||
import { RequestClient } from './request/RequestClient'
|
||||
import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types'
|
||||
import { prefixMessage } from '@sasjs/utils/error'
|
||||
import * as mime from 'mime'
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import jwtDecode from 'jwt-decode'
|
||||
|
||||
/**
|
||||
* Checks if the Access Token is expired or is expiring in 1 hour. A default Access Token
|
||||
* lasts 12 hours. If the Access Token expires, the Refresh Token is used to fetch a new
|
||||
* Access Token. In the case that the Refresh Token is expired, 1 hour is enough to let
|
||||
* most jobs finish.
|
||||
* @param {string} token- token string that will be evaluated
|
||||
*/
|
||||
export function isAccessTokenExpiring(token: string): boolean {
|
||||
if (!token) {
|
||||
return true
|
||||
}
|
||||
const payload = jwtDecode<{ exp: number }>(token)
|
||||
const timeToLive = payload.exp - new Date().valueOf() / 1000
|
||||
|
||||
return timeToLive <= 60 * 60 // 1 hour
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Refresh Token is expired or expiring in 30 secs. A default Refresh Token
|
||||
* lasts 30 days. Once the Refresh Token expires, the user must re-authenticate (provide
|
||||
* credentials in a browser to obtain an authorisation code). 30 seconds is enough time
|
||||
* to make a request for a final Access Token.
|
||||
* @param {string} token- token string that will be evaluated
|
||||
*/
|
||||
export function isRefreshTokenExpiring(token?: string): boolean {
|
||||
if (!token) {
|
||||
return true
|
||||
}
|
||||
const payload = jwtDecode<{ exp: number }>(token)
|
||||
const timeToLive = payload.exp - new Date().valueOf() / 1000
|
||||
|
||||
return timeToLive <= 30 // 30 seconds
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from './asyncForEach'
|
||||
export * from './auth'
|
||||
export * from './compareTimestamps'
|
||||
export * from './convertToCsv'
|
||||
export * from './isRelativePath'
|
||||
|
||||
Reference in New Issue
Block a user