Golang-JWT-Gin-Authentication-project icon indicating copy to clipboard operation
Golang-JWT-Gin-Authentication-project copied to clipboard

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

Open krapton opened this issue 2 years ago • 1 comments

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?

krapton avatar Feb 26 '23 19:02 krapton

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":"[email protected]", "First_name":"Admin", "Last_name":"Nowhere", "Password":"Pass@123", "User_type":"ADMIN", "Phone":"87867055852"

}

umair-bijapure avatar Apr 05 '23 23:04 umair-bijapure