Search code examples
javascriptnode.jsoauth-2.0youtube-apigoogle-oauth

OAuth 2.0 token handling. Is there a Server token and client token?


I have a problem understanding the principle handling of oauth 2.0 tokens.

My scenario is, I have a web based frontend backend system with node.js and angular 2. A user should be able upload a video on this site. Then some additional metadata is created (dosen't matter for this question). When that is done, the user could upload the video to youtube with the additional data by clicking on a button.

My question is how many tokens/credentials are there in this process. The youtube api needs an oauth token. Does the user also have its own token?

Here is the tutorial I used: https://ionicabizau.net/blog/14-uploading-videos-to-youtube-using-nodejs

As you can see one token for the API is created for local testing. But is this token generated in a different way in a live version? And how is the user of my website recognized. Also via this token? Or do I have to generate a second token for him?


Solution

  • I am not sure what you mean by 'Token'.

    In order to access any Google API you will first need to register your application on Google Developer console. You will then need to create Oauth2 credentials. Oauth2 credentials is were your application will request access from a user to access the data on their YouTube account.

    On Google Developer console you will need to save the Client id, client secret and the redirect uri. All three will be needed by your code to authenticate the user.

    When the user grants your application access to their YouTube data. You will get an access token and a refresh token back from the authentication server. Access tokens are short lived about an hour and are used to make requests (like upload) to the API. A refresh token can be used to request a new access token once the one you have currently has expired.

    You will probably end up with the following:

    client id, client secrete, redirect uri, and a refresh token.

    If you are interested I have a tutorial that is part of my Google Development for beginners tutorial series that explains Oauth2 and how it works.