1
0
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:
Costa Huang
2018-11-29 14:46:01 -05:00
parent 2e01ec7746
commit 4542745118
8 changed files with 133 additions and 78 deletions

View 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()
}
}