-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bearer token auth for /decentralized and /rss routers (#436)
- Loading branch information
Showing
8 changed files
with
104 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package middleware | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// BearerAuth middleware for bearer token authentication | ||
func BearerAuth(accessToken string) echo.MiddlewareFunc { | ||
return func(next echo.HandlerFunc) echo.HandlerFunc { | ||
return func(c echo.Context) error { | ||
authHeader := c.Request().Header.Get("Authorization") | ||
if authHeader == "" { | ||
return echo.NewHTTPError(http.StatusUnauthorized, "Missing Authorization header") | ||
} | ||
|
||
// Check if the header starts with "Bearer " | ||
if !strings.HasPrefix(authHeader, "Bearer ") { | ||
return echo.NewHTTPError(http.StatusUnauthorized, "Invalid Authorization header format") | ||
} | ||
|
||
// Extract the token | ||
token := strings.TrimPrefix(authHeader, "Bearer ") | ||
|
||
// Verify the token | ||
if token != accessToken { | ||
return echo.NewHTTPError(http.StatusUnauthorized, "Invalid access token") | ||
} | ||
|
||
return next(c) | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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