Documentation ¶
Overview ¶
Package auth provides general Google authentication implementation agnostic to what specific Google services or resources are used. Implementations in this package generate a https://pkg.golang.ir/net/http#Client that can be used to access Google REST APIs seamlessly. Authentications will be handled automatically, including refreshing the access token when necessary.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OAuth2 ¶
type OAuth2 struct {
// contains filtered or unexported fields
}
OAuth2 takes in OAuth2 relevant information and sets up *http.Client that can be used to access Google APIs seamlessly. Authentications will be handled automatically, including refreshing the access token when necessary.
func NewOAuth2FromFile ¶
func NewOAuth2FromFile(secretFilePath string, credsFilePath string, scopes Scopes, config OAuth2Config) (*OAuth2, error)
NewOAuth2FromFile creates an OAuth2 instance by reading the OAuth2 related information from a secret file.
The "secretFilePath" is referring to the OAuth2 credentials JSON file that can be obtained by creating a new OAuth2 credentials in https://console.cloud.google.com/apis/credentials. You can put any link for the redirection URL field.
The "credsFilePath" is referring to a file where the generated access and refresh token will be cached. This file will be created automatically once the OAuth2 authentication is successful.
The "scopes" tells Google what your application can do to your spreadsheets.
Note that since this is an OAuth2 server flow, human interaction will be needed for the very first authentication. During the OAuth2 flow, you will be asked to click a generated URL in the terminal.
func (*OAuth2) HTTPClient ¶
HTTPClient returns a Google OAuth2 authenticated *http.Client that can be used to access Google APIs.
type OAuth2Config ¶
type OAuth2Config struct { // HTTPClient allows the client to customise the HTTP client used to perform the REST API calls. // This will be useful if you want to have a more granular control over the HTTP client (e.g. using a connection pool). HTTPClient *http.Client }
OAuth2Config defines a list of configurations that can be used to customise how the Google OAuth2 flow works.
type Scopes ¶
type Scopes []string
Scopes encapsulates a list of Google resources scopes to request during authentication step.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service takes in service account relevant information and sets up *http.Client that can be used to access Google APIs seamlessly. Authentications will be handled automatically, including refreshing the access token when necessary.
func NewServiceFromFile ¶
func NewServiceFromFile(filePath string, scopes Scopes, config ServiceConfig) (*Service, error)
NewServiceFromFile creates a Service instance by reading the Google service account related information from a file.
The "filePath" is referring to the service account JSON file that can be obtained by creating a new service account credentials in https://developers.google.com/identity/protocols/oauth2/service-account#creatinganaccount.
The "scopes" tells Google what your application can do to your spreadsheets.
func NewServiceFromJSON ¶
func NewServiceFromJSON(raw []byte, scopes Scopes, config ServiceConfig) (*Service, error)
NewServiceFromJSON works exactly the same as NewServiceFromFile, but instead of reading from a file, the raw content of the Google service account JSON file is provided directly.
func (*Service) HTTPClient ¶
HTTPClient returns a Google OAuth2 authenticated *http.Client that can be used to access Google APIs.
type ServiceConfig ¶
type ServiceConfig struct { // HTTPClient allows the client to customise the HTTP client used to perform the REST API calls. // This will be useful if you want to have a more granular control over the HTTP client (e.g. using a connection pool). HTTPClient *http.Client }
ServiceConfig defines a list of configurations that can be used to customise how the Google service account authentication flow works.