consent/strategy_default.go
File strategy_default.go
has 902 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package consent
Method DefaultStrategy.issueLogoutVerifier
has 140 lines of code (exceeds 50 allowed). Consider refactoring. Open
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
Method DefaultStrategy.verifyAuthentication
has 130 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (s *DefaultStrategy) verifyAuthentication(
ctx context.Context,
w http.ResponseWriter,
r *http.Request,
req fosite.AuthorizeRequester,
Method DefaultStrategy.verifyAuthentication
has a Cognitive Complexity of 38 (exceeds 20 allowed). Consider refactoring. Open
Open
func (s *DefaultStrategy) verifyAuthentication(
ctx context.Context,
w http.ResponseWriter,
r *http.Request,
req fosite.AuthorizeRequester,
- Read upRead up
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
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
- Read upRead up
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
Open
type DefaultStrategy struct {
c *config.DefaultProvider
r InternalRegistry
}
Method DefaultStrategy.forwardAuthenticationRequest
has 77 lines of code (exceeds 50 allowed). Consider refactoring. Open
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."))
}
Method DefaultStrategy.verifyAuthentication
has 22 return statements (exceeds 4 allowed). Open
Open
func (s *DefaultStrategy) verifyAuthentication(
ctx context.Context,
w http.ResponseWriter,
r *http.Request,
req fosite.AuthorizeRequester,
Method DefaultStrategy.issueLogoutVerifier
has 20 return statements (exceeds 4 allowed). Open
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
Method DefaultStrategy.executeBackChannelLogout
has 62 lines of code (exceeds 50 allowed). Consider refactoring. Open
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
Method DefaultStrategy.forwardConsentRequest
has 58 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (s *DefaultStrategy) forwardConsentRequest(
ctx context.Context,
w http.ResponseWriter,
r *http.Request,
ar fosite.AuthorizeRequester,
Method DefaultStrategy.verifyConsent
has 11 return statements (exceeds 4 allowed). Open
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
Method DefaultStrategy.requestAuthentication
has 10 return statements (exceeds 4 allowed). Open
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"), " ")
Method DefaultStrategy.forwardAuthenticationRequest
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
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 {
Method DefaultStrategy.completeLogout
has 8 return statements (exceeds 4 allowed). Open
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 {
Method DefaultStrategy.forwardAuthenticationRequest
has 8 return statements (exceeds 4 allowed). Open
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."))
}
Method DefaultStrategy.forwardConsentRequest
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
ctx context.Context,
w http.ResponseWriter,
r *http.Request,
ar fosite.AuthorizeRequester,
f *flow.Flow,
Method DefaultStrategy.executeBackChannelLogout
has 7 return statements (exceeds 4 allowed). Open
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
Method DefaultStrategy.forwardConsentRequest
has 7 return statements (exceeds 4 allowed). Open
Open
func (s *DefaultStrategy) forwardConsentRequest(
ctx context.Context,
w http.ResponseWriter,
r *http.Request,
ar fosite.AuthorizeRequester,
Method DefaultStrategy.requestConsent
has 6 return statements (exceeds 4 allowed). Open
Open
func (s *DefaultStrategy) requestConsent(
ctx context.Context,
w http.ResponseWriter,
r *http.Request,
ar fosite.AuthorizeRequester,
Method DefaultStrategy.authenticationSession
has 6 return statements (exceeds 4 allowed). Open
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
}
Method DefaultStrategy.verifyAuthentication
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
ctx context.Context,
w http.ResponseWriter,
r *http.Request,
req fosite.AuthorizeRequester,
verifier string,
Method DefaultStrategy.requestConsent
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
ctx context.Context,
w http.ResponseWriter,
r *http.Request,
ar fosite.AuthorizeRequester,
f *flow.Flow,
Method DefaultStrategy.HandleOAuth2AuthorizationRequest
has 5 return statements (exceeds 4 allowed). Open
Open
func (s *DefaultStrategy) HandleOAuth2AuthorizationRequest(
ctx context.Context,
w http.ResponseWriter,
r *http.Request,
req fosite.AuthorizeRequester,
Method DefaultStrategy.ObfuscateSubjectIdentifier
has 5 return statements (exceeds 4 allowed). Open
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()))