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 WithToken(token string) restapi.Authorizer
- type AccessToken
- type Option
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 := oauth2.WithClientID( restapi.New(...), oauth2.Access(...), oauth2.Secret(...), ) client := restapi.New( restapi.Auth(auth), restapi.Endpoint("https://privx.example.com"), ) rolestore.New(client)
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 := oauth2.WithCredential( oauth2.Access(...), oauth2.Secret(...), oauth2.Transport(...), ) client := restapi.New( restapi.Auth(auth), restapi.Endpoint("https://privx.example.com"), ) rolestore.New(client)
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 UseConfigFile ¶
UseConfigFile setup credential from tol file
func UseCookies ¶ added in v1.34.0
func UseCookies() Option
func UseEnvironment ¶
func UseEnvironment() Option
UseEnvironment setup credential from environment variables