ory-am/hydra

View on GitHub
consent/strategy_default.go

Summary

Maintainability
F
6 days
Test Coverage

File strategy_default.go has 902 lines of code (exceeds 500 allowed). Consider refactoring.
Open

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

package consent

Severity: Major
Found in consent/strategy_default.go - About 1 day to fix

    Method DefaultStrategy.issueLogoutVerifier has 140 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (s *DefaultStrategy) issueLogoutVerifier(ctx context.Context, w http.ResponseWriter, r *http.Request) (*flow.LogoutResult, error) {
        // There are two types of log out flows:
        //
        // - RP initiated logout
        // - OP initiated logout
    Severity: Major
    Found in consent/strategy_default.go - About 4 hrs to fix

      Method DefaultStrategy.verifyAuthentication has 130 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (s *DefaultStrategy) verifyAuthentication(
          ctx context.Context,
          w http.ResponseWriter,
          r *http.Request,
          req fosite.AuthorizeRequester,
      Severity: Major
      Found in consent/strategy_default.go - About 4 hrs to fix

        Method DefaultStrategy.verifyAuthentication has a Cognitive Complexity of 38 (exceeds 20 allowed). Consider refactoring.
        Open

        func (s *DefaultStrategy) verifyAuthentication(
            ctx context.Context,
            w http.ResponseWriter,
            r *http.Request,
            req fosite.AuthorizeRequester,
        Severity: Minor
        Found in consent/strategy_default.go - About 3 hrs 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 DefaultStrategy.issueLogoutVerifier has a Cognitive Complexity of 38 (exceeds 20 allowed). Consider refactoring.
        Open

        func (s *DefaultStrategy) issueLogoutVerifier(ctx context.Context, w http.ResponseWriter, r *http.Request) (*flow.LogoutResult, error) {
            // There are two types of log out flows:
            //
            // - RP initiated logout
            // - OP initiated logout
        Severity: Minor
        Found in consent/strategy_default.go - About 3 hrs 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

        DefaultStrategy has 22 methods (exceeds 20 allowed). Consider refactoring.
        Open

        type DefaultStrategy struct {
            c *config.DefaultProvider
            r InternalRegistry
        }
        Severity: Minor
        Found in consent/strategy_default.go - About 2 hrs to fix

          Method DefaultStrategy.forwardAuthenticationRequest has 77 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (s *DefaultStrategy) forwardAuthenticationRequest(ctx context.Context, w http.ResponseWriter, r *http.Request, ar fosite.AuthorizeRequester, subject string, authenticatedAt time.Time, session *flow.LoginSession) error {
              if (subject != "" && authenticatedAt.IsZero()) || (subject == "" && !authenticatedAt.IsZero()) {
                  return errorsx.WithStack(fosite.ErrServerError.WithHint("Consent strategy returned a non-empty subject with an empty auth date, or an empty subject with a non-empty auth date."))
              }
          
          
          Severity: Major
          Found in consent/strategy_default.go - About 2 hrs to fix

            Method DefaultStrategy.verifyAuthentication has 22 return statements (exceeds 4 allowed).
            Open

            func (s *DefaultStrategy) verifyAuthentication(
                ctx context.Context,
                w http.ResponseWriter,
                r *http.Request,
                req fosite.AuthorizeRequester,
            Severity: Major
            Found in consent/strategy_default.go - About 2 hrs to fix

              Method DefaultStrategy.issueLogoutVerifier has 20 return statements (exceeds 4 allowed).
              Open

              func (s *DefaultStrategy) issueLogoutVerifier(ctx context.Context, w http.ResponseWriter, r *http.Request) (*flow.LogoutResult, error) {
                  // There are two types of log out flows:
                  //
                  // - RP initiated logout
                  // - OP initiated logout
              Severity: Major
              Found in consent/strategy_default.go - About 1 hr to fix

                Method DefaultStrategy.executeBackChannelLogout has 62 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (s *DefaultStrategy) executeBackChannelLogout(r *http.Request, subject, sid string) error {
                    ctx := r.Context()
                    clients, err := s.r.ConsentManager().ListUserAuthenticatedClientsWithBackChannelLogout(ctx, subject, sid)
                    if err != nil {
                        return err
                Severity: Minor
                Found in consent/strategy_default.go - About 1 hr to fix

                  Method DefaultStrategy.forwardConsentRequest has 58 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (s *DefaultStrategy) forwardConsentRequest(
                      ctx context.Context,
                      w http.ResponseWriter,
                      r *http.Request,
                      ar fosite.AuthorizeRequester,
                  Severity: Minor
                  Found in consent/strategy_default.go - About 1 hr to fix

                    Method DefaultStrategy.verifyConsent has 11 return statements (exceeds 4 allowed).
                    Open

                    func (s *DefaultStrategy) verifyConsent(ctx context.Context, _ http.ResponseWriter, r *http.Request, verifier string) (_ *flow.AcceptOAuth2ConsentRequest, _ *flow.Flow, err error) {
                        ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("").Start(ctx, "DefaultStrategy.verifyConsent")
                        defer otelx.End(span, &err)
                    
                        // We decode the flow here once again because VerifyAndInvalidateConsentRequest does not return the flow
                    Severity: Major
                    Found in consent/strategy_default.go - About 1 hr to fix

                      Method DefaultStrategy.requestAuthentication has 10 return statements (exceeds 4 allowed).
                      Open

                      func (s *DefaultStrategy) requestAuthentication(ctx context.Context, w http.ResponseWriter, r *http.Request, ar fosite.AuthorizeRequester) (err error) {
                          ctx, span := trace.SpanFromContext(ctx).TracerProvider().Tracer("").Start(ctx, "DefaultStrategy.requestAuthentication")
                          defer otelx.End(span, &err)
                      
                          prompt := stringsx.Splitx(ar.GetRequestForm().Get("prompt"), " ")
                      Severity: Major
                      Found in consent/strategy_default.go - About 1 hr to fix

                        Method DefaultStrategy.forwardAuthenticationRequest has 7 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        func (s *DefaultStrategy) forwardAuthenticationRequest(ctx context.Context, w http.ResponseWriter, r *http.Request, ar fosite.AuthorizeRequester, subject string, authenticatedAt time.Time, session *flow.LoginSession) error {
                        Severity: Major
                        Found in consent/strategy_default.go - About 50 mins to fix

                          Method DefaultStrategy.completeLogout has 8 return statements (exceeds 4 allowed).
                          Open

                          func (s *DefaultStrategy) completeLogout(ctx context.Context, w http.ResponseWriter, r *http.Request) (*flow.LogoutResult, error) {
                              verifier := r.URL.Query().Get("logout_verifier")
                          
                              lr, err := s.r.ConsentManager().VerifyAndInvalidateLogoutRequest(r.Context(), verifier)
                              if err != nil {
                          Severity: Major
                          Found in consent/strategy_default.go - About 50 mins to fix

                            Method DefaultStrategy.forwardAuthenticationRequest has 8 return statements (exceeds 4 allowed).
                            Open

                            func (s *DefaultStrategy) forwardAuthenticationRequest(ctx context.Context, w http.ResponseWriter, r *http.Request, ar fosite.AuthorizeRequester, subject string, authenticatedAt time.Time, session *flow.LoginSession) error {
                                if (subject != "" && authenticatedAt.IsZero()) || (subject == "" && !authenticatedAt.IsZero()) {
                                    return errorsx.WithStack(fosite.ErrServerError.WithHint("Consent strategy returned a non-empty subject with an empty auth date, or an empty subject with a non-empty auth date."))
                                }
                            
                            
                            Severity: Major
                            Found in consent/strategy_default.go - About 50 mins to fix

                              Method DefaultStrategy.forwardConsentRequest has 6 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                  ctx context.Context,
                                  w http.ResponseWriter,
                                  r *http.Request,
                                  ar fosite.AuthorizeRequester,
                                  f *flow.Flow,
                              Severity: Minor
                              Found in consent/strategy_default.go - About 45 mins to fix

                                Method DefaultStrategy.executeBackChannelLogout has 7 return statements (exceeds 4 allowed).
                                Open

                                func (s *DefaultStrategy) executeBackChannelLogout(r *http.Request, subject, sid string) error {
                                    ctx := r.Context()
                                    clients, err := s.r.ConsentManager().ListUserAuthenticatedClientsWithBackChannelLogout(ctx, subject, sid)
                                    if err != nil {
                                        return err
                                Severity: Major
                                Found in consent/strategy_default.go - About 45 mins to fix

                                  Method DefaultStrategy.forwardConsentRequest has 7 return statements (exceeds 4 allowed).
                                  Open

                                  func (s *DefaultStrategy) forwardConsentRequest(
                                      ctx context.Context,
                                      w http.ResponseWriter,
                                      r *http.Request,
                                      ar fosite.AuthorizeRequester,
                                  Severity: Major
                                  Found in consent/strategy_default.go - About 45 mins to fix

                                    Method DefaultStrategy.requestConsent has 6 return statements (exceeds 4 allowed).
                                    Open

                                    func (s *DefaultStrategy) requestConsent(
                                        ctx context.Context,
                                        w http.ResponseWriter,
                                        r *http.Request,
                                        ar fosite.AuthorizeRequester,
                                    Severity: Major
                                    Found in consent/strategy_default.go - About 40 mins to fix

                                      Method DefaultStrategy.authenticationSession has 6 return statements (exceeds 4 allowed).
                                      Open

                                      func (s *DefaultStrategy) authenticationSession(ctx context.Context, _ http.ResponseWriter, r *http.Request) (*flow.LoginSession, error) {
                                          store, err := s.r.CookieStore(ctx)
                                          if err != nil {
                                              return nil, err
                                          }
                                      Severity: Major
                                      Found in consent/strategy_default.go - About 40 mins to fix

                                        Method DefaultStrategy.verifyAuthentication has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                        Open

                                            ctx context.Context,
                                            w http.ResponseWriter,
                                            r *http.Request,
                                            req fosite.AuthorizeRequester,
                                            verifier string,
                                        Severity: Minor
                                        Found in consent/strategy_default.go - About 35 mins to fix

                                          Method DefaultStrategy.requestConsent has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                          Open

                                              ctx context.Context,
                                              w http.ResponseWriter,
                                              r *http.Request,
                                              ar fosite.AuthorizeRequester,
                                              f *flow.Flow,
                                          Severity: Minor
                                          Found in consent/strategy_default.go - About 35 mins to fix

                                            Method DefaultStrategy.HandleOAuth2AuthorizationRequest has 5 return statements (exceeds 4 allowed).
                                            Open

                                            func (s *DefaultStrategy) HandleOAuth2AuthorizationRequest(
                                                ctx context.Context,
                                                w http.ResponseWriter,
                                                r *http.Request,
                                                req fosite.AuthorizeRequester,
                                            Severity: Major
                                            Found in consent/strategy_default.go - About 35 mins to fix

                                              Method DefaultStrategy.ObfuscateSubjectIdentifier has 5 return statements (exceeds 4 allowed).
                                              Open

                                              func (s *DefaultStrategy) ObfuscateSubjectIdentifier(ctx context.Context, cl fosite.Client, subject, forcedIdentifier string) (string, error) {
                                                  if c, ok := cl.(*client.Client); ok && c.SubjectType == "pairwise" {
                                                      algorithm, ok := s.r.SubjectIdentifierAlgorithm(ctx)[c.SubjectType]
                                                      if !ok {
                                                          return "", errorsx.WithStack(fosite.ErrInvalidRequest.WithHintf(`Subject Identifier Algorithm '%s' was requested by OAuth 2.0 Client '%s' but is not configured.`, c.SubjectType, c.GetID()))
                                              Severity: Major
                                              Found in consent/strategy_default.go - About 35 mins to fix

                                                There are no issues that match your filters.

                                                Category
                                                Status