feat: add LDAP authentication module with JWT issuance #2074
+179
−0
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.
Pull Request Template
Description:
internal/auth/ldapauth
.Bind(username, password)
authentication against an LDAP server and issues a JWT token upon successful login.Breaking Changes (if applicable):
Additional Information:
github.com/go-ldap/ldap/v3
crypto/rand
,encoding/base64
) with HMAC SHA256 signing.mainFile/main.go
for demo andtestuser.ldif
for testing against a local OpenLDAP instance.Summary
This PR introduces a standalone LDAP authentication module (
internal/auth/ldapauth
) for the GoFr framework. It usesBind(username, password)
to validate users and issues a JWT on successful login.What's Included
ldapauth.go
: Core logic for LDAP authentication and JWT issuanceldapauth_test.go
: Unit tests with mock LDAP dialermain.go
: Demo login flow using/login
routetestuser.ldif
: Sample LDAP user for testingHow to Test
testuser.ldif
:curl -X POST http://localhost:8080/login
-H "Content-Type: application/json"
-d '{"username":"testuser", "password":"testpass"}'
Checklist:
goimport
andgolangci-lint
.