client

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Introspect

func Introspect(endpoint string) func(string, TokenType) (*TokenInfo, error)

Introspect returns the token introspection response

func NewClientCredentialsClient

func NewClientCredentialsClient(ctx context.Context, cfg ClientCredentialsConfig) *http.Client

NewClientCredentialsClient creates a new OAuth2 client that supports the client_credentials grant type

Types

type Client

type Client interface {
	Introspect(ctx context.Context, token string, tokenType TokenType) (*TokenInfo, error)
}

func NewClient

func NewClient(opts ...ClientOption) Client

NewClient returns a new Client.

type ClientCredentialsConfig

type ClientCredentialsConfig struct {
	ClientID     string
	ClientSecret string
	TokenURL     string
	Scopes       []string
}

ClientCredentialsConfig represents the configuration for the client_credentials grant type

type ClientOption

type ClientOption func(*client)

ClientOption is a function that configures a Client.

func SetClientAPIEndpoint

func SetClientAPIEndpoint(endpoint string) ClientOption

SetClientAPIEndpoint sets the endpoint for the Client API.

func SetHTTPClient

func SetHTTPClient(httpClient *http.Client) ClientOption

SetHTTPClient sets the HTTP client to use for requests.

func SetIntrospectEndpoint

func SetIntrospectEndpoint(endpoint string) ClientOption

SetIntrospectEndpoint sets the endpoint for the Introspect API.

func SetUserAPIEndpoint

func SetUserAPIEndpoint(endpoint string) ClientOption

SetUserAPIEndpoint sets the endpoint for the User API.

type ErrorResponse

type ErrorResponse struct {
	Code      int         `json:"code"`
	Err       string      `json:"error"`
	Message   string      `json:"message,omitempty"`
	Details   interface{} `json:"details,omitempty"`
	RequestID string      `json:"request_id,omitempty"`
}

ErrorResponse is a struct that contains an error message.

func (ErrorResponse) Error

func (e ErrorResponse) Error() string

Error implements the error interface.

type TokenInfo

type TokenInfo struct {
	Active    bool   `json:"active"`
	Scope     string `json:"scope,omitempty"`
	ClientID  string `json:"client_id,omitempty"`
	UserID    string `json:"user_id,omitempty"`
	TokenType string `json:"token_type,omitempty"`
	ExpiresAt int64  `json:"exp,omitempty"`
	IssuedAt  int64  `json:"iat,omitempty"`
	NotBefore int64  `json:"nbf,omitempty"`
	Subject   string `json:"sub,omitempty"`
	Audience  string `json:"aud,omitempty"`
	Issuer    string `json:"iss,omitempty"`
	TokenID   string `json:"jti,omitempty"`
}

TokenInfo is a struct that contains information about a token.

type TokenType

type TokenType string

TokenType is a type of token.

const (
	TokenTypeAccessToken  TokenType = "access_token"
	TokenTypeRefreshToken TokenType = "refresh_token"
)

Token types.

Jump to

Keyboard shortcuts

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