oauth

package
v0.0.0-...-ed5f25b Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: Apache-2.0 Imports: 9 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorResponse

type ErrorResponse struct {
	Error       string `json:"error"`
	Description string `json:"error_description"`
	StatusCode  int    `json:"-"`
}

ErrorResponse repsents a failed response

type HttpClientFactory

type HttpClientFactory func() *http.Client

type OauthClient

type OauthClient struct {
	Service         string
	Client          *http.Client
	Headers         map[string]string
	ClientID        string
	ClientSecret    string
	SourceHeader    string
	ResponseHeaders http.Header
}

OauthClient represents a stateful Oauth client

func GetNewClient

func GetNewClient(service string, httpFactory HttpClientFactory) (*OauthClient, error)

GetNewClient creates a new client for the specified endpoint

func GetNewConfidentialClient

func GetNewConfidentialClient(service string, clientID string, clientSecret string, httpFactory HttpClientFactory) (*OauthClient, error)

GetNewConfidentialClient creates a new client for the specified endpoint

func (*OauthClient) ClientCredentials

func (c *OauthClient) ClientCredentials(appID string, scope string) (*TokenResponse, *ErrorResponse, error)

func (*OauthClient) GetLastResponseHeaders

func (c *OauthClient) GetLastResponseHeaders() http.Header

GetLastResponseHeaders returns the response header for the previous REST call

func (*OauthClient) RefreshToken

func (c *OauthClient) RefreshToken(appID string, refreshToken string) (*TokenResponse, *ErrorResponse, error)

func (*OauthClient) ResourceOwner

func (c *OauthClient) ResourceOwner(appID string, scope string, owner string, ownerPassword string) (*TokenResponse, *ErrorResponse, error)

ResourceOwner implements the ResourceOwner flow

type OauthConfig

type OauthConfig struct {
	ClientID     string   `json:"clientID" structs:"clientID" mapstructure:"clientID"`
	ClientSecret string   `json:"clientSecret" structs:"clientSecret" mapstructure:"clientSecret"`
	ServiceURL   string   `json:"serviceUrl" structs:"serviceUrl" mapstructure:"serviceUrl"`
	AppID        string   `json:"appID" structs:"appID" mapstructure:"appID"`
	Scope        string   `json:"scope,omitempty" structs:"scope" mapstructure:"scope"`
	Policies     []string `json:"policies,omitempty" structs:"policies" mapstructure:"policies"`
}

OauthConfig represents configuration used to create Oauth clients

func GetConfig

func GetConfig(configPath string) (*OauthConfig, error)

GetConfig reads config from a file specified as arg or from the environment

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
}

TokenResponse represents successful token response

Jump to

Keyboard shortcuts

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