Documentation
¶
Index ¶
- func With(client restapi.Connector, opts ...Option) restapi.Authorizer
- func WithClientID(client restapi.Connector, opts ...Option) restapi.Authorizer
- func WithCredential(client restapi.Connector, opts ...Option) restapi.Authorizer
- func WithExchangeToken(client restapi.Connector, opts ...Option) restapi.Authorizer
- func WithToken(token string) restapi.Authorizer
- type AccessToken
- type Option
- func Access(access string) Option
- func AuthClientId(clientId string) Option
- func Digest(oauthAccess, oauthSecret string) Option
- func ExchangeScope(scope string) Option
- func ExchangeToken(token string) Option
- func Secret(secret string) Option
- func UseConfigFile(path string) Option
- func UseCookies() Option
- func UseEnvironment() Option
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func With ¶
func With(client restapi.Connector, opts ...Option) restapi.Authorizer
With implements fallback auth strategy, it choose the desired strategy depends on provided configuration options.
1. OAuth2 Resource Owner Password Grant is default and recommended strategy. This strategy requires definition of * Client Access Key, see oauth.Access(...) * Client Secret Key, see oauth.Secret(...) * Client Secret Digest, also known as OAuth Client Secrets, see oauth.Digest(...)
2. OAuth2 Authorization Code Grant strategy is used when only single pair of access/secret key is provided. It allows usage of username and password * Client Access Key, see oauth.Access(...) * Client Secret Key, see oauth.Secret(...)
3. Finally, it falls back explicit token token definition
func WithClientID ¶
func WithClientID(client restapi.Connector, opts ...Option) restapi.Authorizer
WithClientID executes OAuth2 Resource Owner Password Grant It uses access/secret key pair to authenticate client
auth := oauth.WithClientID( restapi.New( restapi.BaseURL(url), ), oauth.Digest(oauthAccess, oauthSecret), oauth.Access(access), oauth.Secret(secret), ) return restapi.New( restapi.Auth(auth()), restapi.BaseURL(url), )
func WithCredential ¶
func WithCredential(client restapi.Connector, opts ...Option) restapi.Authorizer
WithCredential executes OAuth2 Authorization Code Grant It uses access/secret key pair to authenticate client
auth := oauth.WithCredential( restapi.New( restapi.BaseURL(url), ), oauth.Access(access), oauth.Secret(secret), ) return restapi.New( restapi.Auth(auth()), restapi.BaseURL(url), )
func WithExchangeToken ¶ added in v2.43.0
func WithExchangeToken(client restapi.Connector, opts ...Option) restapi.Authorizer
WithExchangeToken authenticate users using externally created JWT Token in exchange to a PrivX access token
auth := oauth.WithExchangeToken(
restapi.New(
restapi.BaseURL(url),
),
oauth.ExchangeToken(token), # required
oauth.ExchangeScope("privx-user"), # optional
oauth.AuthClientId("privx-ui"), # optional
)
return restapi.New(
restapi.Auth(auth()),
restapi.BaseURL(url),
)
func WithToken ¶
func WithToken(token string) restapi.Authorizer
WithToken uses explicitly defined JWT to authenticate client. Add a 'Bearer ' prefix to the token when passing it to WithToken.
Types ¶
type AccessToken ¶
type AccessToken struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
ExpiresIn uint `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
// contains filtered or unexported fields
}
AccessToken contains OAuth2 access token information.
type Option ¶
type Option func(*tAuth) *tAuth
Option is configuration applied to the client
func AuthClientId ¶ added in v2.43.0
AuthClientId setups OAUTH client Id e.g. privx-ui
func ExchangeScope ¶ added in v2.43.0
ExchangeScope setups access token scope e.g. privx-user
func ExchangeToken ¶ added in v2.43.0
ExchangeToken setups externally created JWT Token
func UseConfigFile ¶
UseConfigFile setup credential from tol file
func UseCookies ¶
func UseCookies() Option
func UseEnvironment ¶
func UseEnvironment() Option
UseEnvironment setup credential from environment variables