Documentation
¶
Index ¶
- Constants
- func Content(body string) functional.OptionWithError[HttpResponse]
- func ContentTypeUrlFormEncoded() map[string]string
- func CreateHttpClient(timeoutInS uint64, certAuth *tls.CertificateAuthentication) (http.Client, error)
- func Headers(headers http.Header) functional.OptionWithError[HttpResponse]
- func IsSuccessfulBasedOnSuccessResponseCodes(statusCode int, successResponseCodes []string) functional.OptionWithError[HttpResponse]
- func Method(method string) functional.OptionWithError[HttpResponse]
- func StatusCode(code int) functional.OptionWithError[HttpResponse]
- func Time(time int64) functional.OptionWithError[HttpResponse]
- func Url(url string) functional.OptionWithError[HttpResponse]
- func UseCertificateAuthentication(certAuthentication *tls.CertificateAuthentication) oAuthorizationHeaderOption
- func WithAuthorizationHeader(h string) functional.OptionWithError[HttpRequestParameters]
- func WithBody(b string) functional.OptionWithError[HttpRequestParameters]
- func WithCertificateAuthentication(cauth *tls.CertificateAuthentication) functional.OptionWithError[HttpRequestParameters]
- func WithClientId(id string) functional.OptionWithError[HttpRequestParameters]
- func WithClientSecret(s string) functional.OptionWithError[HttpRequestParameters]
- func WithCsrfUrl(u string) functional.OptionWithError[HttpRequestParameters]
- func WithHeaders(h map[string]string) functional.OptionWithError[HttpRequestParameters]
- func WithMethod(m string) functional.OptionWithError[HttpRequestParameters]
- func WithPassword(p string) functional.OptionWithError[HttpRequestParameters]
- func WithRefreshToken(rt string) functional.OptionWithError[HttpRequestParameters]
- func WithSucceedOnTimeout(s bool) functional.OptionWithError[HttpRequestParameters]
- func WithSuccessResponseCodes(src []string) functional.OptionWithError[HttpRequestParameters]
- func WithTimeout(t uint64) functional.OptionWithError[HttpRequestParameters]
- func WithTokenUrl(u string) functional.OptionWithError[HttpRequestParameters]
- func WithUrl(u string) functional.OptionWithError[HttpRequestParameters]
- func WithUser(u string) functional.OptionWithError[HttpRequestParameters]
- type AuthorizationHeader
- type AuthorizationHeaderGenerator
- func NewBasicAuthorizationHeader(u string, p string) AuthorizationHeaderGenerator
- func NewBearerAuthorizationHeader(t string) AuthorizationHeaderGenerator
- func NewExternalAuthorizationHeader(v string) AuthorizationHeaderGenerator
- func NewIasAuthorizationHeader(tokenUrl, user, clientCert string) AuthorizationHeaderGenerator
- func NewOAuthHeaderGenerator(p *HttpRequestParameters) AuthorizationHeaderGenerator
- func NewOAuthorizationHeader(tokenType TokenType, grantType GrantType, tokenUrl string, ...) AuthorizationHeaderGenerator
- type AuthorizationHeaderView
- type CacheableAuthorizationHeader
- type CacheableAuthorizationHeaderView
- type CachedToken
- type GrantType
- type HttpExecutor
- type HttpHeaders
- type HttpRequestExecutor
- type HttpRequestParameters
- func (p HttpRequestParameters) GetAuthorizationHeader() string
- func (p HttpRequestParameters) GetCertificateAuthentication() *tls.CertificateAuthentication
- func (p HttpRequestParameters) GetClientId() string
- func (p HttpRequestParameters) GetClientSecret() string
- func (p HttpRequestParameters) GetCsrfUrl() string
- func (p HttpRequestParameters) GetPassword() string
- func (p HttpRequestParameters) GetRefreshToken() string
- func (p HttpRequestParameters) GetTokenUrl() string
- func (p HttpRequestParameters) GetUser() string
- type HttpResponse
- type IllegalTokenTypeError
- type OAuthToken
- type OAuthTokenParseError
- type TokenFetcher
- type TokenType
Constants ¶
View Source
const ( AUTHORIZATION_HEADER_NAME string = "Authorization" IAS_TOKEN_URL_PATTERN string = "^https:\\/\\/(accounts\\.sap\\.com|[A-Za-z0-9+]+\\.accounts400\\.ondemand\\.com|[A-Za-z0-9+]+\\.accounts\\.ondemand\\.com)" )
View Source
const ( METHOD string = "method" URL string = "url" TOKEN_URL string = "tokenUrl" CSRF_URL string = "csrfUrl" CLIENT_ID string = "clientId" CLIENT_SECRET string = "clientSecret" REFRESH_TOKEN string = "refreshToken" HEADERS string = "headers" BODY string = "body" USER string = "user" PASSWORD string = "password" TIMEOUT string = "timeout" SUCCESS_RESPONSE_CODES string = "successResponseCodes" SUCCEED_ON_TIMEOUT string = "succeedOnTimeout" TRUSTED_CERTS string = "trustedCerts" CLIENT_CERT string = "clientCert" TRUST_ANY_CERT string = "trustAnyCert" AUTHORIZATION_HEADER string = "authorizationHeader" )
View Source
const ( CONTENT_TYPE_HEADER string = "Content-Type" CONTENT_TYPE_URL_ENCODED string = "application/x-www-form-urlencoded" TOKEN_EXPIRATION_TIME_PERCENTAGE float32 = 0.95 )
View Source
const ( CACHING_KEY_FORMAT string = "tokenUrl=%s&oAuthUser=%s&oAuthPwd=%s&getTokenBody=%s" PASSWORD_GRANT_FORMAT string = "grant_type=password&username=%s&password=%s" PASSWORD_CREDENTIALS_FORMAT_WITH_CLIENT_ID string = "grant_type=password&client_id=%s&username=%s&password=%s" CLIENT_CREDENTIALS_FORMAT string = "grant_type=client_credentials&client_id=%s&client_secret=%s" REFRESH_TOKEN_FORMAT string = "grant_type=refresh_token&refresh_token=%s" REFRESH_TOKEN_FORMAT_WITH_CERT string = "grant_type=refresh_token&client_id=%s&refresh_token=%s" )
View Source
const CSRF_VERB = "fetch"
View Source
const (
DEFAULT_HTTP_REQUEST_TIMEOUT_IN_S = 3 * time.Second
)
View Source
const (
INVALID_OAUTH_TOKEN_ERROR_MESSAGE = "Invalid oAuth 2.0 token response.\nURL: %s\nMethod: %s\nResponse code: %s"
)
View Source
const PASSCODE string = "passcode"
Variables ¶
This section is empty.
Functions ¶
func Content ¶
func Content(body string) functional.OptionWithError[HttpResponse]
func CreateHttpClient ¶
func Headers ¶
func Headers(headers http.Header) functional.OptionWithError[HttpResponse]
func IsSuccessfulBasedOnSuccessResponseCodes ¶
func IsSuccessfulBasedOnSuccessResponseCodes(statusCode int, successResponseCodes []string) functional.OptionWithError[HttpResponse]
func Method ¶
func Method(method string) functional.OptionWithError[HttpResponse]
func StatusCode ¶
func StatusCode(code int) functional.OptionWithError[HttpResponse]
func Time ¶
func Time(time int64) functional.OptionWithError[HttpResponse]
func Url ¶
func Url(url string) functional.OptionWithError[HttpResponse]
func UseCertificateAuthentication ¶
func UseCertificateAuthentication(certAuthentication *tls.CertificateAuthentication) oAuthorizationHeaderOption
func WithAuthorizationHeader ¶
func WithAuthorizationHeader(h string) functional.OptionWithError[HttpRequestParameters]
func WithBody ¶
func WithBody(b string) functional.OptionWithError[HttpRequestParameters]
func WithCertificateAuthentication ¶
func WithCertificateAuthentication(cauth *tls.CertificateAuthentication) functional.OptionWithError[HttpRequestParameters]
func WithClientId ¶
func WithClientId(id string) functional.OptionWithError[HttpRequestParameters]
func WithClientSecret ¶
func WithClientSecret(s string) functional.OptionWithError[HttpRequestParameters]
func WithCsrfUrl ¶
func WithCsrfUrl(u string) functional.OptionWithError[HttpRequestParameters]
func WithHeaders ¶
func WithHeaders(h map[string]string) functional.OptionWithError[HttpRequestParameters]
func WithMethod ¶
func WithMethod(m string) functional.OptionWithError[HttpRequestParameters]
func WithPassword ¶
func WithPassword(p string) functional.OptionWithError[HttpRequestParameters]
func WithRefreshToken ¶
func WithRefreshToken(rt string) functional.OptionWithError[HttpRequestParameters]
func WithSucceedOnTimeout ¶
func WithSucceedOnTimeout(s bool) functional.OptionWithError[HttpRequestParameters]
func WithSuccessResponseCodes ¶
func WithSuccessResponseCodes(src []string) functional.OptionWithError[HttpRequestParameters]
func WithTimeout ¶
func WithTimeout(t uint64) functional.OptionWithError[HttpRequestParameters]
func WithTokenUrl ¶
func WithTokenUrl(u string) functional.OptionWithError[HttpRequestParameters]
func WithUrl ¶
func WithUrl(u string) functional.OptionWithError[HttpRequestParameters]
func WithUser ¶
func WithUser(u string) functional.OptionWithError[HttpRequestParameters]
Types ¶
type AuthorizationHeader ¶
func CreateAuthorizationHeader ¶
func CreateAuthorizationHeader(params *HttpRequestParameters) (AuthorizationHeader, error)
Currently Basic authentication and Bearer token authentication is supported, OAuth 2.0 will be added later
type AuthorizationHeaderGenerator ¶
type AuthorizationHeaderGenerator interface {
Generate() (AuthorizationHeader, error)
}
func NewBasicAuthorizationHeader ¶
func NewBasicAuthorizationHeader(u string, p string) AuthorizationHeaderGenerator
func NewBearerAuthorizationHeader ¶ added in v0.0.1
func NewBearerAuthorizationHeader(t string) AuthorizationHeaderGenerator
func NewExternalAuthorizationHeader ¶
func NewExternalAuthorizationHeader(v string) AuthorizationHeaderGenerator
func NewIasAuthorizationHeader ¶
func NewIasAuthorizationHeader(tokenUrl, user, clientCert string) AuthorizationHeaderGenerator
func NewOAuthHeaderGenerator ¶
func NewOAuthHeaderGenerator(p *HttpRequestParameters) AuthorizationHeaderGenerator
func NewOAuthorizationHeader ¶
func NewOAuthorizationHeader(tokenType TokenType, grantType GrantType, tokenUrl string, executor HttpExecutor, requestBody string, cachingKey string, opts ...oAuthorizationHeaderOption) AuthorizationHeaderGenerator
type AuthorizationHeaderView ¶
type AuthorizationHeaderView struct {
// contains filtered or unexported fields
}
func EmptyAuthorizationHeader ¶
func EmptyAuthorizationHeader() AuthorizationHeaderView
func NewAuthorizationHeaderView ¶
func NewAuthorizationHeaderView(value string) AuthorizationHeaderView
func (AuthorizationHeaderView) GetName ¶
func (h AuthorizationHeaderView) GetName() string
func (AuthorizationHeaderView) GetValue ¶
func (h AuthorizationHeaderView) GetValue() string
func (AuthorizationHeaderView) HasValue ¶
func (h AuthorizationHeaderView) HasValue() bool
type CacheableAuthorizationHeader ¶
type CacheableAuthorizationHeader interface { AuthorizationHeader GetCachingKey() string GetCacheableValue() (string, error) ApplyCachedToken(token string) (CacheableAuthorizationHeader, error) }
type CacheableAuthorizationHeaderView ¶
type CacheableAuthorizationHeaderView struct { AuthorizationHeaderView // contains filtered or unexported fields }
func NewCacheableAuthorizationHeaderView ¶
func NewCacheableAuthorizationHeaderView(value string, header *oAuthorizationHeader) CacheableAuthorizationHeaderView
func (CacheableAuthorizationHeaderView) ApplyCachedToken ¶
func (h CacheableAuthorizationHeaderView) ApplyCachedToken(token string) (CacheableAuthorizationHeader, error)
func (CacheableAuthorizationHeaderView) GetCacheableValue ¶
func (h CacheableAuthorizationHeaderView) GetCacheableValue() (string, error)
func (CacheableAuthorizationHeaderView) GetCachingKey ¶
func (h CacheableAuthorizationHeaderView) GetCachingKey() string
type CachedToken ¶
type HttpExecutor ¶
type HttpExecutor interface {
ExecuteWithParameters(p *HttpRequestParameters) (HttpResponse, error)
}
type HttpHeaders ¶
type HttpRequestExecutor ¶
func DefaultHttpRequestExecutor ¶
func DefaultHttpRequestExecutor() *HttpRequestExecutor
func NewHttpRequestExecutor ¶
func NewHttpRequestExecutor(h AuthorizationHeader) *HttpRequestExecutor
func (*HttpRequestExecutor) Execute ¶
func (e *HttpRequestExecutor) Execute(ctx executors.ExecutorContext) *executors.ExecutorResult
func (*HttpRequestExecutor) ExecuteWithParameters ¶
func (e *HttpRequestExecutor) ExecuteWithParameters(p *HttpRequestParameters) (HttpResponse, error)
type HttpRequestParameters ¶
type HttpRequestParameters struct {
// contains filtered or unexported fields
}
func NewHttpRequestParameters ¶
func NewHttpRequestParameters(opts ...functional.OptionWithError[HttpRequestParameters]) *HttpRequestParameters
func NewHttpRequestParametersFromContext ¶
func NewHttpRequestParametersFromContext(ctx executors.ExecutorContext) *HttpRequestParameters
func (HttpRequestParameters) GetAuthorizationHeader ¶
func (p HttpRequestParameters) GetAuthorizationHeader() string
func (HttpRequestParameters) GetCertificateAuthentication ¶
func (p HttpRequestParameters) GetCertificateAuthentication() *tls.CertificateAuthentication
func (HttpRequestParameters) GetClientId ¶
func (p HttpRequestParameters) GetClientId() string
func (HttpRequestParameters) GetClientSecret ¶
func (p HttpRequestParameters) GetClientSecret() string
func (HttpRequestParameters) GetCsrfUrl ¶
func (p HttpRequestParameters) GetCsrfUrl() string
func (HttpRequestParameters) GetPassword ¶
func (p HttpRequestParameters) GetPassword() string
func (HttpRequestParameters) GetRefreshToken ¶
func (p HttpRequestParameters) GetRefreshToken() string
func (HttpRequestParameters) GetTokenUrl ¶
func (p HttpRequestParameters) GetTokenUrl() string
func (HttpRequestParameters) GetUser ¶
func (p HttpRequestParameters) GetUser() string
type HttpResponse ¶
type HttpResponse struct { Url string `json:"url"` Method string `json:"method"` Content string `json:"body"` Headers HttpHeaders `json:"headers"` StatusCode string `json:"status"` SizeInBytes uint `json:"size"` Time int64 `json:"time"` // contains filtered or unexported fields }
func NewHttpResponse ¶
func NewHttpResponse(opts ...functional.OptionWithError[HttpResponse]) (*HttpResponse, error)
func (HttpResponse) ToMap ¶
func (r HttpResponse) ToMap() (map[string]interface{}, error)
TODO: Implementation can be improved with reflection and removing json marshalling-unmarshalling process
type IllegalTokenTypeError ¶
type IllegalTokenTypeError struct {
// contains filtered or unexported fields
}
func NewIllegalTokenTypeError ¶
func NewIllegalTokenTypeError(tokenType TokenType) *IllegalTokenTypeError
func (*IllegalTokenTypeError) Error ¶
func (e *IllegalTokenTypeError) Error() string
type OAuthToken ¶
type OAuthToken struct { TokenType string `json:"token_type"` AccessToken string `json:"access_token"` IdToken string `json:"id_token,omitempty"` ExpiresIn int64 `json:"expires_in,omitempty"` // contains filtered or unexported fields }
func NewOAuthToken ¶
func NewOAuthToken(token string, issuedAt int64) (*OAuthToken, error)
func (OAuthToken) HasValue ¶
func (t OAuthToken) HasValue() bool
type OAuthTokenParseError ¶
type OAuthTokenParseError struct {
// contains filtered or unexported fields
}
func NewOAuthTokenParseError ¶
func NewOAuthTokenParseError(url string, method string, responseCode string) *OAuthTokenParseError
func (*OAuthTokenParseError) Error ¶
func (e *OAuthTokenParseError) Error() string
type TokenFetcher ¶
func NewCsrfTokenFetcher ¶
func NewCsrfTokenFetcher(p *HttpRequestParameters, authHeader AuthorizationHeader) TokenFetcher
func NewIasTokenFetcher ¶
func NewIasTokenFetcher(tokenUrl, user, clientCert string) TokenFetcher
func NewOAuthTokenFetcher ¶
func NewOAuthTokenFetcher(opts ...functional.Option[oAuthTokenFetcher]) TokenFetcher
Source Files
¶
- authorization_header.go
- basic_authorization_header.go
- bearer_authorization_header.go
- csrf_token_fetcher.go
- errors.go
- external_authorization_header.go
- generator.go
- grant_type.go
- http_client.go
- http_executor.go
- http_executor_parameters.go
- http_response.go
- ias_authorization_header.go
- ias_token_fetcher.go
- oauth_header.go
- oauth_header_generator.go
- oauth_token_fetcher.go
- token.go
- token_fetcher.go
- token_type.go
Click to show internal directories.
Click to hide internal directories.