grokify/goauth

View on GitHub

Showing 27 of 39 total issues

Function NewEndpoint has 172 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func NewEndpoint(serviceName, subdomain string) (oauth2.Endpoint, string, error) {
    switch strings.ToLower(strings.TrimSpace(serviceName)) {
    case ServiceAha:
        subdomain = strings.TrimSpace(subdomain)
        if len(subdomain) == 0 {
Severity: Major
Found in endpoints/endpoints.go - About 5 hrs to fix

    Function main has 67 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func main() {
        //err := config.LoadDotEnvSkipEmpty(os.Getenv("ENV_PATH"), "./.env")
        _, err := config.LoadDotEnv([]string{"./.env"}, -1)
        if err != nil {
            panic(err)
    Severity: Minor
    Found in salesforce/examples/salesforce_versions/salesforce_versions.go - About 1 hr to fix

      Function sendTestEmail has 65 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func sendTestEmail(cfg appConfig, client gosparkpost.Client) {
          day := 811 // Change this to set the day. This currently uses single digit month + 2 digit day
          seq := 0   // Sequence index. Start with 0 and increment. This demo doesn't support changing the day when changing sequence.
      
          if len(strings.TrimSpace(cfg.SparkPostEmailRecipientDemo)) == 0 {
      Severity: Minor
      Found in sparkpost/examples/send_ics/main.go - About 1 hr to fix

        Method Credentials.NewClient has 10 return statements (exceeds 4 allowed).
        Open

        func (creds *Credentials) NewClient(ctx context.Context) (*http.Client, error) {
            switch creds.Type {
            case TypeBasic:
                if creds.Basic == nil {
                    return nil, ErrBasicAuthNotPopulated
        Severity: Major
        Found in credentials.go - About 1 hr to fix

          Method CredentialsOAuth2.NewToken has 8 return statements (exceeds 4 allowed).
          Open

          func (oc *CredentialsOAuth2) NewToken(ctx context.Context) (*oauth2.Token, error) {
              if oc.Token != nil && len(strings.TrimSpace(oc.Token.AccessToken)) > 0 {
                  return oc.Token, nil
              } else if strings.Contains(strings.ToLower(oc.GrantType), "jwt") {
                  return authutil.NewTokenOAuth2JWT(ctx, oc.Endpoint.TokenURL, oc.ClientID, oc.ClientSecret, oc.JWT)
          Severity: Major
          Found in credentials_oauth2.go - About 50 mins to fix

            Function NewClientFileStore has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                credentials []byte,
                scopes []string,
                tokenPath string,
                useDefaultDir bool,
                forceNewToken bool,
            Severity: Minor
            Found in google/google_client_with_token_store_file.go - About 45 mins to fix

              Function RetrieveRcToken has 7 return statements (exceeds 4 allowed).
              Open

              func RetrieveRcToken(cfg oauth2.Config, params url.Values) (*RcToken, error) {
                  r, err := http.NewRequest(
                      http.MethodPost,
                      cfg.Endpoint.TokenURL,
                      strings.NewReader(params.Encode()))
              Severity: Major
              Found in ringcentral/ringcentral_client.go - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                    } else if oc.IsGrantType(authutil.GrantTypePassword) {
                        // cfg := oc.Config()
                        // return cfg.PasswordCredentialsToken(ctx, oc.Username, oc.Password)
                        return oc.NewTokenPasswordCredentials(ctx) // supports custom request params
                    } else if oc.IsGrantType(authutil.GrantTypeAuthorizationCode) {
                Severity: Major
                Found in credentials_oauth2.go - About 45 mins to fix

                  Function NewClientFileStore has 6 return statements (exceeds 4 allowed).
                  Open

                  func NewClientFileStore(
                      credentials []byte,
                      scopes []string,
                      tokenPath string,
                      useDefaultDir bool,
                  Severity: Major
                  Found in google/google_client_with_token_store_file.go - About 40 mins to fix

                    Function GetOneItem has 6 return statements (exceeds 4 allowed).
                    Open

                    func GetOneItem(items []Item) Item {
                        if len(items) == 0 {
                            return Item{}
                        }
                        havePrimary := false
                    Severity: Major
                    Found in scim/user.go - About 40 mins to fix

                      Function ParseJWTString has 6 return statements (exceeds 4 allowed).
                      Open

                      func ParseJWTString(tokenString string, secretKey string, claims jwt.Claims) (*jwt.Token, error) {
                          // https://stackoverflow.com/questions/41077953/go-language-and-verify-jwt
                          if claims == nil {
                              if token, err := jwt.Parse(tokenString, func(token *jwt.Token) (any, error) {
                                  return []byte(secretKey), nil
                      Severity: Major
                      Found in authutil/jwt.go - About 40 mins to fix

                        Function ContactsV1ExportWriteFiles has 6 return statements (exceeds 4 allowed).
                        Open

                        func ContactsV1ExportWriteFiles(client *http.Client, fileprefix string, opts *ContactsListV1Opts) error {
                            if len(fileprefix) == 0 {
                                fileprefix = "hubspot_contacts_v1"
                            }
                            if opts != nil && opts.Count > LimitMax || opts.Count < 1 {
                        Severity: Major
                        Found in hubspot/contacts_export.go - About 40 mins to fix

                          Method Config.NewClient has 6 return statements (exceeds 4 allowed).
                          Open

                          func (cfg Config) NewClient() (*http.Client, error) {
                              tlsConfig, err := tlsutil.NewTLSConfigCerts("", "", []string{}, []string{}, false)
                              if err != nil {
                                  return nil, err
                              }
                          Severity: Major
                          Found in visa/visa_client.go - About 40 mins to fix

                            Function ContactsV3ExportWriteFiles has 6 return statements (exceeds 4 allowed).
                            Open

                            func ContactsV3ExportWriteFiles(client *http.Client, fileprefix string, opts *ContactsListV3Opts) error {
                                if len(fileprefix) == 0 {
                                    fileprefix = "hubspot_contacts_v3"
                                }
                                if opts != nil && opts.Limit > LimitMax || opts.Limit < 1 {
                            Severity: Major
                            Found in hubspot/contacts_export.go - About 40 mins to fix

                              Function NewClientWithTokenSet has 5 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                              func NewClientWithTokenSet(ctx context.Context, conf *oauth2.Config, token *oauth2.Token,
                                  tokenSet TokenSet, tokenKey, serviceKey, serviceType string) (*http.Client, error) {
                              Severity: Minor
                              Found in multiservice/tokens/tokens.go - About 35 mins to fix

                                Function NewClientWebTokenStore has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                func NewClientWebTokenStore(ctx context.Context, conf *oauth2.Config, tStore *TokenStoreFile, forceNewToken bool, state string) (*http.Client, error) {
                                Severity: Minor
                                Found in authutil/token_store.go - About 35 mins to fix

                                  Method ClientUtil.GetSCIMUser has 5 return statements (exceeds 4 allowed).
                                  Open

                                  func (apiutil *ClientUtil) GetSCIMUser() (scim.User, error) {
                                      scimUser := scim.User{}
                                  
                                      resp, err := apiutil.Client.Get(GoogleAPIURLUserinfo)
                                      if err != nil {
                                  Severity: Major
                                  Found in google/google_clientutil.go - About 35 mins to fix

                                    Function main has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                                    Open

                                    func main() {
                                        //err := config.LoadDotEnvSkipEmpty(os.Getenv("ENV_PATH"), "./.env")
                                        _, err := config.LoadDotEnv([]string{"./.env"}, -1)
                                        if err != nil {
                                            panic(err)
                                    Severity: Minor
                                    Found in salesforce/examples/salesforce_versions/salesforce_versions.go - About 35 mins to fix

                                    Cognitive Complexity

                                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                    A method's cognitive complexity is based on a few simple rules:

                                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                    • Code is considered more complex for each "break in the linear flow of the code"
                                    • Code is considered more complex when "flow breaking structures are nested"

                                    Further reading

                                    Function TokenClientCredentials has 5 return statements (exceeds 4 allowed).
                                    Open

                                    func TokenClientCredentials(cfg clientcredentials.Config) (*oauth2.Token, error) {
                                        body := url.Values{}
                                        body.Add(ParamGrantType, GrantTypeClientCredentials)
                                        for _, scope := range cfg.Scopes {
                                            body.Add(ParamScope, scope)
                                    Severity: Major
                                    Found in authutil/token.go - About 35 mins to fix

                                      Method CredentialsOAuth2.NewTokenPasswordCredentials has 5 return statements (exceeds 4 allowed).
                                      Open

                                      func (oc *CredentialsOAuth2) NewTokenPasswordCredentials(ctx context.Context) (*oauth2.Token, error) {
                                          if sreq, err := oc.newTokenPasswordCredentialsRequest(ctx); err != nil {
                                              return nil, err
                                          } else if hreq, err := sreq.HTTPRequest(ctx); err != nil {
                                              return nil, err
                                      Severity: Major
                                      Found in credentials_oauth2.go - About 35 mins to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language