Skip to content
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

Token Verification Enhancements #205

Closed
wants to merge 5 commits into from
Closed

Conversation

gklps
Copy link
Member

@gklps gklps commented Aug 1, 2024

Token Verification Client Enhancements

This pull request enhances the client-side handling of token verification, making it more robust and integrated with the new token verification API.

Key Changes:

  • tokenverification API/Command:

    • A new API /api/validate-token?token={tokenID} & command ./rubixgoplatform validatetoken -token {tokenID}has been created to encapsulate the logic for interacting with the token verification API.
  • TokenVerificationClient:

    • A TokenVerificationClient struct has been introduced to handle API calls and responses.
    • This client leverages the existing webClient for HTTP requests and includes a logger for better observability.
  • Input/Output Interfaces:

    • Clear interfaces (TokenVerificationRequest and TokenVerificationResponse) define the expected format of the API request and response data, enhancing code readability and maintainability.
  • VerifyTokens Function:

    • This function within the TokenVerificationClient handles the core logic of sending the verification request and processing the response.
    • It marshals the token data into JSON, makes the API call, and unmarshals the JSON response.
    • It includes robust error handling to report any issues during the process.
  • Integration into ValidateToken:

    • The ValidateToken function in the core package has been updated to use the TokenVerificationClient to verify tokens.
    • This streamlines the verification process and improves code modularity.
  • IPFS Integration:

    • The ValidateToken function now seamlessly handles reading token hashes from IPFS using an io.ReadCloser and ensures proper newline trimming for correct JSON formatting.
    • This allows for flexible token storage and retrieval mechanisms.

Benefits:

  • TODO - Improved Modularity: The token verification logic is now neatly encapsulated in a separate package, making the code more organized and easier to maintain.
  • Clearer Interfaces: The input and output interfaces enhance code readability and make the API interactions more explicit.
  • Robustness: The code includes comprehensive error handling and input validation to gracefully handle various failure scenarios.

How to Test:

  1. Ensure the token verification server is running.
  2. Use the VerifyTokens function or integrate it into your existing code (like in the ValidateToken example) to make verification requests.
  3. Observe the logs and responses to verify that the token verification is working as expected.

Remember: You might need to adjust the ServerURL in the VerifyTokens function and ensure the ensweb.Client configuration is set up correctly in your TokenVerificationClient to match your actual API endpoint.

@gklps gklps changed the title Ft/gklps/validate token Token Verification Enhancements Aug 1, 2024
@gklps gklps added the enhancement New feature or request label Aug 1, 2024
@gklps gklps closed this Aug 20, 2024
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.

1 participant