1
0
mirror of https://github.com/vwxyzjn/portwarden synced 2025-12-22 18:43:13 +00:00

API-6 # Add middleware to verify token

This commit is contained in:
Costa Huang
2018-12-01 01:45:35 -05:00
parent ad3cb2a185
commit 094966f20e
5 changed files with 61 additions and 55 deletions

View File

@@ -10,7 +10,11 @@ import (
)
const (
ErrRetrievingOauthCode = "error retrieving oauth login credentials; try again"
ErrRetrievingOauthCode = "error retrieving oauth login credentials; try again"
ErrCreatingPortwardenUser = "error creating a portwarden user"
FrontEndBaseAddressTest = "http://localhost:8000/"
FrontEndBaseAddressProd = ""
)
func EncryptBackupHandler(c *gin.Context) {
@@ -51,14 +55,15 @@ func (ps *PortwardenServer) GetGoogleDriveLoginHandler(c *gin.Context) {
c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error(), "message": "Login failure"})
return
}
// pu := &PortwardenUser{GoogleToken: tok}
body, err := GetUserInfo(tok)
pu := &PortwardenUser{GoogleToken: tok}
err = pu.CreateWithGoogle()
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": ""})
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error(), "message": ErrCreatingPortwardenUser})
return
}
spew.Dump(string(body))
c.JSON(200, "Login Successful")
spew.Dump(pu)
c.Redirect(http.StatusMovedPermanently, FrontEndBaseAddressTest+"?access_token="+pu.GoogleToken.AccessToken)
return
}