Skip to content

Conversation

xixas
Copy link
Contributor

@xixas xixas commented May 20, 2024

Description

Backend

  • Authentication will be done based on the access token of the microsoft account.

Frontend

  • Microsoft Guard applied with scope for backend.
  • Will redirect to microsoft to login if not logged.
  • Set active account and fetch token from session storage.

Summary by CodeRabbit

  • New Features

    • Added Azure Active Directory (AAD) authentication to the application.
    • Introduced new environment variables for Azure Client configuration.
    • Implemented Azure authentication guards and strategies for secure access.
  • Updates

    • Enhanced configuration in angular.json for better resource management.
    • Updated Angular app to include MSAL (Microsoft Authentication Library) for authentication.
    • Improved error handling and token management in various components and services.
  • Bug Fixes

    • Fixed unauthorized access handling by redirecting users appropriately.
  • Documentation

    • Updated example environment files with new Azure configuration settings.
  • Refactor

    • Refactored modules and services to integrate Azure AD authentication seamlessly.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 20, 2024

Walkthrough

The recent updates introduce Azure Active Directory (AAD) authentication to the backend and frontend applications. The backend now includes AAD configuration, dependencies, and authentication guards. The frontend integrates MSAL for enhanced security and user management. Additionally, the Angular app sees improved error handling and token management for API interactions.

Changes

File(s) Change Summary
apps/api/.env.example Updated with Azure Client configuration settings.
apps/api/package.json Added @nestjs/passport, passport, passport-azure-ad dependencies.
apps/api/src/app.module.ts Refactored with ConfigModule, PassportModule, and AzureADStrategy.
apps/api/src/auth/azure-ad.guard.ts Introduced AzureADGuard for AAD authentication.
apps/api/src/auth/azure-ad.strategy.ts Added AzureADStrategy for AAD authentication.
apps/api/src/config/azure.config.ts Provided Azure authentication settings for NestJS.
apps/api/src/modules/summary/summary.resolver.ts Applied AzureADGuard to relevant methods.
apps/portal/angular.json Updated budget values and added fileReplacements.
apps/portal/package.json Included @azure/msal-angular, @azure/msal-browser dependencies.
apps/portal/src/app/app-routing.module.ts Added MsalGuard for route protection.
apps/portal/src/app/app.component.html Conditionally displayed content based on loginDisplay.
apps/portal/src/app/app.component.ts Enhanced authentication logic and lifecycle hooks.
apps/portal/src/app/app.module.ts Integrated MSAL configurations and imports.
apps/portal/src/app/features/file-processor/...component.ts Updated error handling and token management.
apps/portal/src/app/features/transcript-analyzer/...component.ts Enhanced error handling and token management.
apps/portal/src/app/graphql/graphql.service.ts Improved token handling and error management.
apps/portal/src/assets/i18n/en.json Added message for unauthorized access.
apps/portal/src/common/interface.ts Introduced ErrorResponse and ResponseData interfaces.
apps/portal/src/environments/environment.interface.ts Added properties for Azure AD configuration.
apps/portal/src/environments/environment.prod.ts Included Azure AD configuration properties.
apps/portal/src/environments/environment.ts Added Azure AD configuration properties.

🐰 In code we trust, with keys azure blue,
Guarding our apps, both old and new.
Tokens in hand, security tight,
Users can log in, day or night.
With MSAL and Passport, we stand tall,
A safer world, for one and all.
Hopping through code, we answer the call. 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e45616a and ceb5849.
Files ignored due to path filters (2)
  • apps/api/package-lock.json is excluded by !**/package-lock.json
  • apps/portal/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (21)
  • apps/api/.env.example (1 hunks)
  • apps/api/package.json (2 hunks)
  • apps/api/src/app.module.ts (2 hunks)
  • apps/api/src/auth/azure-ad.guard.ts (1 hunks)
  • apps/api/src/auth/azure-ad.strategy.ts (1 hunks)
  • apps/api/src/config/azure.config.ts (1 hunks)
  • apps/api/src/modules/summary/summary.resolver.ts (1 hunks)
  • apps/portal/angular.json (1 hunks)
  • apps/portal/package.json (1 hunks)
  • apps/portal/src/app/app-routing.module.ts (2 hunks)
  • apps/portal/src/app/app.component.html (1 hunks)
  • apps/portal/src/app/app.component.ts (1 hunks)
  • apps/portal/src/app/app.module.ts (2 hunks)
  • apps/portal/src/app/features/file-processor/file-processor.component.ts (4 hunks)
  • apps/portal/src/app/features/transcript-analyzer/transcript-analyzer.component.ts (5 hunks)
  • apps/portal/src/app/graphql/graphql.service.ts (1 hunks)
  • apps/portal/src/assets/i18n/en.json (1 hunks)
  • apps/portal/src/common/interface.ts (1 hunks)
  • apps/portal/src/environments/environment.interface.ts (1 hunks)
  • apps/portal/src/environments/environment.prod.ts (1 hunks)
  • apps/portal/src/environments/environment.ts (1 hunks)
Files skipped from review due to trivial changes (5)
  • apps/api/.env.example
  • apps/portal/angular.json
  • apps/portal/src/common/interface.ts
  • apps/portal/src/environments/environment.prod.ts
  • apps/portal/src/environments/environment.ts
Additional comments not posted (28)
apps/portal/src/environments/environment.interface.ts (4)

2-2: The addition of apiScope is appropriate for Azure AD configuration.


3-3: The addition of redirectUri is correctly implemented for handling OAuth redirections.


4-4: The addition of tenantId is crucial for Azure AD integration and is correctly implemented.


5-5: The addition of clientId is essential for Azure AD application identification and is correctly implemented.

apps/portal/src/app/app.component.html (1)

1-5: The conditional rendering of the <h1> element using *ngIf="loginDisplay" is correctly implemented and aligns with the login display requirements.

apps/api/src/auth/azure-ad.guard.ts (1)

8-11: The implementation of the getRequest method in AzureADGuard correctly extracts the request object from the GraphQL execution context, ensuring proper functioning of the guard.

apps/portal/src/app/app-routing.module.ts (1)

13-13: The addition of MsalGuard to the transcript route is correctly implemented, ensuring that the route is protected and requires authenticated access.

apps/portal/src/assets/i18n/en.json (1)

19-19: The addition of the "UNAUTHORIZED" message in the localization file is clear and aligns with the security enhancements of the application.

apps/api/src/config/azure.config.ts (1)

8-24: The AzureConfig object is well-structured and correctly uses configService.getOrThrow to ensure all necessary Azure AD settings are provided, enhancing the application's robustness and security.

apps/api/src/modules/summary/summary.resolver.ts (1)

15-15: The use of AzureADGuard in the createSummary and findAll methods is correctly implemented, ensuring that these GraphQL endpoints are secured and accessible only to authenticated users.

Also applies to: 23-23

apps/api/src/auth/azure-ad.strategy.ts (1)

8-27: The AzureADStrategy class is correctly implemented with comprehensive configuration for Azure AD authentication. The placeholder in the validate method is appropriate, allowing for customization based on specific user validation needs.

apps/api/src/app.module.ts (5)

17-19: Configuring ConfigModule as global is a good practice for making environment variables available throughout the application.


21-21: Setting the default strategy to 'azure-ad' aligns with the PR's goal to integrate Azure AD authentication.


25-26: Using ConfigService to dynamically set Redis configuration is a robust approach, ensuring flexibility and scalability.


35-35: Conditionally enabling the GraphQL playground in development is a best practice to avoid exposing it in production environments.


11-13: Ensure that the imported AzureADStrategy is properly implemented and tested since it's crucial for the new authentication mechanism.

Verification successful

The AzureADStrategy class is properly implemented in apps/api/src/auth/azure-ad.strategy.ts. It extends PassportStrategy and includes a constructor that configures the Azure AD strategy using settings from AzureConfig. The validate method is also defined, which is crucial for user validation.

  • apps/api/src/auth/azure-ad.strategy.ts: Contains the implementation of AzureADStrategy.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the implementation of AzureADStrategy.

# Test: Search for the implementation of AzureADStrategy. Expect: Proper implementation details.
ast-grep --lang typescript --pattern $'class AzureADStrategy {
  $$$
}'

Length of output: 72



Script:

#!/bin/bash
# Locate the file containing the AzureADStrategy class
fd 'AzureADStrategy.ts' -t f

# If the file is found, display its content to verify the implementation
if [ -f $(fd 'AzureADStrategy.ts' -t f) ]; then
  cat $(fd 'AzureADStrategy.ts' -t f)
fi

Length of output: 107



Script:

#!/bin/bash
# Search for the AzureADStrategy class definition within the codebase
ast-grep --lang typescript --pattern 'class AzureADStrategy { $$$ }'

Length of output: 70



Script:

#!/bin/bash
# Search for any file containing the term AzureADStrategy
rg 'AzureADStrategy'

Length of output: 301



Script:

#!/bin/bash
# Display the content of the AzureADStrategy implementation file
cat apps/api/src/auth/azure-ad.strategy.ts

Length of output: 1280

apps/portal/package.json (1)

27-28: Adding @azure/msal-angular and @azure/msal-browser is essential for integrating Azure AD authentication in the Angular application.

apps/portal/src/app/graphql/graphql.service.ts (3)

15-15: Injecting MsalService to handle authentication in GraphQL services aligns with the PR's objectives to secure API access.


29-49: Properly handling tokens and using catchError to manage errors in GraphQL queries enhances security and robustness.


53-79: The implementation of token handling and error management in GraphQL mutations is well-executed, ensuring secure and reliable data mutations.

apps/portal/src/app/app.module.ts (3)

7-15: Importing and configuring MSAL-related modules and services is crucial for integrating Azure AD authentication in the Angular application.


30-61: The factory functions for MSAL configuration are well-implemented, providing a clean and maintainable way to configure authentication.


79-83: Initializing the MSAL module in the NgModule with custom factory functions ensures that the authentication configuration is centralized and easily manageable.

apps/portal/src/app/app.component.ts (1)

1-17: Importing and using MSAL services and related classes in the main component is essential for handling authentication lifecycle events and token management.

apps/api/package.json (1)

Line range hint 42-61: Adding @nestjs/passport, passport, and passport-azure-ad is crucial for integrating Azure AD authentication in the NestJS application.

apps/portal/src/app/features/transcript-analyzer/transcript-analyzer.component.ts (2)

19-19: Injecting MsalService to handle authentication in the TranscriptAnalyzerComponent aligns with the PR's objectives to secure feature components.


60-91: Properly handling unauthorized errors in the summarizeTranscript method enhances security by ensuring that sensitive operations are protected.

apps/portal/src/app/features/file-processor/file-processor.component.ts (1)

32-32: Injecting MsalService to handle authentication in the FileProcessorComponent aligns with the PR's objectives to secure feature components.

@xixas xixas self-assigned this May 20, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between ceb5849 and ed7c7fe.
Files selected for processing (1)
  • apps/portal/angular.json (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/portal/angular.json

Copy link
Member

@osm-vishnukyatannawar osm-vishnukyatannawar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor change to be done.
Approved for now to be able to merge after the issue is fixed.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between ed7c7fe and 57fa8a7.
Files selected for processing (1)
  • apps/portal/src/app/features/transcript-analyzer/transcript-analyzer.component.ts (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • apps/portal/src/app/features/transcript-analyzer/transcript-analyzer.component.ts

@osm-vishnukyatannawar osm-vishnukyatannawar merged commit 8121967 into main May 20, 2024
@osm-vishnukyatannawar osm-vishnukyatannawar deleted the feat/microsoft-sso branch May 20, 2024 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants