Auth module handles Authentication and Authorization when interacting with the TIDAL API or other TIDAL SDKs. It provides a simple setup and easy to use SDK to interact with the oAuth2 server endpoints.
npm install @tidal-music/auth
(or similar for other package managers)
This authentication method uses clientId
and clientSecret
, e.g. when utilizing the TIDAL API. Follow these steps or refer to our example for "client credentials".
init
and ensure to provide the clientId
and clientSecret
.credentialsProvider.getCredentials
, which should return credentials containing a token
.Authentication: Bearer YOUR_TOKEN
as a header.To implement the login redirect flow, follow these steps or refer to our example for "authorization code".
init
function.initializeLogin
function, which provides the login URL. Open this URL in a browser, where the user can log in using their username/password.finalizeLogin
.credentialsProvider.getCredentials
to obtain a token for activities like API calls.credentialsProvider.getCredentials
. This is sufficient unless the user actively logs out or a token is revoked (e.g., due to a password change).⚠️ Ensure to invoke
credentialsProvider.getCredentials
each time you need a token and avoid storing it. This approach enables the SDK to manage timeouts, upgrades, or automatic retries seamlessly.
(Only available for TIDAL internally developed applications for now)
For devices with limited input capabilities, such as TVs, an alternative login method is provided. Follow these steps or refer to our example for "device login".
init
function.initializeDeviceLogin
and await the response.userCode
and a verificationUri
; display these to the user.link.tidal.com
, log in, and enter the displayed code.finalizeDeviceLogin
, which will continually poll the backend until the user successfully enters the code. Upon a successful promise return, you are ready to proceed..credentialsProvider.getCredentials
.💡 Many modern apps feature a QR-Code for scanning, which you can also generate. Ensure it includes
verificationUriComplete
, as provided in the response.
If your application was previously authenticated, you can migrate these credentials into the auth module by following these steps or checking out our example for "setting credentials".
init
with the same clientId
, etc., used for your previously authenticated user.setCredentials
by providing the accessToken and refreshToken.credentialsProvider.getCredentials
to obtain credentials containing a token
.You can find examples in /examples
, each one is dedicated to one type of receiving credentials.
Some examples needs a proxy to run, but there is one configured if you use pnpm dev
.
Heads up! Redirect login flow requires a secure context and valid https url to work properly.
For the examples to work you might need to build the library once with pnpm build
.
All public methods are documented and described. Please also have a look at the examples since they should document most use cases.
Run pnpm i
in the auth root folder.
pnpm run test:dev
runs vitest in watch mode.