I currently still use GAPI for a project that accesses the YouTube Data API with endpoints that require authorization.
Very briefly, this is the current implementation:
- User clicks "Log in with Google" in the frontend
- User can select his YouTube channel (this can either be the main account or any other account where the user is owner, e.g. brand accounts)
- Google returns the code, code is sent to backend, backend exchanges the code for a refresh token and the refresh token is stored for that specific YouTube account.
From then on, authorized requests can be made for that account. Now GAPI is being deprecated in place of Google Identity it separates authentication from authorization.
My problem is: I can only select the main Google Account during both authentication and authorization. I cannot see brand accounts or others channels I am the owner of. However I need to be able to select any of the YouTube accounts.
With GAPI the page for account selection shows "Select an account or brand account" - with Google Identity Services it is just "choose an account".
So now my theory is that I might be able to retrieve and store the refresh token for the main Google Account and then access all YouTube accounts connected to it.
- Is this correct?
If it is:
- When Google wanted to make login more fine granular, not being able to select only a limited number of YouTube accounts seems like a downgrade. Is there any way to counteract this?
- How do I know what YouTube accounts are linked to the main Google Account? It does not help to have access to all accounts, when I don't know which they are.
If it is not: How else can I select a specific YouTube account?
Edit:
Code
Regarding the implementation in the frontend: I use React with @react-oauth/google. You can find a preview of that hosted here which can be cloned from here.
Basically the idea would be to let a user log in to the application using the ID Token flow, which corresponds to the button on the left on the preview page. A logged-in user could then grant permission to any of their YouTube accounts, which would correspond to the "Authorization" button on the right.
To reproduce the problem, create a second YouTube account with your main Google Account. The goal would be to find any way to grant permission to query that account using the YouTube Data API.