MCPcopy Create free account
hub / github.com/SmartThingsCommunity/smartthings-cli / authenticate

Function authenticate

src/lib/login-authenticator.ts:280–297  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

278 }
279
280 const authenticate = async (): Promise<HttpClientHeaders> => {
281 logger.debug('authentication - enter')
282 // refresh if we have less than an hour left on the auth token
283 if (authenticationInfo && authenticationInfo.expires.getTime() < Date.now() + 60 * 60 * 1000) {
284 await refreshToken()
285 }
286
287 // log in if we don't have authentication info or the refresh failed
288 if (!authenticationInfo || authenticationInfo.expires.getTime() < Date.now() + 59 * 60 * 1000) {
289 await login()
290 }
291
292 if (authenticationInfo) {
293 return { Authorization: `Bearer ${authenticationInfo.accessToken}` }
294 }
295
296 throw new Error('unable to obtain user credentials')
297 }
298
299 return {
300 login,

Callers

nothing calls this directly

Calls 2

refreshTokenFunction · 0.85
loginFunction · 0.85

Tested by

no test coverage detected