Skip to content

An open-source, faster Devin alternative

TypeScript

Add GET /api/me identity endpoint

Igor Zalutski33398b77721e
diff --git a/internal/api/identity.go b/internal/api/identity.go
new file mode 100644
index 00000000..8bc9e242
--- /dev/null
+++ b/internal/api/identity.go
@@ -0,0 +1,29 @@
+package api
+
+import (
+ "net/http"
+
+ "github.com/labstack/echo/v4"
+ "github.com/opensandbox/opensandbox/internal/auth"
+)
+
+// getMe returns the identity (org and optional user) associated with the
+// current API key. Downstream services use this to resolve key → owner.
+func (s *Server) getMe(c echo.Context) error {
+ orgID, ok := auth.GetOrgID(c)
+ if !ok {
+ return c.JSON(http.StatusUnauthorized, map[string]string{
+ "error": "org context required",
+ })
+ }
+
+ resp := map[string]interface{}{
+ "org_id": orgID.String(),
+ }
+
+ if userID := auth.GetUserID(c); userID != nil {
+ resp["user_id"] = userID.String()
+ }
+
+ return c.JSON(http.StatusOK, resp)
+}
diff --git a/internal/api/router.go b/internal/api/router.go
index 30c2395e..5591ea9b 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -187,6 +187,9 @@ func NewServer(mgr sandbox.Manager, ptyMgr *sandbox.PTYManager, apiKey string, o
api := e.Group("/api")
api.Use(auth.PGAPIKeyMiddleware(s.store, apiKey))
+ // Identity
+ api.GET("/me", s.getMe)
+
// Sandbox lifecycle
api.POST("/sandboxes", s.createSandbox)
api.GET("/sandboxes", s.listSandboxes)