Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
/ opentidal Public archive

A thin TIDAL API wrapper written in TypeScript with 100% test coverage.

License

Notifications You must be signed in to change notification settings

cloudr-app/opentidal

Repository files navigation


A thin TIDAL API wrapper written in TypeScript with 100% test coverage.

Codecov

Example usage

import { auth } from "opentidal"

const client_id = "client_id"
const client_secret = "client_secret"

;(async () => {
  // get a device token to start the auth process
  const deviceToken = await auth.getDeviceToken({ client_id })

  // prints something like https://link.tidal.com/ABCDE
  // go to the provided URI and authorize the device
  console.log(`authorize via https://${deviceToken.verificationUriComplete}`)

  let accessToken

  // poll this endpoint until authorization is complete
  const interval = setInterval(async () => {
    console.log("checking if authorized")
    accessToken = await auth.getAccessToken({
      client_id,
      client_secret,
      device_code: deviceToken.deviceCode,
    })

    // if the response contains an access_token, you're authenticated!
    if ("access_token" in accessToken) {
      clearInterval(interval)
      console.log("access_token:", accessToken.access_token)
    }
  }, deviceToken.interval * 1000)
})()