Star (-) Watch (-)

Itcs208-2-2013-projects

Authentication and Authorization

Terminology

  • Authentication means the process of proving of one's identity that it is authentic. For example, a user proves him/herself to a web application by performing the login, providing the username and password.

  • Authorization is an act that specifies access rights to resources for an identity. For example, a user can be granted for only reading a file, but not writing. For the case of YouTube API, an application that use the API may be granted the rights for only read data from YouTube, or user's account information, but not modifying the private information. This granting in YouTube or Google is done by the user who is the account owner.

  • A token is something that represents something else, generally having higher value, such as a coin representing an amount of money. In the case of security, a token may be used to represent a pass of authentication, a result from an authorization. In the case of Google API, after a user grants permissions for an application (authorization), Google generates tokens that represent that authoziation (for the pair of the user and the application), and sends them back to the application. The application can store these tokens somewhere. When the application needs to perform specific actions that need authorization from the user again, it can just present the tokens to Google for verification. If the tokens are valid, Google allows the application to do what it requests according to the permissions having been granted by the user previously. Google now does not ask the user for authorization again. However, if the tokens are not valid, or absent, the user is going to be asked by Google whether he/she wants to grants the permission(s) to the application again.

  • A credential is an item to be used in security, to represent something on behalf of an individual. For example, the username and password are credentials to represent a user. A Google's OAuth token is a credential to represent a set of authorized permissions.

Getting Credentials for the Application

This step is going to get credentials that represent your application. There are many types of applications that can use Google APIs as mentioned here. It assumes that you have already created a project in here already.

Your application can be classified as an installed application, which is neither a web application, client-side application, nor device application. Therefore, when you go to get the credentials (client ID and client secret) by going into your project in Google -> APIs & auth -> Credentials, then click CREATE NEW CLIENT ID and choose "Installed application". You can also consult here.

Then you will see Client ID and Client secret under "Client ID for native application". You can copy these two to replace "Enter ..." in client_secrets.json in the directory resources in here.

Login and Logout

You can use the following Auth class to let your application's users log in and out using their Google accounts. The code with examples is here. You may also find its Java document here.

Libraries Required