config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package config provides configuration management for the PingOne Go Client SDK. It handles service configuration, environment variable parsing, OAuth2 credential management, and endpoint configuration for connecting to PingOne services across different regions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	// Auth contains authentication-related configuration including client credentials and grant types.
	Auth struct {
		ClientID     *string              `envconfig:"PINGONE_CLIENT_ID" json:"clientId,omitempty"`
		ClientSecret *string              `envconfig:"PINGONE_CLIENT_SECRET" json:"clientSecret,omitempty"`
		AccessToken  *string              `envconfig:"PINGONE_API_ACCESS_TOKEN" json:"accessToken,omitempty"`
		GrantType    *svcOAuth2.GrantType `envconfig:"PINGONE_AUTH_GRANT_TYPE" json:"grantType,omitempty"`
	} `json:"auth"`
	// Endpoint contains endpoint configuration for API and authentication domains.
	Endpoint struct {
		AuthEnvironmentID *string `envconfig:"PINGONE_ENVIRONMENT_ID" json:"environmentId,omitempty"`
		TopLevelDomain    *string `envconfig:"PINGONE_TOP_LEVEL_DOMAIN" json:"topLevelDomain,omitempty"`
		RootDomain        *string `envconfig:"PINGONE_ROOT_DOMAIN" json:"rootDomain,omitempty"`
		APIDomain         *string `envconfig:"PINGONE_API_DOMAIN" json:"apiDomain,omitempty"`
		CustomDomain      *string `envconfig:"PINGONE_CUSTOM_DOMAIN" json:"customDomain,omitempty"`
	} `json:"endpoint"`
}

Configuration represents the complete configuration for the PingOne Go Client SDK. It contains authentication settings and endpoint configuration for connecting to PingOne services. The configuration can be populated from environment variables or set explicitly through the builder methods.

func NewConfiguration

func NewConfiguration() *Configuration

NewConfiguration creates a new Configuration instance with default values. This configuration must be populated with authentication credentials and endpoint information before it can be used to create API clients. Use the builder methods (With...) to set the required configuration values.

func (*Configuration) APIDomain

func (c *Configuration) APIDomain() (string, error)

APIDomain constructs the API domain for PingOne service calls. It returns a string containing the complete API domain based on the configured domain settings. The method prioritizes explicit API domain configuration over root domain and top-level domain settings. It returns an error if no valid domain configuration can be determined from the current settings.

func (*Configuration) AddBearerTokenToContext

func (c *Configuration) AddBearerTokenToContext(parent context.Context, key any) context.Context

AddBearerTokenToContext adds the configured access token to a context. The parent parameter is the base context to extend, and key is the context key to use for storing the token value. It returns a new context with the token value if a token is configured, or the original context if no token is set.

func (*Configuration) AuthEndpoints

func (c *Configuration) AuthEndpoints() (endpoints.OIDCEndpoint, error)

AuthEndpoints constructs the OAuth2 and OIDC endpoints for authentication. It returns an OIDCEndpoint struct containing the authorization, token, and userinfo URLs based on the configured domain settings. The method prioritizes custom domain over environment-specific domains. It returns an error if no valid endpoint configuration can be determined from the current settings.

func (*Configuration) BearerToken

func (c *Configuration) BearerToken() *oauth2.Token

BearerToken creates an OAuth2 token from the configured access token. It returns a pointer to an OAuth2 token with the access token and "Bearer" token type. This method assumes an access token has been configured; call HasBearerToken first to verify a token is available.

func (*Configuration) Client

func (c *Configuration) Client(ctx context.Context, httpClient *http.Client) (*http.Client, error)

Client creates an HTTP client configured for PingOne API authentication. The ctx parameter provides the context for the OAuth2 token source operations. The httpClient parameter is the base HTTP client to use for requests; if nil, a default client will be used. It returns an HTTP client that automatically handles authentication token management, or an error if token source creation fails.

func (*Configuration) HasBearerToken

func (c *Configuration) HasBearerToken() bool

HasBearerToken checks if a static access token is configured. It returns true if an access token has been set and is not empty, false otherwise. This is used to determine whether to use static token authentication or OAuth2 flows.

func (*Configuration) TokenSource

func (c *Configuration) TokenSource(ctx context.Context) (*oauth2.TokenSource, error)

TokenSource creates an OAuth2 token source based on the configured authentication method. The ctx parameter provides the context for OAuth2 operations. It returns a token source that can be used to obtain access tokens, or an error if the configuration is invalid or incomplete. If a static access token is configured, it returns a static token source. Otherwise, it creates a token source appropriate for the configured grant type.

func (*Configuration) WithAPIDomain

func (c *Configuration) WithAPIDomain(apiDomain string) *Configuration

WithAPIDomain sets a custom API domain for PingOne services. The apiDomain parameter should be a complete API domain like "api.pingone.com". When set, this overrides automatic domain construction from other domain settings.

func (*Configuration) WithAccessToken

func (c *Configuration) WithAccessToken(accessToken string) *Configuration

WithAccessToken sets a static access token for API authentication. The accessToken parameter must be a valid PingOne API access token. When set, this bypasses OAuth2 flows and uses the provided token directly.

func (*Configuration) WithAuthEnvironmentID

func (c *Configuration) WithAuthEnvironmentID(environmentID string) *Configuration

WithAuthEnvironmentID sets the PingOne environment ID for authentication. The environmentID parameter must be a valid PingOne environment UUID string. This environment ID is used to construct the OAuth2 authentication endpoints.

func (*Configuration) WithClientID

func (c *Configuration) WithClientID(clientID string) *Configuration

WithClientID sets the OAuth2 client ID for authentication. The clientID parameter must be a valid client ID from a PingOne application. This is required when using client credentials grant type authentication.

func (*Configuration) WithClientSecret

func (c *Configuration) WithClientSecret(clientSecret string) *Configuration

WithClientSecret sets the OAuth2 client secret for authentication. The clientSecret parameter must be the secret associated with the configured client ID. This is required when using client credentials grant type with client secret authentication.

func (*Configuration) WithCustomDomain

func (c *Configuration) WithCustomDomain(customDomain string) *Configuration

WithCustomDomain sets a custom domain for PingOne authentication services. The customDomain parameter should be a complete custom domain configured in PingOne. When set, this takes precedence over all other domain configuration methods.

func (*Configuration) WithGrantType

func (c *Configuration) WithGrantType(grantType svcOAuth2.GrantType) *Configuration

WithGrantType sets the OAuth2 grant type for authentication. The grantType parameter specifies which OAuth2 flow to use for token acquisition. Currently supported grant types are defined in the oauth2 package.

func (*Configuration) WithRootDomain

func (c *Configuration) WithRootDomain(rootDomain string) *Configuration

WithRootDomain sets the root domain for PingOne services. The rootDomain parameter should be a complete domain like "pingone.com" or "pingone.eu". This takes precedence over top-level domain configuration when constructing endpoints.

func (*Configuration) WithTopLevelDomain

func (c *Configuration) WithTopLevelDomain(tld string) *Configuration

WithTopLevelDomain sets the top-level domain for PingOne services. The tld parameter should be a domain suffix like "com", "eu", or "asia". This is used to construct service endpoints for different PingOne regions.

Jump to

Keyboard shortcuts

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