credentials

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyClientID     = NewOauth2Error("clientId is empty")
	EmptyClientSecret = NewOauth2Error("clientSecret is empty")
	EmptyBaseURL      = NewOauth2Error("baseURL is empty")
)

Functions

func DefaultPrompt

func DefaultPrompt() (string, string, error)

DefaultPrompt is a default implementation of the user prompt function.

func OauthRedirectHandler

func OauthRedirectHandler(w http.ResponseWriter, r *http.Request)

Types

type AccessToken

type AccessToken struct {
	// AccessToken is the actual access token issued by the authorization server.
	AccessToken string `json:"access_token"`
	// ExpiresIn is the duration in seconds for which the access token is valid.
	ExpiresIn int `json:"expires_in"`
	// ExpiresAt is the time at which the access token expires.
	ExpiresAt time.Time
	// RefreshToken is an optional token used to obtain a new access token without requiring reauthorization.
	RefreshToken string `json:"refresh_token"`
	// Scope is a space-delimited list of permissions or access rights granted by the token.
	Scope string `json:"scope"`
	// TokenType is the type of token, usually "Bearer" for OAuth2 access tokens.
	TokenType string `json:"token_type"`
}

AccessToken represents an OAuth2 access token and associated metadata.

func (*AccessToken) IsExpired

func (t *AccessToken) IsExpired() bool

IsExpired Checks if the access token is expired

type Credential

type Credential struct {
}

type CredentialError

type CredentialError struct {
	// Message is the error message associated with the credential error.
	Message string
}

CredentialError represents an error related to credentials or authentication.

func NewCredentialError

func NewCredentialError(message string) *CredentialError

NewCredentialError creates a new CredentialError with the specified error message.

func (*CredentialError) Error

func (e *CredentialError) Error() string

Error returns the error message associated with the CredentialError.

type HTTPServer

type HTTPServer struct {
	// contains filtered or unexported fields
}

HTTPServer represents an HTTP server for OAuth2 redirection.

func NewHTTPServer

func NewHTTPServer(address string) *HTTPServer

NewHTTPServer creates a new HTTP Server

func (*HTTPServer) Start

func (s *HTTPServer) Start()

Start starts the HTTP Server

func (*HTTPServer) Stop

func (s *HTTPServer) Stop()

Stop stops the HTTP Server

type Oauth2Error

type Oauth2Error struct {
	CredentialError
}

Oauth2Error represents an error related to OAuth2 authentication and extends CredentialError.

func NewOauth2Error

func NewOauth2Error(message string) *Oauth2Error

NewOauth2Error creates a new Oauth2Error with the specified error message.

type TokenCredential

type TokenCredential struct {
	ClientID     string
	ClientSecret string
	Token        *AccessToken
	BaseURL      string
	Prompt       func() (string, string, error)
	// contains filtered or unexported fields
}

TokenCredential represents the OAuth2 token credentials.

func NewTokenCredential

func NewTokenCredential(clientID, clientSecret, baseURL string, prompt func() (string, string, error)) (*TokenCredential, error)

NewTokenCredential creates a new token credential

func (*TokenCredential) GetAuthentication

func (tc *TokenCredential) GetAuthentication() (string, error)

GetAuthentication gets the authentication header value

func (*TokenCredential) GetOauth2Url

func (tc *TokenCredential) GetOauth2Url() string

type UsernamePasswordCredential

type UsernamePasswordCredential struct {
	Username string
	Password string
}

func NewUsernamePasswordCredential

func NewUsernamePasswordCredential(username, password string) *UsernamePasswordCredential

NewUsernamePasswordCredential creates a new instance of UsernamePasswordCredential. It accepts the username and password as parameters and returns a pointer to the created UsernamePasswordCredential.

func (*UsernamePasswordCredential) BasicAuth

func (c *UsernamePasswordCredential) BasicAuth(username, password string) string

BasicAuth returns a Basic Authentication string based on the provided username and password. The function combines the username and password with a colon and encodes the result using base64. It returns the encoded Basic Authentication string.

func (*UsernamePasswordCredential) GetAuthentication

func (c *UsernamePasswordCredential) GetAuthentication() (string, error)

GetAuthentication returns the authentication string for UsernamePasswordCredential. It uses the BasicAuth method from the underlying Credential to generate the encoded authentication string. It returns the authentication string in the format "Basic <encoded-auth-string>".

Jump to

Keyboard shortcuts

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