Skip to content

Fix: Implement Validate Method in ZitadelStrategy #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 4, 2025

Conversation

EngineerNV
Copy link
Contributor

Fix: Implement PassportStrategy's Abstract validate Method in ZitadelStrategy

Problem:

When a developer tries to run the server with npm run start:dev - they run into an exception error
ERROR in ./libs/zitadel-auth/src/strategy/zitadel.strategy.ts:9:14
TS2515: Non-abstract class 'ZitadelStrategy' does not implement inherited abstract member validate from class 'ZitadelIntrospectionStrategy & PassportStrategyMixin'.

`     7 `|`
     8 | @Injectable()
  >  9 | export class ZitadelStrategy extends PassportStrategy(
       |              ^^^^^^^^^^^^^^^
    10 |   ZitadelIntrospectionStrategy,
    11 |   'zitadel',
    12 | ) {

Solution:

This patch addresses a critical requirement by implementing the abstract validate method within the ZitadelStrategy class. The validate method is mandated by the PassportStrategyMixin abstract class, which is part of the @nestjs/passport library. By implementing this method, we ensure that our Zitadel authentication strategy correctly adheres to the Passport framework's expected structure and lifecycle.

Currently, the implemented validate method performs a minimal operation: it receives the user payload (of type ZitadelUser) and returns it without modification. This provides a functional baseline that satisfies the abstract method's requirement.

Changes:

  • Implemented the validate method in zitadel.strategy.ts, fulfilling the abstract method requirement from PassportStrategyMixin.

Rationale:

The validate method serves as the hook for processing and validating user information retrieved from the authentication provider (in this case, ZITADEL). By implementing this method, we gain the ability to:

  • Transform the user data into a format suitable for our application.
  • Perform custom validation checks to ensure the user meets specific criteria.
  • Enrich the user object with additional information from other data sources (e.g., a database).

This initial implementation provides a necessary foundation for future enhancements to the Zitadel authentication strategy.

Next Steps:

  • Review the current implementation to ensure it aligns with the project's coding standards and security best practices.
  • Evaluate the need for custom validation logic or user enrichment within the validate method based on application requirements.

Implement the abstract `validate` method in `ZitadelStrategy`, as required by the `PassportStrategyMixin` class from `@nestjs/passport`. The `validate` method currently returns the user payload as-is, providing a foundation for future custom validation or user enrichment.
@tafaust tafaust added the enhancement New feature or request label Mar 31, 2025
@tafaust tafaust self-assigned this Mar 31, 2025
@tafaust tafaust self-requested a review March 31, 2025 18:28
Adding in missing import for the validate function
@tafaust tafaust merged commit 483188f into ehwplus:main Apr 4, 2025
@tafaust
Copy link
Collaborator

tafaust commented Apr 4, 2025

Thanks for the contribution!

@EngineerNV EngineerNV deleted the patch-1 branch April 7, 2025 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants