Documentation ¶
Overview ¶
Package oauth2 implements helper functions for implementing OAuth2 Applications for provider.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetHTTPClient ¶
func GetHTTPClient(ctx context.Context, credentialsLoaders []config.CredentialsLoader) (*http.Client, error)
GetHTTPClient returns an authenticated HTTP client that always injects a valid token.
Example (Default) ¶
This example demonstrates how to create an authenticated http client and use it call the Knowledge API.
credentialsLoaders = append(credentialsLoaders, apicfg.DefaultEnvironmentLoader) client, err := oauth2.GetHTTPClient(context.Background(), credentialsLoaders) if err != nil { log.Fatalf("failed to generate token source %v", err) } resp, err := client.Get("indykite.com") if err != nil { log.Fatalf("unable to fetch url") } fmt.Println(resp.Body)
Output:
func GetRefreshableTokenSource ¶
func GetRefreshableTokenSource( ctx context.Context, credentialsLoaders []config.CredentialsLoader, ) (oauth2.TokenSource, error)
GetRefreshableTokenSource Token returns a token or an error. Token must be safe for concurrent use by multiple goroutines. The returned Token must not be modified.
Example (Default) ¶
This example demonstrates how to generate a token.
credentialsLoaders = append(credentialsLoaders, apicfg.DefaultEnvironmentLoader) tokenSource, err := oauth2.GetRefreshableTokenSource(context.Background(), credentialsLoaders) if err != nil { log.Fatalf("failed to generate token source %v", err) } token, err := tokenSource.Token() if err != nil { log.Fatalf("failed to get token from tokenSource %v", err) } if token.Type() != "Bearer" { log.Fatalf("unsupported token type, must be 'Bearer' but got %s", token.Type()) } fmt.Println(token.AccessToken)
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.