googleauth

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

README

googleauth

This directory contains support code that can be used to get an OAuth2 token for a Google API user.

It is designed to work on computers with attached displays. Use it to write command-line tools and test programs that call Google APIs.

Instructions

Import this package and make the following call to request a token.

client, err := googleauth.NewOAuth2Client(scopes)

scopes should be a string containing the OAuth scopes needed by the APIs to be called. For example, the URL Shortener API would require "https://www.googleapis.com/auth/urlshortener".

This call will then open a local browser that will redirect to a Google signin page with information about the app that is requesting a token.

Application Credentials

To use this package, you need to download a "client secrets" file and save it as client_secrets.json in the directory where your tool is run.

To get this file, visit the {{ Google Cloud Console }}{{ https://cloud.google.com/console }} and create a project. Then go to the API Manager to enable the APIs that you want to use and create OAuth2 credentials. You'll then be able to download these credentials as JSON. Save this file as client_secrets.json

For more information about the client_secrets.json file format, please visit: https://developers.google.com/api-client-library/python/guide/aaa_client_secrets

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOAuth2Client

func NewOAuth2Client(scopes ...string) (*http.Client, error)

NewOAuth2Client takes the user through the three-legged OAuth flow. It opens a browser in the native OS or outputs a URL, then blocks until the redirect completes to the /oauth2callback URI. It returns an instance of an HTTP client that can be passed to the constructor of an OAuth client. scopes is a variable number of OAuth scopes

func NewOAuth2TokenSource

func NewOAuth2TokenSource(scopes ...string) (oauth2.TokenSource, error)

NewOAuth2TokenSource takes the user through the three-legged OAuth flow. It opens a browser in the native OS or outputs a URL, then blocks until the redirect completes to the /oauth2callback URI. It returns an instance of an OAuth token source that can be passed to the constructor of an OAuth client. scopes is a variable number of OAuth scopes

Types

type ClientConfig

type ClientConfig struct {
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	RedirectURIs []string `json:"redirect_uris"`
	AuthURI      string   `json:"auth_uri"`
	TokenURI     string   `json:"token_uri"`
}

ClientConfig is a data structure definition for the client_secrets.json file. The code unmarshals the JSON configuration file into this structure.

type Config

type Config struct {
	Installed ClientConfig `json:"installed"`
	Web       ClientConfig `json:"web"`
}

Config is a root-level configuration object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL