diff --git a/.env b/.env index 19c8d17..3bd29d8 100644 --- a/.env +++ b/.env @@ -5,7 +5,7 @@ BASE_URL = https://pb.venbait.in UAEPASS_TOKEN_API = https://stg-id.uaepass.ae/idshub/token UAEPASS_TOKEN_API_PARAM_GRANT_TYPE = authorization_code -UAEPASS_TOKEN_API_PARAM_REDIRECTION_URL = http://localhost:60876 +UAEPASS_TOKEN_API_PARAM_REDIRECTION_URL = http://localhost:55227 UAEPASS_TOKEN_API_AUTHORIZATION_USERNAME = sandbox_stage UAEPASS_TOKEN_API_AUTHORIZATION_PASSWORD = sandbox_stage diff --git a/main.go b/main.go index 21ba74a..8c95ee1 100755 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ import ( firebase "firebase.google.com/go" "firebase.google.com/go/messaging" + "github.com/golang-jwt/jwt/v4" "github.com/joho/godotenv" "github.com/labstack/echo/v5" "github.com/pocketbase/dbx" @@ -1827,7 +1828,30 @@ func main() { } defer tokenResp.Body.Close() - tokenBody, _ := ioutil.ReadAll(tokenResp.Body) + // tokenBody, _ := ioutil.ReadAll(tokenResp.Body) + + fmt.Println("---------- UAEPASS TOKEN API DEBUG ----------") + + fmt.Println("Token API URL:", tokenURL) + fmt.Println("grant_type:", os.Getenv("UAEPASS_TOKEN_API_PARAM_GRANT_TYPE")) + fmt.Println("redirect_uri:", os.Getenv("UAEPASS_TOKEN_API_PARAM_REDIRECTION_URL")) + fmt.Println("code:", reqData.Code) + + fmt.Println("BasicAuth Username:", os.Getenv("UAEPASS_TOKEN_API_AUTHORIZATION_USERNAME")) + fmt.Println("BasicAuth Password:", os.Getenv("UAEPASS_TOKEN_API_AUTHORIZATION_PASSWORD")) + + fmt.Println("Status Code:", tokenResp.StatusCode) + + tokenBodyBytes, err := ioutil.ReadAll(tokenResp.Body) + tokenBody := tokenBodyBytes + + if err != nil { + fmt.Println("Error reading token response body:", err) + } else { + fmt.Println("Raw Token API Response:", string(tokenBodyBytes)) + } + + fmt.Println("--------------------------------------------") var tokenResult struct { AccessToken string `json:"access_token"` @@ -1890,11 +1914,25 @@ func main() { }) } + // Extract exp from PB token + parsed, _, err := new(jwt.Parser).ParseUnverified(token, jwt.MapClaims{}) + if err != nil { + return c.JSON(http.StatusInternalServerError, map[string]interface{}{ + "status": "error", + "message": "Failed to decode token", + "error": err.Error(), + }) + } + + claims := parsed.Claims.(jwt.MapClaims) + exp := claims["exp"] + return c.JSON(http.StatusOK, map[string]interface{}{ - "status": "success", - "message": "User found by UUID", - "token": token, - "data": userDetails, + "status": "success", + "message": "User found by UUID", + "token": token, + "data": user, + "expiresOn": exp, }) } @@ -1931,11 +1969,25 @@ func main() { }) } + // Extract exp from PB token + parsed, _, err := new(jwt.Parser).ParseUnverified(token2, jwt.MapClaims{}) + if err != nil { + return c.JSON(http.StatusInternalServerError, map[string]interface{}{ + "status": "error", + "message": "Failed to decode token", + "error": err.Error(), + }) + } + + claims := parsed.Claims.(jwt.MapClaims) + exp := claims["exp"] + return c.JSON(http.StatusOK, map[string]interface{}{ - "status": "success", - "message": "User found by email and UUID updated", - "token": token2, - "data": userDetails, + "status": "success", + "message": "User found by email and UUID updated", + "token": token2, + "data": userByEmail, + "expiresOn": exp, }) }) diff --git a/pb_data/data.db b/pb_data/data.db index e8816f2..0042580 100644 Binary files a/pb_data/data.db and b/pb_data/data.db differ diff --git a/pb_data/data.db-shm b/pb_data/data.db-shm index fe9ac28..ecbc612 100644 Binary files a/pb_data/data.db-shm and b/pb_data/data.db-shm differ diff --git a/pb_data/data.db-wal b/pb_data/data.db-wal index e69de29..b16c4e2 100644 Binary files a/pb_data/data.db-wal and b/pb_data/data.db-wal differ diff --git a/pb_data/logs.db-shm b/pb_data/logs.db-shm deleted file mode 100644 index fe9ac28..0000000 Binary files a/pb_data/logs.db-shm and /dev/null differ diff --git a/pb_data/logs.db-wal b/pb_data/logs.db-wal deleted file mode 100644 index e69de29..0000000