auth

package
v0.0.0-...-55a2669 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: BSD-2-Clause Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateEncodedState

func GenerateEncodedState(req *http.Request, privateKeyStr string) (csrfToken, encryptedCsrfToken string, err error)

func GenerateToken

func GenerateToken(methodEncrypt *jwt.SigningMethodECDSA, privateKeyStr string, tokenData jwt.MapClaims) (token string, err error)

func GetCompanyInfo

func GetCompanyInfo(w http.ResponseWriter, r *http.Request)

* Sample QBO API call to get CompanyInfo using OAuth2 tokens

func ValidateToken

func ValidateToken(publicKeyStr string, token string) (valid bool, claims jwt.MapClaims, err error)

Types

type Address

type Address struct {
	StreetAddress string `json:"streetAddress"`
	Locality      string `json:"locality"`
	Region        string `json:"region"`
	PostalCode    string `json:"postalCode"`
	Country       string `json:"country"`
}

type BearerTokenResponse

type BearerTokenResponse struct {
	RefreshToken           string `json:"refresh_token"`
	AccessToken            string `json:"access_token"`
	TokenType              string `json:"token_type"`
	IdToken                string `json:"id_token"`
	ExpiresIn              int64  `json:"expires_in"`
	XRefreshTokenExpiresIn int64  `json:"x_refresh_token_expires_in"`
}

type Claims

type Claims struct {
	AUD       []string `json:"aud"`
	EXP       int64    `json:"exp"`
	IAT       int      `json:"iat"`
	ISS       string   `json:"iss"`
	REALMID   string   `json:"realmid"`
	SUB       string   `json:"sub"`
	AUTH_TIME int      `json:"auth_time"`
}

type Config

type Config struct {

	// Loads once
	ClientId                    string
	ClientSecret                string
	RedirectUri                 string
	OpenIdConfigurationEndpoint string

	// Loads daily
	OpenIdConfiguration OpenIdConfiguration
	// contains filtered or unexported fields
}

func GetAuthConfig

func GetAuthConfig() Config

func (*Config) BasicAuth

func (c *Config) BasicAuth() string

func (*Config) CallJWKSAPI

func (c *Config) CallJWKSAPI() (*JWKSResponse, error)

* Call JWKS endpoint and retrieve the key values

func (*Config) Connect

func (c *Config) Connect(req *http.Request) (authUri string, encryptedCsrfToken string, err error)

func (*Config) RefreshToken

func (c *Config) RefreshToken(w http.ResponseWriter, r *http.Request)

* Call the refresh endpoint to generate new tokens

func (*Config) RetrieveBearerToken

func (c *Config) RetrieveBearerToken(code string) (*BearerTokenResponse, error)

* Method to retrive access token (bearer token)

func (*Config) RevokeToken

func (c *Config) RevokeToken(w http.ResponseWriter, r *http.Request)

* Call the revoke endpoint to revoke tokens

func (*Config) UpdateOpenIdEndpoints

func (c *Config) UpdateOpenIdEndpoints() (err error)

func (*Config) ValidateIDToken

func (c *Config) ValidateIDToken(idToken string) bool

func (*Config) VerifyOauth2Callback

func (c *Config) VerifyOauth2Callback(req *http.Request) (realmId string, accessToken string, refreshToken string, intuitJWToken string, err error)
type Header struct {
	ALG string `json:"alg"`
	KID string `json:"kid"`
}

type JWKSResponse

type JWKSResponse struct {
	KEYS []Keys `json:"keys"`
}

type Keys

type Keys struct {
	KTY string `json:"kty"`
	E   string `json:"e"`
	USE string `json:"use"`
	KID string `json:"kid"`
	ALG string `json:"alg"`
	N   string `json:"n"`
}

type OpenIdConfiguration

type OpenIdConfiguration struct {
	Issuer                string `json:"issuer"`
	AuthorizationEndpoint string `json:"authorization_endpoint"`
	TokenEndpoint         string `json:"token_endpoint"`
	UserinfoEndpoint      string `json:"userinfo_endpoint"`
	RevocationEndpoint    string `json:"revocation_endpoint"`
	JwksUri               string `json:"jwks_uri"`
}

type UserInfoResponse

type UserInfoResponse struct {
	Sub                 string  `json:"sub"`
	Email               string  `json:"email"`
	EmailVerified       bool    `json:"emailVerified"`
	GivenName           string  `json:"givenName"`
	FamilyName          string  `json:"familyName"`
	PhoneNumber         string  `json:"phoneNumber"`
	PhoneNumberVerified bool    `json:"phoneNumberVerified"`
	Address             Address `json:"address"`
}

func GetUserInfo

func GetUserInfo(w http.ResponseWriter, r *http.Request, accessToken string) (*UserInfoResponse, error)

* Method to retrive userInfo - email, address, name, phone etc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL