Open Dialvive opened 3 years ago
The routes that use x-api-key
are for development only?
If that's the case then I'm stuck with something else :cry:
Suppose the following routes:
GET /foo -> public
POST /foo -> dev only
DELETE /foo -> dev only
GET /bar -> public
POST /bar -> dev only
DELETE /bar -> dev only
How should I create the groups, I've designed 3 options with the following middleware to check the api key:
func MustHaveSecretKey(c *gin.Context) {
if c.GetHeader("x-api-key") == "" {
c.AbortWithStatus(http.StatusBadRequest)
}
}
There are two uses for x-api-keys now. Some operations that require x-api-key
are admin-only operations, meaning that the webpage nor regular developers can invoke those operations. Examples of admin-only access:
Admin-only operations will continue to use x-api-key
authentication header.
There are also operations that use the same api key for development purposes, these api key authentication will be deprecated in favor of JWT user authentication. These will be available to the website for user-invoked-operations. Examples of these operations:
One option is to group operations by admin-only, authenticated-user-only, and public-access. Needless to say, authenticated-user-only will only allow operations on the user itself, and not into other users, except when removing friends.
I have updated the issue.
Probably, the best would be to create a middleware for x-api-key
authentication for all admin-only routes, and another middleware that verifies user auth token for authenticated-user-only routes.
I have another doubt
Should I add /
as a prefix, because it can be omitted?
For example, the following code produces the same route /v1/bar
v1 := r.Group("v1")
public := v1.Group("")
public.GET("bar", myfunc)
v1 := r.Group("/v1")
public := v1.Group("/")
public.GET("/bar", myfunc)
It would be better if we explicitly add the '/'
Group routes in: