Conversation
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Implements Web3-style (Stellar signature) authentication for the CoopFinance API:
src/modules/auth/auth.module.ts— wires up@nestjs/jwtwithJWT_SECRETfrom config.src/modules/auth/auth.service.ts— in-memory nonce generation (5-minute TTL, keyed by address) and Stellar signature verification viaKeypair.verify()from@stellar/stellar-sdk, plus JWT issuance.src/modules/auth/auth.controller.ts—GET /api/auth/nonce?address=andPOST /api/auth/verify.src/modules/auth/jwt-auth.guard.ts—JwtAuthGuardvalidating theAuthorization: Bearer <token>header.JwtAuthGuard+@ApiBearerAuth()toPOST /api/groups,POST /api/loans, andPATCH /api/loans/:id/status.AuthModuleinAppModule, and imported it intoGroupsModule/LoansModuleso the guard can resolveJwtService.GET /api/groups,GET /api/loans, andGET /api/statspublic/unguarded.Why
All write endpoints were publicly callable with no authentication, allowing anyone to register groups or submit/modify loans. Since CoopFinance is Stellar-native, we use signature-based auth (nonce + Keypair signature) rather than email/password, leveraging the already-installed
@nestjs/jwt/@nestjs/passport/passport-jwtdependencies.Testing
GET /api/auth/nonce?address=<G...>returns a nonce string; sign it client-side withstellar-sdk'sKeypair.sign(), base64-encode the signature, thenPOST /api/auth/verifywith{ address, signedNonce }returns{ accessToken }.POST /api/groups,POST /api/loans,PATCH /api/loans/:id/statusnow return 401 without a validAuthorization: Bearer <token>header, and succeed with a valid token.GET /api/groups,GET /api/loans,GET /api/statsremain accessible without auth./api/docs) shows the bearer-auth lock icon on the guarded routes.Closes #6