Hansi
09/14/2022, 1:52 PMapp_info
values to this:
app_info=InputAppInfo(
app_name="GG-Host",
api_domain="http://backend:8080",
website_domain="http://frontend:3000",
api_base_path="/auth",
website_base_path="/auth"
)
Running with this configuration causes the following error:
supertokens_python.exceptions.GeneralError: Since your API and website domain are different, for sessions to work, please use https on your apiDomain and don't set cookieSecure to false.
I don't want to use https, since this is all local networking within the Docker network. Changing api_domain
to use https instead resolves the error, but the sign up form still errors.rp_st
09/14/2022, 1:54 PMHansi
09/14/2022, 1:54 PMrp_st
09/14/2022, 1:54 PMrp_st
09/14/2022, 1:54 PMHansi
09/14/2022, 1:55 PMrp_st
09/14/2022, 1:55 PMhttp://localhost:3000
rp_st
09/14/2022, 1:55 PMHansi
09/14/2022, 1:56 PMhttp://backend:8080
rp_st
09/14/2022, 1:57 PMHansi
09/14/2022, 1:58 PMrp_st
09/14/2022, 1:58 PMHansi
09/14/2022, 1:58 PMHansi
09/14/2022, 1:59 PMrp_st
09/14/2022, 2:05 PMHansi
09/14/2022, 2:06 PMHansi
09/14/2022, 2:07 PMhttp://frontend:3000
. This circles back to the initial problem with httpsrp_st
09/14/2022, 2:07 PMrp_st
09/14/2022, 2:08 PMHansi
09/14/2022, 2:10 PMINFO:werkzeug:172.26.0.1 - - [14/Sep/2022 14:08:54] "OPTIONS /auth/session/refresh HTTP/1.1" 404 -
INFO:werkzeug:172.26.0.1 - - [14/Sep/2022 14:09:00] "OPTIONS /auth/session/refresh HTTP/1.1" 404 -
INFO:werkzeug:172.26.0.1 - - [14/Sep/2022 14:09:00] "OPTIONS /auth/signin HTTP/1.1" 404 -
rp_st
09/14/2022, 2:10 PMrp_st
09/14/2022, 2:11 PMrp_st
09/14/2022, 2:11 PMHansi
09/14/2022, 2:11 PMINFO:werkzeug:172.26.0.1 - - [14/Sep/2022 14:10:27] "OPTIONS /auth/session/refresh HTTP/1.1" 404 -
INFO:werkzeug:172.26.0.1 - - [14/Sep/2022 14:10:30] "OPTIONS /auth/session/refresh HTTP/1.1" 404 -
INFO:werkzeug:172.26.0.1 - - [14/Sep/2022 14:10:31] "OPTIONS /auth/signup/email/exists?email=elneff%40pm.me HTTP/1.1" 404 -
INFO:werkzeug:172.26.0.1 - - [14/Sep/2022 14:10:33] "OPTIONS /auth/session/refresh HTTP/1.1" 404 -
INFO:werkzeug:172.26.0.1 - - [14/Sep/2022 14:10:33] "OPTIONS /auth/signup HTTP/1.1" 404 -
I will check the network tab nowrp_st
09/14/2022, 2:12 PMrp_st
09/14/2022, 2:12 PMHansi
09/14/2022, 2:12 PMrp_st
09/14/2022, 2:12 PMrp_st
09/14/2022, 2:12 PMrp_st
09/14/2022, 2:13 PMHansi
09/14/2022, 2:13 PMdef add_supertokens_apis(app):
""""Add SuperTokens API to Flask app"""
Middleware(app)
# TODO: Add APIs
CORS(
app=app,
origins=[
"https://localhost:3000"
],
supports_credentials=True,
allow_headers=["Content-Type"] + get_all_cors_headers(),
)
Hansi
09/14/2022, 2:13 PMif __name__ == '__main__':
logging.basicConfig(
# filename='gamehost.log'
encoding='utf-8',
level=logging.INFO
)
# Start Connexion
app = connexion.App(__name__, options={'swagger_ui': True})
supertokens.add_supertokens_apis(app.app)
app.add_api('openapi.yml')
app.run(server='flask', host='0.0.0.0', port=8080)
rp_st
09/14/2022, 2:14 PMrp_st
09/14/2022, 2:14 PMrp_st
09/14/2022, 2:15 PMHansi
09/14/2022, 2:16 PMrp_st
09/14/2022, 2:17 PMHansi
09/14/2022, 2:30 PM14 Sep 2022 14:24:56:951 +0000 | INFO | pid: 56ca2e82-56c5-4a29-8e3d-b1d9a92c0fb2 | [http-nio-0.0.0.0-3567-exec-1] thread | io.supertokens.webserver.WebserverAPI.service(WebserverAPI.java:184) | API ended: /hello. Method: GET
It seems to just be an info log, but it's printed way too often for my liking, filling up my terminal. Is there any way to disable it?rp_st
09/14/2022, 2:30 PMrp_st
09/14/2022, 2:31 PMHansi
09/14/2022, 2:32 PMHansi
09/14/2022, 2:43 PMAccess-Control-Allow-Origin
header is not set in the request. Am I supposed to set this somewhere? Printing the result of get_all_cors_headers()
shows the following list: ['anti-csrf', 'rid', 'fdi-version']
rp_st
09/14/2022, 2:44 PMrp_st
09/14/2022, 2:44 PMrp_st
09/14/2022, 2:44 PMHansi
09/14/2022, 2:45 PMrp_st
09/14/2022, 2:45 PMrp_st
09/14/2022, 2:45 PMHansi
09/14/2022, 2:51 PMapp.app
to get the Flask app and enable CORS that way, like in the example you sent.
I will post my code here, in case it helps KShivendu spot something
python
if __name__ == '__main__':
# Start Connexion
app = connexion.App(__name__, options={'swagger_ui': True})
app.add_api('openapi.yml')
Middleware(app.app)
CORS(
app=app.app,
origins=[
"https://localhost:3000"
],
supports_credentials=True,
allow_headers=["Content-Type"] + get_all_cors_headers(),
)
print('CORS headers:', str(get_all_cors_headers()))
app.run(host='0.0.0.0', port=8080)
KShivendu
09/14/2022, 3:27 PMopenapi.yml
file. They also return CORS error (while the registered ones succeed). So I think the issue is related to connexion.
give me some time, I'll try to figure something to fix it.Hansi
09/14/2022, 3:28 PMHansi
09/14/2022, 3:31 PMHansi
09/14/2022, 3:31 PMHansi
09/14/2022, 3:38 PMhttp://localhost:8080/auth/session/refresh
This makes the backend log:
INFO:werkzeug:172.26.0.1 - - [14/Sep/2022 15:36:45] "GET /auth/session/refresh HTTP/1.1" 404 -
INFO:werkzeug:172.26.0.1 - - [14/Sep/2022 15:36:46] "GET /favicon.ico HTTP/1.1" 404 -
Hansi
09/14/2022, 3:51 PMFlask==2.2.2
to Flask==2.1.3
in order to use Werkzeug==2.0.3
, which supertokens-python==0.10.4
(latest version) requires. Though I doubt this is related to the issue at hand.KShivendu
09/14/2022, 3:51 PM/auth/session/refresh
expects POST requestHansi
09/14/2022, 3:51 PMKShivendu
09/14/2022, 3:51 PMfetch("http://localhost:8000/auth/session/refresh", {method: "POST"}).then(res => res.text()).then(console.log)
try thisHansi
09/14/2022, 3:52 PMKShivendu
09/14/2022, 3:53 PMHansi
09/14/2022, 3:54 PMKShivendu
09/14/2022, 3:57 PMKShivendu
09/14/2022, 3:58 PMpython
from flask import Flask, abort
from flask_cors import CORS
from supertokens_python import get_all_cors_headers
from supertokens_python.framework.flask import Middleware
from supertokens_python import init, SupertokensConfig, InputAppInfo
from supertokens_python.recipe import session
init(
supertokens_config=SupertokensConfig(
connection_uri="XXX",
api_key="YYY"
),
app_info=InputAppInfo(
app_name="SuperTokens Demo",
api_domain="http://api.supertokens.io",
website_domain="http://supertokens.io",
api_base_path="/auth",
),
framework="flask",
recipe_list=[
session.init(anti_csrf="VIA_TOKEN"),
],
)
app = Flask(__name__)
Middleware(app)
CORS(
app=app,
supports_credentials=True,
origins=["http://localhost:3000"],
allow_headers=["Content-Type"] + get_all_cors_headers(),
)
@app.get("/hello")
def hello_wolrd():
return "Hello World"
# This is required since if this is not there, then OPTIONS requests for
# the APIs exposed by the supertokens' Middleware will return a 404
@app.route("/", defaults={"u_path": ""}) # type: ignore
@app.route("/<path:u_path>") # type: ignore
def catch_all(u_path: str): # pylint: disable=unused-argument
abort(404)
app.run(host="0.0.0.0", port=8000)
KShivendu
09/14/2022, 3:59 PMHansi
09/14/2022, 4:00 PMtry.supertokens.com
Hansi
09/14/2022, 4:00 PMKShivendu
09/14/2022, 4:00 PMKShivendu
09/14/2022, 4:02 PMHansi
09/14/2022, 4:05 PMpython
from flask import Flask, abort
from flask_cors import CORS
from supertokens_python import get_all_cors_headers
from supertokens_python.framework.flask import Middleware
from supertokens_python import init, SupertokensConfig, InputAppInfo
from supertokens_python.recipe import session
init(
supertokens_config=SupertokensConfig(
connection_uri="http://localhost:3567",
api_key="someKey"
),
app_info=InputAppInfo(
app_name="SuperTokens Demo",
api_domain="http://localhost:8080",
website_domain="http://localhost:3000",
api_base_path="/auth",
),
framework="flask",
recipe_list=[
session.init(anti_csrf="VIA_TOKEN"),
],
)
app = Flask(__name__)
Middleware(app)
CORS(
app=app,
supports_credentials=True,
origins=["http://localhost:3000"],
allow_headers=["Content-Type"] + get_all_cors_headers(),
)
@app.get("/hello")
def hello_world():
return "Hello World"
# This is required since if this is not there, then OPTIONS requests for
# the APIs exposed by the supertokens' Middleware will return a 404
@app.route("/", defaults={"u_path": ""}) # type: ignore
@app.route("/<path:u_path>") # type: ignore
def catch_all(u_path: str): # pylint: disable=unused-argument
abort(404)
app.run(host="0.0.0.0", port=8000)
Hansi
09/14/2022, 4:05 PMHansi
09/14/2022, 4:06 PMHansi
09/14/2022, 4:06 PMHansi
09/14/2022, 4:07 PMHansi
09/14/2022, 4:08 PMKShivendu
09/14/2022, 4:12 PMWerkzeug==2.0.1
Flask==2.1.1
my supertokens-python
is in edit mode and contains the latest code from the repo (just latest version of st-python should be sufficient for you)Hansi
09/14/2022, 4:12 PMKShivendu
09/14/2022, 4:12 PMFlask-Cors==3.0.10
Hansi
09/14/2022, 4:13 PMsupertokens-python==0.10.4
should be fine, right?KShivendu
09/14/2022, 4:13 PMHansi
09/14/2022, 4:14 PMCORS Failed
KShivendu
09/14/2022, 4:15 PMKShivendu
09/14/2022, 4:15 PMpython
import connexion
from flask_cors import CORS
from flask import abort
from supertokens_python import get_all_cors_headers
from supertokens_python.framework.flask import Middleware
from supertokens_python import init, SupertokensConfig, InputAppInfo
from supertokens_python.recipe import session
def post_greeting(name: str) -> str:
return f"Hello {name}"
init(
supertokens_config=SupertokensConfig(
connection_uri="XXX",
api_key="YYY",
),
app_info=InputAppInfo(
app_name="SuperTokens Demo",
api_domain="http://api.supertokens.io",
website_domain="http://supertokens.io",
api_base_path="/auth",
),
framework="flask",
recipe_list=[
session.init(anti_csrf="VIA_TOKEN"),
],
)
app = connexion.FlaskApp(__name__, specification_dir='openapi/')
app.add_api('my_api.yaml')
flask_app = app.app
Middleware(flask_app)
CORS(
app=flask_app,
origins=[
"http://localhost:3000"
],
supports_credentials=True,
allow_headers=["Content-Type"] + get_all_cors_headers(),
)
# This is required since if this is not there, then OPTIONS requests for
# the APIs exposed by the supertokens' Middleware will return a 404
@flask_app.route("/", defaults={"u_path": ""}) # type: ignore
@flask_app.route("/<path:u_path>") # type: ignore
def catch_all(u_path: str): # pylint: disable=unused-argument
abort(404)
app.run(host="0.0.0.0", port=8000)
Hansi
09/14/2022, 4:17 PMKShivendu
09/14/2022, 4:17 PMyaml
swagger: "2.0"
info:
title: "{{title}}"
version: "1.0"
basePath: /v1.0
paths:
/greeting/{name}:
post:
summary: Generate greeting
description: Generates a greeting message.
operationId: demo.post_greeting
produces:
- text/plain;
responses:
200:
description: greeting response
schema:
type: string
examples:
"text/plain": "Hello John"
parameters:
- name: name
in: path
description: Name of the person to greet.
required: true
type: string
KShivendu
09/14/2022, 4:21 PMKShivendu
09/14/2022, 4:22 PMHansi
09/14/2022, 4:23 PMhttp://localhost:8080/greeting/test
Hansi
09/14/2022, 4:23 PMhttp://localhost:3000/greeting/test
worksKShivendu
09/14/2022, 4:23 PMHansi
09/14/2022, 4:24 PMHansi
09/14/2022, 4:24 PMKShivendu
09/14/2022, 4:25 PMcurl -X POST --header 'Content-Type: application/json' --header 'Accept: text/plain' 'http://localhost:8000/v1.0/greeting/22'
again a post requestKShivendu
09/14/2022, 4:26 PMKShivendu
09/14/2022, 4:27 PMHansi
09/14/2022, 4:28 PMHansi
09/14/2022, 4:29 PMHansi
09/14/2022, 4:29 PMHansi
09/14/2022, 4:30 PMKShivendu
09/14/2022, 4:30 PMKShivendu
09/14/2022, 4:31 PMHansi
09/14/2022, 4:31 PMKShivendu
09/14/2022, 4:32 PMKShivendu
09/14/2022, 4:32 PMHansi
09/14/2022, 4:32 PMHansi
09/14/2022, 4:33 PMHansi
09/14/2022, 4:33 PMKShivendu
09/14/2022, 4:34 PMKShivendu
09/14/2022, 4:34 PMHansi
09/14/2022, 4:35 PMKShivendu
09/14/2022, 4:35 PMHansi
09/14/2022, 4:35 PMCORS Failed
at that point 🤔Hansi
09/14/2022, 4:36 PMsession.init(anti_csrf="VIA_TOKEN")
KShivendu
09/14/2022, 4:37 PMKShivendu
09/14/2022, 4:37 PMHansi
09/14/2022, 4:41 PMHansi
09/14/2022, 4:50 PMHansi
09/14/2022, 4:51 PMHansi
09/14/2022, 5:03 PMKShivendu
09/14/2022, 5:07 PMHansi
09/14/2022, 5:33 PMStep 2) Backend > Core > Self hosted > With Docker
.
I'm told to use connection_uri='http://localhost:3567'
but that does not resolve. I know that my core is running and everything works when I do this instead: connection_uri='http://supertokens:3567'
rp_st
09/14/2022, 5:34 PMHansi
09/14/2022, 5:35 PMsupertokens:
image: registry.supertokens.io/supertokens/supertokens-postgresql
depends_on:
- db
ports:
- 3567:3567
environment:
POSTGRESQL_CONNECTION_URI: "postgresql://supertokens_user:somePassword@db:5432/supertokens"
LOG_LEVEL: "WARN"
networks:
- app_network
restart: unless-stopped
healthcheck:
test: >
bash -c 'exec 3<>/dev/tcp/127.0.0.1/3567 && echo -e "GET /hello HTTP/1.1\r\nhost: 127.0.0.1:3567\r\nConnection: close\r\n\r\n" >&3 && cat <&3 | grep "Hello"'
interval: 10s
timeout: 5s
retries: 5
networks:
app_network:
driver: bridge
rp_st
09/14/2022, 5:36 PMrp_st
09/14/2022, 5:36 PM