ory-am/hydra

View on GitHub
oauth2/handler.go

Summary

Maintainability
F
4 days
Test Coverage

File handler.go has 787 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0

package oauth2

Severity: Major
Found in oauth2/handler.go - About 1 day to fix

    Method Handler.createVerifiableCredential has 126 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (h *Handler) createVerifiableCredential(w http.ResponseWriter, r *http.Request) {
        ctx := r.Context()
        session := NewSessionWithCustomClaims(ctx, h.c, "")
        accessToken := fosite.AccessTokenFromRequest(r)
        tokenType, _, err := h.r.OAuth2Provider().IntrospectToken(ctx, accessToken, fosite.AccessToken, session)
    Severity: Major
    Found in oauth2/handler.go - About 4 hrs to fix

      Method Handler.oAuth2Authorize has 91 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (h *Handler) oAuth2Authorize(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
          ctx := r.Context()
      
          authorizeRequest, err := h.r.OAuth2Provider().NewAuthorizeRequest(ctx, r)
          if err != nil {
      Severity: Major
      Found in oauth2/handler.go - About 2 hrs to fix

        Method Handler.introspectOAuth2Token has 81 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (h *Handler) introspectOAuth2Token(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
            ctx := r.Context()
            session := NewSessionWithCustomClaims(ctx, h.c, "")
        
            if r.Method != "POST" {
        Severity: Major
        Found in oauth2/handler.go - About 2 hrs to fix

          Method Handler.performOidcFrontOrBackChannelLogout has 79 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (h *Handler) performOidcFrontOrBackChannelLogout(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
              ctx := r.Context()
          
              handled, err := h.r.ConsentStrategy().HandleOpenIDConnectLogout(ctx, w, r)
              if errors.Is(err, consent.ErrAbortOAuth2Request) {
          Severity: Major
          Found in oauth2/handler.go - About 2 hrs to fix

            Method Handler.oauth2TokenExchange has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
            Open

            func (h *Handler) oauth2TokenExchange(w http.ResponseWriter, r *http.Request) {
                ctx := r.Context()
                session := NewSessionWithCustomClaims(ctx, h.c, "")
            
                accessRequest, err := h.r.OAuth2Provider().NewAccessRequest(ctx, r, session)
            Severity: Minor
            Found in oauth2/handler.go - About 1 hr 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

            Method Handler.getOidcUserInfo has 68 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (h *Handler) getOidcUserInfo(w http.ResponseWriter, r *http.Request) {
                ctx := r.Context()
                session := NewSessionWithCustomClaims(ctx, h.c, "")
                tokenType, ar, err := h.r.OAuth2Provider().IntrospectToken(ctx, fosite.AccessTokenFromRequest(r), fosite.AccessToken, session)
                if err != nil {
            Severity: Minor
            Found in oauth2/handler.go - About 1 hr to fix

              Method Handler.createVerifiableCredential has 18 return statements (exceeds 4 allowed).
              Open

              func (h *Handler) createVerifiableCredential(w http.ResponseWriter, r *http.Request) {
                  ctx := r.Context()
                  session := NewSessionWithCustomClaims(ctx, h.c, "")
                  accessToken := fosite.AccessTokenFromRequest(r)
                  tokenType, _, err := h.r.OAuth2Provider().IntrospectToken(ctx, accessToken, fosite.AccessToken, session)
              Severity: Major
              Found in oauth2/handler.go - About 1 hr to fix

                Method Handler.oauth2TokenExchange has 65 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (h *Handler) oauth2TokenExchange(w http.ResponseWriter, r *http.Request) {
                    ctx := r.Context()
                    session := NewSessionWithCustomClaims(ctx, h.c, "")
                
                    accessRequest, err := h.r.OAuth2Provider().NewAccessRequest(ctx, r, session)
                Severity: Minor
                Found in oauth2/handler.go - About 1 hr to fix

                  Method Handler.oAuth2Authorize has 10 return statements (exceeds 4 allowed).
                  Open

                  func (h *Handler) oAuth2Authorize(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
                      ctx := r.Context()
                  
                      authorizeRequest, err := h.r.OAuth2Provider().NewAuthorizeRequest(ctx, r)
                      if err != nil {
                  Severity: Major
                  Found in oauth2/handler.go - About 1 hr to fix

                    Method Handler.getOidcUserInfo has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func (h *Handler) getOidcUserInfo(w http.ResponseWriter, r *http.Request) {
                        ctx := r.Context()
                        session := NewSessionWithCustomClaims(ctx, h.c, "")
                        tokenType, ar, err := h.r.OAuth2Provider().IntrospectToken(ctx, fosite.AccessTokenFromRequest(r), fosite.AccessToken, session)
                        if err != nil {
                    Severity: Minor
                    Found in oauth2/handler.go - About 45 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

                    Method Handler.getOidcUserInfo has 6 return statements (exceeds 4 allowed).
                    Open

                    func (h *Handler) getOidcUserInfo(w http.ResponseWriter, r *http.Request) {
                        ctx := r.Context()
                        session := NewSessionWithCustomClaims(ctx, h.c, "")
                        tokenType, ar, err := h.r.OAuth2Provider().IntrospectToken(ctx, fosite.AccessTokenFromRequest(r), fosite.AccessToken, session)
                        if err != nil {
                    Severity: Major
                    Found in oauth2/handler.go - About 40 mins to fix

                      Method Handler.introspectOAuth2Token has 5 return statements (exceeds 4 allowed).
                      Open

                      func (h *Handler) introspectOAuth2Token(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
                          ctx := r.Context()
                          session := NewSessionWithCustomClaims(ctx, h.c, "")
                      
                          if r.Method != "POST" {
                      Severity: Major
                      Found in oauth2/handler.go - About 35 mins to fix

                        Method Handler.performOidcFrontOrBackChannelLogout has 5 return statements (exceeds 4 allowed).
                        Open

                        func (h *Handler) performOidcFrontOrBackChannelLogout(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
                            ctx := r.Context()
                        
                            handled, err := h.r.ConsentStrategy().HandleOpenIDConnectLogout(ctx, w, r)
                            if errors.Is(err, consent.ErrAbortOAuth2Request) {
                        Severity: Major
                        Found in oauth2/handler.go - About 35 mins to fix

                          Method Handler.oauth2TokenExchange has 5 return statements (exceeds 4 allowed).
                          Open

                          func (h *Handler) oauth2TokenExchange(w http.ResponseWriter, r *http.Request) {
                              ctx := r.Context()
                              session := NewSessionWithCustomClaims(ctx, h.c, "")
                          
                              accessRequest, err := h.r.OAuth2Provider().NewAccessRequest(ctx, r, session)
                          Severity: Major
                          Found in oauth2/handler.go - About 35 mins to fix

                            Method Handler.createVerifiableCredential has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                            Open

                            func (h *Handler) createVerifiableCredential(w http.ResponseWriter, r *http.Request) {
                                ctx := r.Context()
                                session := NewSessionWithCustomClaims(ctx, h.c, "")
                                accessToken := fosite.AccessTokenFromRequest(r)
                                tokenType, _, err := h.r.OAuth2Provider().IntrospectToken(ctx, accessToken, fosite.AccessToken, session)
                            Severity: Minor
                            Found in oauth2/handler.go - About 25 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

                            Identical blocks of code found in 2 locations. Consider refactoring.
                            Open

                                if e := &(fosite.RFC6749Error{}); errors.As(err, &e) {
                                    x.LogAudit(r, err, h.r.AuditLogger())
                                    h.writeAuthorizeError(w, r, authorizeRequest, err)
                                    return
                                } else if err != nil {
                            Severity: Minor
                            Found in oauth2/handler.go and 1 other location - About 50 mins to fix
                            oauth2/handler.go on lines 1066..1074

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 120.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            Identical blocks of code found in 2 locations. Consider refactoring.
                            Open

                                } else if e := &(fosite.RFC6749Error{}); errors.As(err, &e) {
                                    x.LogAudit(r, err, h.r.AuditLogger())
                                    h.writeAuthorizeError(w, r, authorizeRequest, err)
                                    return
                                } else if err != nil {
                            Severity: Minor
                            Found in oauth2/handler.go and 1 other location - About 50 mins to fix
                            oauth2/handler.go on lines 1102..1110

                            Duplicated Code

                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                            Tuning

                            This issue has a mass of 120.

                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                            Refactorings

                            Further Reading

                            There are no issues that match your filters.

                            Category
                            Status