A token-based authentication system allows users to enter their username and password in order to obtain a token, which allows them to fetch a specific resource, without using their username and password. Once their token has been obtained, the user can offer the token, which offers access to a specific resource for a time period, to the remote site. This article explains how to generate a Google Services token, step by step, with the needed permissions for the COZYROC REST Connection Manager component. And it explains how to generate a token for the different Google Services.
In order to use the generated token, you need to create a specific XML file, which then needs to be entered into the REST Connection Manager Configuration. To simplify this article, the process has been separated into 4 steps:
1) Generate authorization code and give permission to COZYROC to access your Google Service
2) Create a custom POST request to be sent to the Google server
3) Receive the authorization and refresh token in JSON format so that you can examine the result from the response
4) Create an XML file for the token that complies to the COZYROC token XML format
Step 1: Generate authorization code and give permission to COZYROC to access your Google Service
We have prepared a separate URL for each different Google Service, that is going to be used to grant COZYROC permissions to access your Google Service(Google Drive, Google Tasks, Google Sheets and etc..)
Google Service | URL |
Google Drive | |
Google Tasks | |
Google Analytics | |
Google Calendar | |
Google Sheets | |
GoogleBigQuery | |
For explanation which parameters you need and the value you need for each parameter please look at the table below. Table below shows the parameters and their value for Google Drive token. You will find those parameters and values in the URLS above.
Parameters
| Value
|
client_id
| 822955360540k56u5vu2ssvivg9qno2oisml9322esj.apps.googleusercontent.com
|
redirect_url
| http%3A%2F%2Flocalhost
|
scope
| https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive%20https%3A%2F%2Fwww.
googleapis.com%2Fauth%2Fdrive.readonly%20https%3A%2F%2Fwww.googleapis.com
%2Fauth%2Fdrive.appfolder%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.
file%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.install%20https%3A%2F%2Fwww.
googleapis.com%2Fauth%2Fdrive.metadata%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2F
drive.metadata.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.photos.
readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.scripts
|
access_type
| offline
|
|
|
- Based on what Google Service token you want to create, Click the URL above for the particular Google Service and then the following screen will open:
- Then enter your credentials and you will get the following screen:
- Click the "Allow" button in the above screen to grant permissions to COZYROC to access your Google Service, in our case Google Drive. As a result, a link will be generated, that includes the authorization code that we are going to need in Step 2.
In our case the following link gets generated:
You are going to need the value of the code parameter from the generated URL and, in our case, this value is:
code=4/zgFa2OjKFvuYkxqHDBvGZ9xlp2TEVRJhsA_Kp6s2chwV3fhiImh6o8iUzfyuVlVInWiLJEcEGjAwUcoh7gEL5-0
You can use this code for only a single request and it will expire in 5 minutes or less.
Step 2: Create a custom POST request to be sent to the Google server
In this step, we are going to create a POST URL that needs to be sent to the Google Server. In order to do that, we will be using POSTMAN. You can use any software that will allow you to do that.
In the following table, you can find all the Post request parameters that you are going to need and their values.
Parameter
| Value
| Notes
|
grant_type
| authorization_code
| You should use this value
|
client_id
| 822955360543-0k56u5vu2ssvivg9qno2oisml9322esj.apps.googleusercontent.com
| You should use this value
|
redirect_uri
| http://localhost/
| You should use this value
|
client_secret
| Em0SYyJ09-NgLvhyT2hPOlfY
| You should use this value
|
code
| 4/zgFa2OjKFvuYkxqHDBvGZ9xlp2TEVRJhsA_Kp6s2chwV3fhiImh6o8iUz
fyuVlVInWiLJEcEGjAwUcoh7gEL5-0
| In my case, the Code value will be: 4/zgFa2OjKFvuYkxqHDBv
GZ9xlp2TEVRJhsA_Kp6s2chwV3fhiImh6o8iUz
fyuVlVInWiLJEcEGjAwUcoh7gEL5-0. It will be a different value for you. Please look at the information above.
|
To create a new POST Request by POSTMAN please follow the steps:
- Login to POSTMAN
- Click the button "New" and select "Request" from the dropdown menu. Please look at the screenshot below:
- Enter request name and save your request.
- Open your request, select POST for the Request and enter for URL: "https://oauth2.googleapis.com/token". This is the URL where we are going to send the Post Request. Please look at the screenshot below:
- Click "Body"
- Select "x-www-form-urlencoded
- Enter for Key and Value all the Post request parameters and their values we showed you in the table above. Please look at the screenshot above
- You will also need to set up the Headers as Content-Type = application/x-www-form-urlencoded. Please look at the POSTMAN screenshot below:
- Then click "Send" to send the POST Request
Once you send the Post request you will get a response in JSON format.
Step 3: You will receive the authorization and refresh token in JSON format. You will need to examine the result from the response.
If the operation is successful, you will get a response similar to the following in JSON Format:
{
"access_token": "ya29.a0Ae4lvC1ZqXVJXpwFHVY7-dWu9a1_6HuJQovLf16docSDIU0PThJQ1NgIufBAY2dVqzeYuruc4QVwHpMwY1tuspj4qo2JAQ_8xibmmHTdiDxlk0bNkl2EaJH1l7UcKZUOMdvH8pC9gPKBQU0mahLrHHGsah3VvL7PN3M",
"expires_in": 3599,
"refresh_token": "1//0dFnlTD2PccEjCgYIARAAGA0SNwF-L9IrdAiKWj7zFCGXBNRYywpv_LYL48JTsWCWDGioq216Ao9mCKM36p8anjdtzbnXw0EBde4",
"token_type": "Bearer"
}
If you don't get the response, examine your process for errors and fix them.
We will use the access_token value and the refresh_token values in the next step to create the XML Token File.
Step 4: Create an XML file for the token that complies with the COZYROC token XML format
- Go to your REST Connection Manager and click on it twice; the REST Connection Manager configuration screen will open.
- Select your Google Service for Configuration, in our case this is "Google Drive" . Please look at the screenshot below:
- Click the button "New" to create a new token file.
- Complete all the steps until you get to the third page of the Wizard. Please look at the screenshot below:
- For "Access Token", enter the access_token value from the JSON Response you received above.
- For "Refresh Token", enter the refresh_token value from the JSON Response you received above.
- For "Expiration(UTC):", keep the default Expiration date and time value that was automatically calculated(Current UTC date and time + 50 minutes )
- For "Save Files:", enter the file token name and the file path where you want to save the newly generated Token XML File.
- For "Password:", enter a token password. Please look at the screenshot below:
-
- Click the "OK" button. Your token XML file will be generated. Please look at the screenshot below:
- Click the "Test Connection" button and you should get the message "Test connection succeeded".