oauth

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

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"`
}

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
	AppID           string
	Scope           string
	Token           string
	SkipCertVerify  bool
}

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) GetClient

func (c *OauthClient) GetClient() (*restapi.RestClient, error)

GetClient creates REST client

func (*OauthClient) GetLastResponseHeaders

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

GetLastResponseHeaders returns the response header for the previous REST call

func (*OauthClient) GetOauthToken

func (c *OauthClient) GetOauthToken() (*TokenResponse, error)

GetOauthToken obtains OAuth token string

func (*OauthClient) GetRestClient

func (c *OauthClient) GetRestClient(token *TokenResponse) (*restapi.RestClient, error)

GetRestClient returns rest client directly with oauth token

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"`
	SkipCertVerify bool     `json:"skipCertVerify,omitempty" structs:"skipCertVerify" mapstructure:"skipCertVerify"`
}

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