Documentation
¶
Index ¶
- Variables
- func ExecuteOAuth2BrowserTokenFlow(ctx context.Context, conf *oauth2.Config) (*oauth2.Token, error)
- func NewBrowserFlowTokenSource(ctx context.Context, conf *oauth2.Config) (oauth2.TokenSource, error)
- func NewCachedTokenSource(ctx context.Context, cacheName string, store TokenStore, ...) (oauth2.TokenSource, error)
- func NewClient(configer ...ClientOption) (*http.Client, error)
- type ClientOption
- type TokenStore
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrMissingScopes = errors.New("missing scopes")
Functions ¶
func NewCachedTokenSource ¶
func NewCachedTokenSource(ctx context.Context, cacheName string, store TokenStore, source oauth2.TokenSource) (oauth2.TokenSource, error)
func NewClient ¶
func NewClient(configer ...ClientOption) (*http.Client, error)
Example ¶
scopes := []string{"openid", "profile"} client, err := NewClient(WithClientSecretsFile(clientSecretsPath, scopes), WithFileTokenStore()) if err != nil { log.Fatal(err) } res, err := client.Get("https://www.googleapis.com/oauth2/v1/userinfo?alt=json") defer res.Body.Close() if err != nil { log.Fatal(err) } data, err := io.ReadAll(res.Body) if err != nil { log.Fatal(err) } fmt.Println(string(data))
Output:
Types ¶
type ClientOption ¶
type ClientOption func(c *config) error
func FailOnMissingScopes ¶
func FailOnMissingScopes(doFail bool) ClientOption
func WithClientSecretsFile ¶
func WithClientSecretsFile(filepath string, scopes []string) ClientOption
func WithConfig ¶
func WithConfig(conf *oauth2.Config) ClientOption
func WithFileTokenStore ¶
func WithFileTokenStore() ClientOption
func WithTokenStore ¶
func WithTokenStore(t TokenStore) ClientOption
Click to show internal directories.
Click to hide internal directories.