| 1 | # googleauth |
| 2 | |
| 3 | This directory contains support code that can be used to get an OAuth2 token for a Google API user. |
| 4 | |
| 5 | It is designed to work on computers with attached displays. |
| 6 | Use it to write command-line tools and test programs that call Google APIs. |
| 7 | |
| 8 | ## Instructions |
| 9 | |
| 10 | Import this package and make the following call to request a token. |
| 11 | |
| 12 | client, err := googleauth.NewOAuth2Client(scopes) |
| 13 | |
| 14 | `scopes` should be a string containing the OAuth scopes needed by the APIs to be called. |
| 15 | For example, the URL Shortener API would require "https://www.googleapis.com/auth/urlshortener". |
| 16 | |
| 17 | This call will then open a local browser that will redirect to a Google signin page |
| 18 | with information about the app that is requesting a token. |
| 19 | |
| 20 | ## Application Credentials |
| 21 | |
| 22 | To use this package, you need to download a "client secrets" file and |
| 23 | save it as `client_secrets.json` in the directory where your tool is run. |
| 24 | |
| 25 | To get this file, visit the {{ Google Cloud Console }}{{ https://cloud.google.com/console }} |
| 26 | and create a project. Then go to the API Manager to enable the APIs that you want to use |
| 27 | and create OAuth2 credentials. You'll then be able to download these credentials |
| 28 | as JSON. Save this file as `client_secrets.json` |
| 29 | |
| 30 | For more information about the `client_secrets.json` file format, please visit: |
| 31 | https://developers.google.com/api-client-library/python/guide/aaa_client_secrets |