goauth2client

package module
v0.0.0-...-73ad786 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2024 License: MIT Imports: 8 Imported by: 0

README

goauth2client

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateState

func GenerateState() string

GenerateState generates a state to be supplied in an auth request and to be tested against in the response. It is generated from 20 random bytes, encoded to base64.

Types

type AuthCallbackFunc

type AuthCallbackFunc func(*Response, error)

type AuthConfig

type AuthConfig struct {
	ClientID     string
	ClientSecret string
}

type Client

type Client struct {
	Config *ClientConfig
	Auth   *AuthConfig

	AuthCallback AuthCallbackFunc
	// contains filtered or unexported fields
}

func New

func New(clientConfig *ClientConfig, authConfig *AuthConfig, authCallback AuthCallbackFunc, httpClient *http.Client) *Client

func (*Client) BuildAuthURL

func (cl *Client) BuildAuthURL() string

BuildAuthURL builds the URL to navigate to in order to initialize the auth process.

func (*Client) HandleAuthInit

func (cl *Client) HandleAuthInit(w http.ResponseWriter, r *http.Request)

HandleAuthInit shows a very barebone page with a link to start the authentication process. Alternatively, use auth URL from cl.BuildAuthURL() and redirect to it programmatically.

func (*Client) HandleCallback

func (cl *Client) HandleCallback(w http.ResponseWriter, r *http.Request)

HandleCallback handles the returning *http.Request from the Auth server. it will call the AuthCallbackFunc initially supplied with the response data, once validated.

type ClientConfig

type ClientConfig struct {
	AuthServerURL       string
	AuthServerAuthPath  string
	AuthServerTokenPath string

	LocalServerURL          string
	LocalServerRedirectPath string

	Scope string
	State string
}

func (*ClientConfig) IsValid

func (c *ClientConfig) IsValid() bool

type Response

type Response struct {
	AccessToken      string `json:"access_token"`
	TokenType        string `json:"token_type"`
	ExpiresIn        uint64 `json:"expires_in"`
	Scope            string `json:"scope"`
	RefreshToken     string `json:"refresh_token"`
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

Jump to

Keyboard shortcuts

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