jasonraimondi/typescript-oauth2-server

View on GitHub

Showing 15 of 21 total issues

Function respondToAccessTokenRequest has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  async respondToAccessTokenRequest(req: RequestInterface, accessTokenTTL: DateInterval): Promise<ResponseInterface> {
    const client = await this.validateClient(req);

    const encryptedAuthCode = this.getRequestParameter("code", req);

Severity: Minor
Found in src/grants/auth_code.grant.ts - About 2 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

AbstractGrant has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

export abstract class AbstractGrant implements GrantInterface {
  protected authCodeRepository?: OAuthAuthCodeRepository;
  protected userRepository?: OAuthUserRepository;
  protected readonly scopeDelimiterString = " ";
  protected readonly supportedGrantTypes: GrantIdentifier[] = [
Severity: Minor
Found in src/grants/abstract/abstract.grant.ts - About 2 hrs to fix

    Function respondToAccessTokenRequest has 52 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async respondToAccessTokenRequest(req: RequestInterface, accessTokenTTL: DateInterval): Promise<ResponseInterface> {
        const client = await this.validateClient(req);
    
        const encryptedAuthCode = this.getRequestParameter("code", req);
    
    
    Severity: Major
    Found in src/grants/auth_code.grant.ts - About 2 hrs to fix

      Function bootstrap has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      async function bootstrap() {
        const prisma = new PrismaClient();
        const authCodeRepository = new AuthCodeRepository(prisma);
        const userRepository = new UserRepository(prisma);
      
      
      Severity: Minor
      Found in example/src/main.ts - About 1 hr to fix

        Function completeAuthorizationRequest has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          async completeAuthorizationRequest(authorizationRequest: AuthorizationRequest): Promise<ResponseInterface> {
            if (!authorizationRequest.user || !authorizationRequest.user?.id) {
              throw OAuthException.badRequest("A user must be set on the AuthorizationRequest");
            }
        
        
        Severity: Minor
        Found in src/grants/implicit.grant.ts - About 1 hr to fix

          Function enableGrantType has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            enableGrantType(toEnable: EnableGrant, accessTokenTTL: DateInterval = new DateInterval("1h")): void {
              if (Array.isArray(toEnable)) {
                const [grantType, ttl] = toEnable;
                accessTokenTTL = ttl;
                toEnable = grantType;
          Severity: Minor
          Found in src/authorization_server.ts - About 1 hr to fix

            Function completeAuthorizationRequest has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              async completeAuthorizationRequest(authorizationRequest: AuthorizationRequest): Promise<ResponseInterface> {
                if (!authorizationRequest.user) {
                  throw OAuthException.badRequest("A user should be set on the authorization request");
                }
            
            
            Severity: Minor
            Found in src/grants/auth_code.grant.ts - About 1 hr to fix

              Function validateAuthorizationRequest has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                async validateAuthorizationRequest(request: RequestInterface): Promise<AuthorizationRequest> {
                  const clientId = this.getQueryStringParameter("client_id", request);
              
                  if (typeof clientId !== "string") {
                    throw OAuthException.invalidParameter("client_id");
              Severity: Minor
              Found in src/grants/auth_code.grant.ts - About 1 hr to fix

                Function validateAuthorizationRequest has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  async validateAuthorizationRequest(request: RequestInterface): Promise<AuthorizationRequest> {
                    const clientId = this.getQueryStringParameter("client_id", request);
                
                    if (typeof clientId !== "string") {
                      throw OAuthException.invalidParameter("client_id");
                Severity: Minor
                Found in src/grants/auth_code.grant.ts - 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

                Function validateOldRefreshToken has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  private async validateOldRefreshToken(request: RequestInterface, clientId: string): Promise<OAuthToken> {
                    const encryptedRefreshToken = this.getRequestParameter("refresh_token", request);
                
                    if (!encryptedRefreshToken) {
                      throw OAuthException.invalidParameter("refresh_token");
                Severity: Minor
                Found in src/grants/refresh_token.grant.ts - About 1 hr to fix

                  Function validateOldRefreshToken has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                    private async validateOldRefreshToken(request: RequestInterface, clientId: string): Promise<OAuthToken> {
                      const encryptedRefreshToken = this.getRequestParameter("refresh_token", request);
                  
                      if (!encryptedRefreshToken) {
                        throw OAuthException.invalidParameter("refresh_token");
                  Severity: Minor
                  Found in src/grants/refresh_token.grant.ts - About 55 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 validateAuthorizationCode has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    private async validateAuthorizationCode(payload: any, client: OAuthClient, request: RequestInterface) {
                      if (!payload.auth_code_id) {
                        throw OAuthException.invalidParameter("code", "Authorization code malformed");
                      }
                  
                  
                  Severity: Minor
                  Found in src/grants/auth_code.grant.ts - 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 completeAuthorizationRequest has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    async completeAuthorizationRequest(authorizationRequest: AuthorizationRequest): Promise<ResponseInterface> {
                      if (!authorizationRequest.user || !authorizationRequest.user?.id) {
                        throw OAuthException.badRequest("A user must be set on the AuthorizationRequest");
                      }
                  
                  
                  Severity: Minor
                  Found in src/grants/implicit.grant.ts - 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

                  Avoid too many return statements within this function.
                  Open

                      return;
                  Severity: Major
                  Found in src/grants/refresh_token.grant.ts - About 30 mins to fix

                    Function enableGrantType has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      enableGrantType(toEnable: EnableGrant, accessTokenTTL: DateInterval = new DateInterval("1h")): void {
                        if (Array.isArray(toEnable)) {
                          const [grantType, ttl] = toEnable;
                          accessTokenTTL = ttl;
                          toEnable = grantType;
                    Severity: Minor
                    Found in src/authorization_server.ts - 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

                    Severity
                    Category
                    Status
                    Source
                    Language