googleclient

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeProfile = "https://www.googleapis.com/auth/userinfo.profile"
	ScopeEmail   = "https://www.googleapis.com/auth/userinfo.email"
)

Variables

View Source
var (
	DefaultConfig = Config{
		Name:    "",
		Timeout: defaultTimeout,
		Scopes:  []string{ScopeProfile, ScopeEmail},
	}
)

Functions

func NewError

func NewError(resp *http.Response) error

Types

type APIError

type APIError struct {
	Code    int    `json:"code"`
	Status  string `json:"status"`
	Message string `json:"message"`
}

func (APIError) Error

func (e APIError) Error() string

type APIErrors

type APIErrors struct {
	APIError `json:"error"`
}

type Client

type Client struct {
	Name     string
	CacheDir string
	*oauth2.Config
	*url.URL
	*http.Client
}

func NewClientWithClientSecret

func NewClientWithClientSecret(cfg Config, path string) (*Client, error)

Client with client secret

func (*Client) CommandLineAuth

func (client *Client) CommandLineAuth() (*CommandLineAuth, error)

Start device authentication

func (*Client) CommandLineToken

func (client *Client) CommandLineToken(ctx context.Context, code string) (*oauth2.Token, error)

Start device authentication

func (*Client) DeviceAuth

func (client *Client) DeviceAuth() (*DeviceAuth, error)

Start device authentication

func (*Client) DeviceToken

func (client *Client) DeviceToken(ctx context.Context, auth *DeviceAuth) (*oauth2.Token, error)

Wait for user to provide authentication response and return an oauth token

func (*Client) Get

func (client *Client) Get(path string, out interface{}, opts ...ClientOpt) error

Perform a GET with no body

func (*Client) Post

func (client *Client) Post(path string, in, out interface{}, opts ...ClientOpt) error

Perform a POST with a JSON body

func (*Client) PostBinary

func (client *Client) PostBinary(path string, data io.Reader, out interface{}, opts ...ClientOpt) error

Perform POST with a byte stream

func (*Client) ReadToken

func (client *Client) ReadToken() (*oauth2.Token, error)

func (*Client) String

func (client *Client) String() string

func (*Client) Use

func (client *Client) Use(ctx context.Context, token *oauth2.Token, endpoint string) error

Use a token and endpoint for communication, refresh token when necessary, etc

func (*Client) WriteToken

func (client *Client) WriteToken(token *oauth2.Token) error

type ClientOpt

type ClientOpt func(url.Values, *http.Request) ClientOptDone

func OptHeader

func OptHeader(key, value string) ClientOpt

type ClientOptDone

type ClientOptDone func(interface{})

type CommandLineAuth

type CommandLineAuth struct {
	VerificationURL string `json:"verification_url"`
}

type Config

type Config struct {
	Name      string        `yaml:"name"`      // Path to application name
	ConfigDir string        `yaml:"configdir"` // Path to configuration path
	CacheDir  string        `yaml:"cachedir"`  // Path to cache path
	Scopes    []string      `yaml:"scopes"`    // Scopes for read, write and share
	Timeout   time.Duration `yaml:"timeout"`   // Client timeout
}

type DeviceAuth

type DeviceAuth struct {
	DeviceCode      string `json:"device_code"`
	UserCode        string `json:"user_code"`
	VerificationURL string `json:"verification_url"`
	ExpiresIn       int64  `json:"expires_in"`
	Interval        int64  `json:"interval"`
	// contains filtered or unexported fields
}

func (*DeviceAuth) ExpiryTime

func (code *DeviceAuth) ExpiryTime() time.Time

type OAuthError

type OAuthError struct {
	Status  string `json:"error"`
	Message string `json:"error_description"`
}

func (OAuthError) Error

func (e OAuthError) Error() string

Jump to

Keyboard shortcuts

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