Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(platform): Enable auth on local-backend mode by default #8405

Merged
merged 10 commits into from
Oct 23, 2024
4 changes: 2 additions & 2 deletions autogpt_platform/backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ PYRO_HOST=localhost
SENTRY_DSN=

## User auth with Supabase is required for any of the 3rd party integrations with auth to work.
ENABLE_AUTH=false
ENABLE_AUTH=true
majdyz marked this conversation as resolved.
Show resolved Hide resolved
SUPABASE_URL=http://localhost:8000
SUPABASE_SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q
SUPABASE_JWT_SECRET=your-super-secret-jwt-token-with-at-least-32-characters-long

# For local development, you may need to set FRONTEND_BASE_URL for the OAuth flow for integrations to work.
# FRONTEND_BASE_URL=http://localhost:3000
FRONTEND_BASE_URL=http://localhost:3000

## == INTEGRATION CREDENTIALS == ##
# Each set of server side credentials is required for the corresponding 3rd party
Expand Down
5 changes: 3 additions & 2 deletions autogpt_platform/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,18 @@ We use the Poetry to manage the dependencies. To set up the project, follow thes
6. Migrate the database. Be careful because this deletes current data in the database.

```sh
docker compose up db redis -d
docker compose up db -d
poetry run prisma migrate deploy
```

## Running The Server

### Starting the server without Docker

Run the following command to build the dockerfiles:
Run the following command to run database in docker but the application locally:

```sh
ntindle marked this conversation as resolved.
Show resolved Hide resolved
docker compose --profile local up deps --build --detach
poetry run app
```

Expand Down
24 changes: 11 additions & 13 deletions autogpt_platform/backend/backend/data/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,17 @@ async def get_user_by_id(user_id: str) -> Optional[User]:
return User.model_validate(user) if user else None


async def create_default_user(enable_auth: str) -> Optional[User]:
if not enable_auth.lower() == "true":
user = await prisma.user.find_unique(where={"id": DEFAULT_USER_ID})
if not user:
user = await prisma.user.create(
data={
"id": DEFAULT_USER_ID,
"email": "[email protected]",
"name": "Default User",
}
)
return User.model_validate(user)
return None
async def create_default_user() -> Optional[User]:
user = await prisma.user.find_unique(where={"id": DEFAULT_USER_ID})
if not user:
user = await prisma.user.create(
data={
"id": DEFAULT_USER_ID,
"email": "[email protected]",
"name": "Default User",
}
)
return User.model_validate(user)


async def get_user_metadata(user_id: str) -> UserMetadataRaw:
Expand Down
4 changes: 2 additions & 2 deletions autogpt_platform/backend/backend/server/ws_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def lifespan(app: FastAPI):


docs_url = "/docs" if settings.config.app_env == AppEnvironment.LOCAL else None
app = FastAPI(lifespan=lifespan)
app = FastAPI(lifespan=lifespan, docs_url=docs_url)
_connection_manager = None

logger.info(f"CORS allow origins: {settings.config.backend_cors_allow_origins}")
Expand Down Expand Up @@ -66,7 +66,7 @@ async def event_broadcaster(manager: ConnectionManager):


async def authenticate_websocket(websocket: WebSocket) -> str:
if settings.config.enable_auth.lower() == "true":
if settings.config.enable_auth:
token = websocket.query_params.get("token")
if not token:
await websocket.close(code=4001, reason="Missing authentication token")
Expand Down
6 changes: 3 additions & 3 deletions autogpt_platform/backend/backend/util/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):
default="localhost",
description="The default hostname of the Pyro server.",
)
enable_auth: str = Field(
default="false",
enable_auth: bool = Field(
default=True,
description="If authentication is enabled or not",
)
enable_credit: str = Field(
Expand Down Expand Up @@ -133,7 +133,7 @@ class Config(UpdateTrackingModel["Config"], BaseSettings):
)

frontend_base_url: str = Field(
default="",
default="http://localhost:3000",
description="Can be used to explicitly set the base URL for the frontend. "
"This value is then used to generate redirect URLs for OAuth flows.",
)
Expand Down
2 changes: 1 addition & 1 deletion autogpt_platform/backend/backend/util/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def __aenter__(self):

await db.connect()
await initialize_blocks()
await create_default_user("false")
await create_default_user()

return self

Expand Down
3 changes: 3 additions & 0 deletions autogpt_platform/backend/test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os

os.environ["ENABLE_AUTH"] = "false"
majdyz marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 21 additions & 0 deletions autogpt_platform/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,24 @@ services:
extends:
file: ./supabase/docker/docker-compose.yml
service: vector

deps:
<<: *supabase-services
profiles:
- local
image: busybox
command: /bin/true
majdyz marked this conversation as resolved.
Show resolved Hide resolved
depends_on:
- studio
- kong
- auth
- rest
- realtime
- storage
- imgproxy
- meta
- functions
- analytics
- db
- vector
- redis
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,10 @@ export default class BaseAutoGPTServerAPI {

if (
response.status === 403 &&
response.statusText === "Not authenticated" &&
typeof window !== "undefined" // Check if in browser environment
) {
window.location.href = "/login";
return null;
}

let errorDetail;
Expand Down
Loading