A thin TIDAL API wrapper written in TypeScript with 100% test coverage.
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)
})()