AkhilSharma90 / Golang-JWT-Gin-Authentication-project

MIT License
59 stars 21 forks source link

{"error":"No Authorization header provided"} shown even for test endpoints #3

Open krapton opened 1 year ago

krapton commented 1 year ago

There seems to be an issue where with recent versions of Gin, all endpoints get protected, even the /api-1 and /api-2 endpoints.

When running the code in the repo with go run main.go and testing with Postman:

GET /api-2 HTTP/1.1
User-Agent: PostmanRuntime/7.31.1
Accept: */*
Postman-Token: d0265184-15e4-46ec-aef6-e7fc553fdac8
Host: localhost:9000
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

HTTP/1.1 500 Internal Server Error
Content-Type: application/json; charset=utf-8
Date: Sun, 26 Feb 2023 18:38:12 GMT
Content-Length: 44

{"error":"No Authorization header provided"}

What am i missing?

umair-bijapure commented 1 year ago

just Comment this line (incomingRoutes.Use(middleware.Authentication()) ) in userRouter file and remove the respective package, and then add the below lines in the same file
incomingRoutes.POST("/users/signup",controller.SignUp()) incomingRoutes.POST("/users/login",controller.Login())

and add this router.Use(middleware.Authentication()) in main.go,did make all those changes please have in main repo

finally post, { "Email":"admin@gmail.com", "First_name":"Admin", "Last_name":"Nowhere", "Password":"Pass@123", "User_type":"ADMIN", "Phone":"87867055852"

}

vivek-101 commented 1 week ago

@umair-bijapure This seems to be not working as what you are suggesting is the remove the authentication from the selective endpoints and make it part on the whole file after combining the endpoints together or maybe your explanation is not upto the mark to resolve the issue.