Documentation ¶
Index ¶
- Constants
- Variables
- func BasicAuthHeader(userid, password string) (string, error)
- func BasicAuthToken(username, password string) (*oauth2.Token, error)
- func ClientSetTLSInsecureSkipVerify(client *http.Client, insecureSkipVerify bool) *http.Client
- func HandlerFuncWrapBasicAuth(handler http.HandlerFunc, username, password, realm, errmsg string) http.HandlerFunc
- func NewClientAuthCode(conf oauth2.Config, authCode string) (*http.Client, error)
- func NewClientAuthzTokenSimple(tokenType, accessToken string) *http.Client
- func NewClientBasicAuth(username, password string, tlsInsecureSkipVerify bool) (*http.Client, error)
- func NewClientBearerTokenSimpleOrJSON(ctx context.Context, tokenOrJSON []byte) (*http.Client, error)
- func NewClientHeaderQuery(header http.Header, query url.Values, allowInsecure bool) *http.Client
- func NewClientPassword(conf oauth2.Config, ctx context.Context, username, password string) (*http.Client, error)
- func NewClientPasswordConf(conf oauth2.Config, username, password string) (*http.Client, error)
- func NewClientTLSToken(ctx context.Context, tlsConfig *tls.Config, token *oauth2.Token) *http.Client
- func NewClientToken(tokenType, tokenValue string, allowInsecure bool) *http.Client
- func NewClientTokenBase64Encode(tokenType, tokenValue string, allowInsecure bool) *http.Client
- func NewClientTokenJSON(ctx context.Context, tokenJSON []byte) (*http.Client, error)
- func NewClientTokenOAuth2(token *oauth2.Token) *http.Client
- func NewClientWebTokenStore(ctx context.Context, conf *oauth2.Config, tStore *TokenStoreFile, ...) (*http.Client, error)
- func NewTokenAccountCredentials(ctx context.Context, tokenEndpoint, clientID, clientSecret string, ...) (*oauth2.Token, error)
- func NewTokenCLIFromWeb(cfg *oauth2.Config, state string) (*oauth2.Token, error)
- func ParseToken(rawToken []byte) (*oauth2.Token, error)
- func ParseTokenReader(r io.Reader) (*oauth2.Token, error)
- func PathVersion() string
- func RFC7617UserPass(userid, password string) (string, error)
- func ReadTokenFile(fpath string) (*oauth2.Token, error)
- func TokenClientCredentials(cfg clientcredentials.Config) (*oauth2.Token, error)
- func UserCredentialsDir() (string, error)
- func UserCredentialsDirMk(perm os.FileMode) (string, error)
- func WriteTokenFile(fpath string, tok *oauth2.Token) error
- type AppCredentials
- type AppCredentialsWrapper
- type AuthorizationType
- type OAuth2Util
- type Scope
- type ServiceType
- type TokenStoreFile
- type UserCredentials
Constants ¶
const ( GrantTypeAccountCredentials = "account_credentials" // used by only Zoom? GrantTypeAuthorizationCode = "authorization_code" GrantTypeClientCredentials = "client_credentials" GrantTypeJWTBearer = "urn:ietf:params:oauth:grant-type:jwt-bearer" // #nosec G101 GrantTypePassword = "password" GrantTypeRefreshToken = "refresh_token" GrantTypeCustomStatic = "custom_static" ParamAssertion = "assertion" ParamGrantType = "grant_type" ParamScope = "scope" ParamPassword = "password" ParamUsername = "usernamae" ParamRefreshToken = "refresh_token" TokenBasic = "Basic" TokenBearer = "Bearer" OAuth2TokenPropAccessToken = "access_token" OAuth2TokenPropExpiresIn = "expires_in" OAuth2TokenPropRefreshToken = "refresh_token" OAuth2TokenPropTokenType = "token_type" TestRedirectURL = "https://grokify.github.io/goauth/oauth2callback/" )
const ( VERSION = "0.10" PATH = "github.com/grokify/goauth" )
Variables ¶
var (
RelCredentialsDir = ".credentials"
)
Functions ¶
func BasicAuthHeader ¶
func BasicAuthToken ¶
BasicAuthToken provides Basic Authentication support via an oauth2.Token.
func ClientSetTLSInsecureSkipVerify ¶ added in v0.21.1
func HandlerFuncWrapBasicAuth ¶
func HandlerFuncWrapBasicAuth(handler http.HandlerFunc, username, password, realm, errmsg string) http.HandlerFunc
func NewClientAuthCode ¶
func NewClientAuthzTokenSimple ¶
NewClientAuthzTokenSimple returns a *http.Client given a token type and token string.
func NewClientBasicAuth ¶
func NewClientBasicAuth(username, password string, tlsInsecureSkipVerify bool) (*http.Client, error)
NewClientBasicAuth returns a *http.Client given a basic auth username and password.
func NewClientHeaderQuery ¶
NewClientHeaderQuery returns a new `*http.Client` that will set headers and query string parameters on very request.
func NewClientPassword ¶
func NewClientPasswordConf ¶
func NewClientTLSToken ¶
func NewClientToken ¶
func NewClientTokenJSON ¶
func NewClientWebTokenStore ¶
func NewTokenAccountCredentials ¶ added in v0.21.1
func NewTokenAccountCredentials(ctx context.Context, tokenEndpoint, clientID, clientSecret string, bodyOpts url.Values) (*oauth2.Token, error)
NewTokenAccountCredentials is to support Zoom API's `application_credentials` OAuth 2.0 grant type. It is unknown if anyone else uses this at the time of this writing. This grant type is described here: https://developers.zoom.us/docs/internal-apps/s2s-oauth/ .
func NewTokenCLIFromWeb ¶
NewTokenCLIFromWeb enables a CLI app with no UI to generate a OAuth2 AuthURL which is copy and pasted into a web browser to return an an OAuth 2 authorization code and state, where the authorization code is entered on the command line.
func ParseToken ¶
ParseToken parses a OAuth 2 token and returns an `*oauth2.Token` with custom properties.
func PathVersion ¶
func PathVersion() string
func RFC7617UserPass ¶
RFC7617UserPass base64 encodes a user-id and password per: https://tools.ietf.org/html/rfc7617#section-2
func ReadTokenFile ¶
ReadTokenFile retrieves a Token from a given filepath.
func TokenClientCredentials ¶
func TokenClientCredentials(cfg clientcredentials.Config) (*oauth2.Token, error)
TokenClientCredentials is an alternative to `clientcredentials.Config.Token()` which does not work for some APIs. More investigation is needed but it appears the issue is encoding the HTTP request body. The approach here uses `&` in the URL encoded values.
func UserCredentialsDir ¶
Types ¶
type AppCredentials ¶
type AppCredentials struct { Service string `json:"service,omitempty"` ClientID string `json:"client_id"` ClientSecret string `json:"client_secret"` RedirectURIs []string `json:"redirect_uris"` AuthURI string `json:"auth_uri"` TokenURI string `json:"token_uri"` Scopes []string `json:"scopes"` }
func (*AppCredentials) Config ¶
func (ac *AppCredentials) Config() *oauth2.Config
func (*AppCredentials) Defaultify ¶
func (ac *AppCredentials) Defaultify()
type AppCredentialsWrapper ¶
type AppCredentialsWrapper struct { Web *AppCredentials `json:"web"` Installed *AppCredentials `json:"installed"` }
func NewAppCredentialsWrapperFromBytes ¶
func NewAppCredentialsWrapperFromBytes(data []byte) (AppCredentialsWrapper, error)
type AuthorizationType ¶
type AuthorizationType int
const ( Anonymous AuthorizationType = iota Basic Bearer Digest NTLM Negotiate OAuth )
func (AuthorizationType) String ¶
func (a AuthorizationType) String() string
String returns the English name of the authorizationTypes ("Basic", "Bearer", ...).
type OAuth2Util ¶
type ServiceType ¶
type ServiceType int
const ( Google ServiceType = iota Facebook RingCentral Aha )
type TokenStoreFile ¶
func NewTokenStoreFile ¶
func NewTokenStoreFile(file string) *TokenStoreFile
func (*TokenStoreFile) NewTokenCLIFromWeb ¶
func (*TokenStoreFile) Read ¶
func (ts *TokenStoreFile) Read() error
func (*TokenStoreFile) Write ¶
func (ts *TokenStoreFile) Write() error
type UserCredentials ¶
UserCredentials represents a user's credentials.