mirror of
https://github.com/vwxyzjn/portwarden
synced 2026-01-06 00:53:13 +00:00
API-6 # Save work
This commit is contained in:
28
web/scheduler/server/middleware.go
Normal file
28
web/scheduler/server/middleware.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
func TokenAuthMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
code := c.Query("code")
|
||||
|
||||
tok, err := GoogleDriveAppConfig.Exchange(oauth2.NoContext, code)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error(), "message": "Login failure"})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
_, err = GetUserInfo(tok)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error(), "message": "Login failure"})
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user