import axios from 'axios' ; let authToken = null ; export function getAuthToken ( ) { return authToken ; } export function setAuthToken ( newAuthToken ) { authToken = newAuthToken ; } export function isAuthTokenSet ( ) { return authToken !== null ; } export async function requestAuthToken ( clientId , clientSecret ) { const response = await axios ( { method : 'post' , url : 'https://services.sentinel-hub.com/oauth/token' , headers : { 'content-type' : 'application/x-www-form-urlencoded' } , data : `grant_type=client_credentials&client_id=${ encodeURIComponent ( clientId ) }&client_secret=${ encodeURIComponent ( clientSecret ) }` , } ) ; return response . data . access_token ; }