diff --git a/.gitignore b/.gitignore index fa6217cc..6ecbfdf9 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,6 @@ dist/ downloads/ eggs/ .eggs/ -/lib/ lib64/ parts/ sdist/ diff --git a/gotrue/.gitignore b/gotrue/.gitignore index c6814621..b4a49a4a 100644 --- a/gotrue/.gitignore +++ b/gotrue/.gitignore @@ -29,7 +29,6 @@ dist/ downloads/ eggs/ .eggs/ -/lib/ lib64/ parts/ sdist/ diff --git a/gotrue/__init__.py b/gotrue/__init__.py index db4869e2..a0a2bbc1 100644 --- a/gotrue/__init__.py +++ b/gotrue/__init__.py @@ -1,6 +1,5 @@ __version__ = '0.2.0' -from . import lib from . import api from . import client from .client import Client diff --git a/gotrue/lib/__init__.py b/gotrue/lib/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/gotrue/lib/constants.py b/gotrue/lib/constants.py new file mode 100644 index 00000000..bd4f7f0b --- /dev/null +++ b/gotrue/lib/constants.py @@ -0,0 +1,12 @@ +GOTRUE_URL = 'http://localhost:9999' +AUDIENCE = '' +DEFAULT_HEADERS = {} +EXPIRY_MARGIN = 60 * 1000 +STORAGE_KEY = 'supabase.auth.token' +COOKIE_OPTIONS = { + "name": 'sb:token', + "lifetime": 60 * 60 * 8, + "domain": '', + "path": '/', + "sameSite": 'lax', + } diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index b42520ce..5865a8ef 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -1,30 +1,99 @@ # docker-compose.yml version: '3' services: - gotrue: + gotrue: # Signup enabled, autoconfirm off image: supabase/gotrue:latest ports: - '9999:9999' environment: - GOTRUE_JWT_SECRET: "37c304f8-51aa-419a-a1af-06154e63707a" + GOTRUE_MAILER_URLPATHS_CONFIRMATION: '/verify' + GOTRUE_JWT_SECRET: '37c304f8-51aa-419a-a1af-06154e63707a' GOTRUE_JWT_EXP: 3600 GOTRUE_DB_DRIVER: postgres DB_NAMESPACE: auth - API_EXTERNAL_URL: http://localhost GOTRUE_API_HOST: 0.0.0.0 PORT: 9999 - GOTRUE_DISABLE_SIGNUP: "false" - GOTRUE_SITE_URL: http://localhost - GOTRUE_MAILER_AUTOCONFIRM: "true" + GOTRUE_DISABLE_SIGNUP: 'false' + API_EXTERNAL_URL: http://localhost:9999 + GOTRUE_SITE_URL: http://localhost:9999 + GOTRUE_URI_ALLOW_LIST: https://supabase.io/docs + GOTRUE_MAILER_AUTOCONFIRM: 'false' GOTRUE_LOG_LEVEL: DEBUG GOTRUE_OPERATOR_TOKEN: super-secret-operator-token - DATABASE_URL: "postgres://postgres:postgres@db:5432/postgres?sslmode=disable" - GOTRUE_EXTERNAL_GOOGLE_ENABLED: "true" + DATABASE_URL: 'postgres://postgres:postgres@db:5432/postgres?sslmode=disable' + GOTRUE_EXTERNAL_GOOGLE_ENABLED: 'true' GOTRUE_EXTERNAL_GOOGLE_CLIENT_ID: 53566906701-bmhc1ndue7hild39575gkpimhs06b7ds.apps.googleusercontent.com GOTRUE_EXTERNAL_GOOGLE_SECRET: Sm3s8RE85rDcS36iMy8YjrpC GOTRUE_EXTERNAL_GOOGLE_REDIRECT_URI: http://localhost:9999/callback + GOTRUE_SMTP_HOST: mail + GOTRUE_SMTP_PORT: 2500 + GOTRUE_SMTP_USER: GOTRUE_SMTP_USER + GOTRUE_SMTP_PASS: GOTRUE_SMTP_PASS + GOTRUE_SMTP_ADMIN_EMAIL: admin@email.com + GOTRUE_MAILER_SUBJECTS_CONFIRMATION: 'Please confirm' + GOTRUE_EXTERNAL_PHONE_ENABLED: 'true' + GOTRUE_SMS_PROVIDER: "twilio" + GOTRUE_SMS_TWILIO_ACCOUNT_SID: "${GOTRUE_SMS_TWILIO_ACCOUNT_SID}" + GOTRUE_SMS_TWILIO_AUTH_TOKEN: "${GOTRUE_SMS_TWILIO_AUTH_TOKEN}" + GOTRUE_SMS_TWILIO_MESSAGE_SERVICE_SID: "${GOTRUE_SMS_TWILIO_MESSAGE_SERVICE_SID}" + GOTRUE_SMS_AUTOCONFIRM: 'false' depends_on: - db + restart: on-failure + autoconfirm: # Signup enabled, autoconfirm on + image: supabase/gotrue:latest + ports: + - '9998:9998' + environment: + GOTRUE_JWT_SECRET: '37c304f8-51aa-419a-a1af-06154e63707a' + GOTRUE_JWT_EXP: 3600 + GOTRUE_DB_DRIVER: postgres + DB_NAMESPACE: auth + GOTRUE_API_HOST: 0.0.0.0 + PORT: 9998 + GOTRUE_DISABLE_SIGNUP: 'false' + API_EXTERNAL_URL: http://localhost:9998 + GOTRUE_SITE_URL: http://localhost:9998 + GOTRUE_MAILER_AUTOCONFIRM: 'true' + GOTRUE_SMS_AUTOCONFIRM: 'true' + GOTRUE_LOG_LEVEL: DEBUG + GOTRUE_OPERATOR_TOKEN: super-secret-operator-token + DATABASE_URL: 'postgres://postgres:postgres@db:5432/postgres?sslmode=disable' + GOTRUE_EXTERNAL_PHONE_ENABLED: 'true' + GOTRUE_SMS_AUTOCONFIRM: 'true' + depends_on: + - db + restart: on-failure + disabled: # Signup disabled + image: supabase/gotrue:latest + ports: + - '9997:9997' + environment: + GOTRUE_JWT_SECRET: '37c304f8-51aa-419a-a1af-06154e63707a' + GOTRUE_JWT_EXP: 3600 + GOTRUE_DB_DRIVER: postgres + DB_NAMESPACE: auth + GOTRUE_API_HOST: 0.0.0.0 + PORT: 9997 + GOTRUE_DISABLE_SIGNUP: 'true' + GOTRUE_ENABLE_SIGNUP: 'false' + API_EXTERNAL_URL: http://localhost:9997 + GOTRUE_SITE_URL: http://localhost:9997 + GOTRUE_MAILER_AUTOCONFIRM: 'false' + GOTRUE_LOG_LEVEL: DEBUG + GOTRUE_OPERATOR_TOKEN: super-secret-operator-token + DATABASE_URL: 'postgres://postgres:postgres@db:5432/postgres?sslmode=disable' + GOTRUE_EXTERNAL_PHONE_ENABLED: 'false' + GOTRUE_EXTERNAL_EMAIL_ENABLED: 'false' + depends_on: + - db + restart: on-failure + mail: + image: phamhieu/inbucket:latest + ports: + - '2500:2500' # SMTP + - '9000:9000' # web interface + - '1100:1100' # POP3 db: image: supabase/postgres ports: @@ -35,4 +104,4 @@ services: POSTGRES_DB: postgres POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - POSTGRES_PORT: 5432 \ No newline at end of file + POSTGRES_PORT: 5432 diff --git a/tests/test_gotrue.py b/tests/test_gotrue.py index df637a2d..d6ab4129 100644 --- a/tests/test_gotrue.py +++ b/tests/test_gotrue.py @@ -1,3 +1,4 @@ +from gotrue.lib.constants import GOTRUE_URL from gotrue.client import Client import os import random @@ -9,7 +10,8 @@ def _random_string(length: int = 10) -> str: """Generate random string.""" - return "".join(random.choices(string.ascii_uppercase + string.digits, k=length)) + return "".join( + random.choices(string.ascii_uppercase + string.digits, k=length)) def _assert_authenticated_user(data: Dict[str, Any]): @@ -29,11 +31,22 @@ def client(): supabase_url: str = os.environ.get("SUPABASE_TEST_URL") supabase_key: str = os.environ.get("SUPABASE_TEST_KEY") - url: str = f"{supabase_url}/auth/v1" - return Client( - url=url, - headers={"apiKey": supabase_key, "Authorization": f"Bearer {supabase_key}"}, - ) + if supabase_url and supabase_key: + url: str = f"{supabase_url}/auth/v1" + return Client( + url=url, + headers={ + "apiKey": supabase_key, + "Authorization": f"Bearer {supabase_key}" + }, + ) + else: + return Client( + url=GOTRUE_URL, + headers={ + "Authorization": + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicm9sZSI6InN1cGFiYXNlX2FkbWluIiwiaWF0IjoxNTE2MjM5MDIyfQ.0sOtTSTfPv5oPZxsjvBO249FI4S4p0ymHoIZ6H6z9Y8" + }) def test_user_auth_flow(client: Client):