Skip to content

Authorization

Kayra Uylar edited this page May 26, 2024 · 4 revisions

Using cookies

Warning

Cookies authentication in 1.x.x is broken, either update to 2.x.x or use refresh tokens

To authenticate using cookies, you will need to extract the following cookies from a browser which is logged in to YouTube.

  • SID
  • HSID
  • SSID
  • APISID
  • SAPISID

After getting the cookies, just set the Authorization field in your InnerTubeConfiguration to InnerTubeAuthorization.SapisidAuthorization("YOUR-SID-COOKIE", "YOUR-HSID-COOKIE", "YOUR-SSID-COOKIE", "YOUR-APISID-COOKIE", "YOUR-SAPISID-COOKIE"), and it should work fine! For an example, you should check this file.

Note

While these cookies have never expired in our tests, its still recommended to use a refresh token instead.

Using a refresh token

Instead of using cookies that can expire, you can just use a refresh token that works just as well. You can get a refresh token by doing some debugger magic on the YouTube TV app.

  1. Visit https://youtube.com/tv
    • You will need to get a TV user agent to access to the app. If your user agent is invalid, you will see this screen: YouTube TV invalid user agent screen
    • You can bypass this message by using a user agent changer extension, and setting your user agent to one of the following:
      • Mozilla/5.0 (AppleTV; CPU OS 13_4_6 like Mac OS X) HW_AppleTV/5.3
      • Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/90.0.4430.212 Large Screen Safari/534.24 GoogleTV/092754
      • Mozilla/5.0 (PlayStation; PlayStation 4/8.50) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Safari/605.1.15
  2. Go to the sign in prompt located in the sidebar YouTube TV sign in prompt
    • At this point, you should get your browser's DevTools up and switch to the network tab. Make sure that this tab is open BEFORE you sign in, and that persist logs is enabled. Sign in prompt with the DevTools open
  3. Follow the instructions on the screen, and look for a new request that goes to https://www.youtube.com/o/oauth2/token. There will be a lot of these, check all of them until one of them looks like the following
    Response of a successful log in
  4. Put the refresh_token from that response inside your InnerTubeConfiguration, like so:
    Code example

If you did all the steps above correctly, you should now be authorized!

Using a refresh token (alternative way)

  1. Open the YouTube TV website as described above
  2. Log in to an account
  3. Run the following JavaScript snippet in your browser's JavaScript console.
JSON.parse(localStorage.getItem("yt.leanback.default::last-identity-used")).data.identityCredentials.refreshToken
  1. Paste the result inside your InnerTubeConfiguration, without quotes, like so:
    Code example
Clone this wiki locally