Uploaded by BlackSoft Co

OAuth Documentation (1)

advertisement
OAuth Documentation
Enable APIs for your project
Any application that calls Google APIs needs to enable those APIs in the API Console.
To enable an API for your project:
1. Open the API Library in the Google API Console.
2. If prompted, select a project, or create a new one.
3. The API Library lists all available APIs, grouped by product family and popularity.
If the API you want to enable isn't visible in the list, use search to find it, or click
View All in the product family it belongs to.
4. Select the API you want to enable, then click the Enable button.
5. If prompted, enable billing.
6. If prompted, read and accept the API's Terms of Service.
Once activated it will look like this.
First, we create OAuth Consent Screen
1)
2)
3)
4)
5)
Choose a name ex “gmailapp”
Under user support mail we choose our email ex: “testre296@gmail.com”
If we want we can fill the app domain and privacy page for google verification
Under developer contact information we add also our email “testre296@gmail.com”
Save and continue
On the scopes page we click add or remove scopes and will add 2 scopes
1) ./auth/gmail.modify
2) ./auth/gmail.compose
Create authorization credentials
Any application that uses OAuth 2.0 to access Google APIs must have authorization
credentials that identify the application to Google's OAuth 2.0 server. The following
steps explain how to create credentials for your project. Your applications can then use
the credentials to access APIs that you have enabled for that project.
1.
2.
3.
4.
Go to the Credentials page.
Click Create credentials > OAuth client ID.
Select the Desktop Application type.
After creating your credentials, download the client_secret.json file from the API
Console. Securely store the file in a location that only your application can
access.
Downloaded json will look like this.
We will save it inside the project with the filename “credentials.json” under
GoogleAuth\Settings Directory.
A new empty JSON File OAuthToken.json that will be used to store credentials for later use so
the app doesn’t do auth every time but uses a refresh token to handle everything.
After oauth2 the file will have all the necessary properties that need to handle all google
operations.
{
"access_token": "ya29.A0ARrdaM8jYCgygToFjbgHe5yTMf3qjvDGsoPtfB6wmGV2dBhFBrFRB76RJo4whNQxzyagZSadE-D-pmLjcGoIFjAH4vSJMpy3PguwGY_2rtEV2fa6C_ab2tbK4JsurtPEXySv00NxwjW9VnaqZVg-EGPFiQ",
"expires_in": 3599,
"refresh_token": "1//09_d_RRxCKGfHCgYIARAAGAkSNwF-L9IrLafVFZN4DKqqQgkZLwXN10yueACS-syVVLaoCfBKivdihVMDiaQ8dKT8VxxbA5piyM",
"scope": "https://www.googleapis.com/auth/gmail.send",
"token_type": "Bearer",
"GeneratedTime": "2022-04-24T22:37:37.5848936+02:00"
}
Note: Don't forget to put also the email in Pic/EmailOfTheSiteOwner.txt
ex:(testre296@gmail.com)
Download