Skip to content
This repository has been archived by the owner on Feb 23, 2022. It is now read-only.

Commit

Permalink
Merge pull request #380 from multinet-app/cors-refinement
Browse files Browse the repository at this point in the history
Enable cross-origin credential transfer to login API
  • Loading branch information
waxlamp committed May 29, 2020
2 parents 2e1856c + 27b1e06 commit 521e464
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .env.default
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ GOOGLE_CLIENT_SECRET=
# Will be set automatically by the server
FLASK_SECRET_KEY=

# Comma separated list of domains that will be allowed to send cookies to the
# server.
ALLOWED_ORIGINS=http://localhost:8080

ARANGO_HOST=localhost
ARANGO_PORT=8529
ARANGO_PROTOCOL=http
15 changes: 13 additions & 2 deletions multinet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flasgger import Swagger
from sentry_sdk.integrations.flask import FlaskIntegration

from typing import Optional, MutableMapping, Any, Tuple, Union
from typing import Optional, MutableMapping, Any, Tuple, Union, List

from multinet import auth
from multinet.auth import google
Expand All @@ -21,10 +21,21 @@
sentry_sdk.init(dsn=sentry_dsn, integrations=[FlaskIntegration()])


def get_allowed_origins() -> List[str]:
"""Read in comma-separated list of allowed origins from environment."""
allowed_origins = os.getenv("ALLOWED_ORIGINS", default=None)
if allowed_origins is None:
return []

return [s.strip() for s in allowed_origins.split(",")]


def create_app(config: Optional[MutableMapping] = None) -> Flask:
"""Create a Multinet app instance."""
app = Flask(__name__)
CORS(app)

allowed_origins = get_allowed_origins()
CORS(app, origins=allowed_origins, supports_credentials=True)
Swagger(app, template_file="swagger/template.yaml")

app.secret_key = flask_secret_key()
Expand Down
9 changes: 8 additions & 1 deletion mypy_stubs/flask_cors.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
from flask import Flask

def CORS(app: Flask) -> None: ...
from typing import Dict, Any, List, Union

def CORS(
app: Flask,
origins: Union[str, List[str]],
supports_credentials: bool,
resources: Dict[str, Dict[str, Any]] = None,
) -> None: ...

0 comments on commit 521e464

Please sign in to comment.