tomasvotava / fastapi-sso

FastAPI plugin to enable SSO to most common providers (such as Facebook login, Google login and login via Microsoft Office 365 Account)

Home Page:https://tomasvotava.github.io/fastapi-sso/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

oauthlib.oauth2.rfc6749.errors.CustomOAuth2Error: (redirect_uri_mismatch) Bad Request

raghunila opened this issue · comments

Locally I am able to run this setup. But in AWS EC2 I am getting above error.

EC2 is setup with nginx and fastapi-sso.

I am getting below error

INFO: 127.0.0.1:52288 - "GET /google/callback?state=2a8bead4-ae70-46de-91f1-448439342094&code=4%2F0AX4XfWjuPSN701bRYyTs2AMP3tUt77906-kLGFtqFYubbMAK-dmR83ks2YSGfkN_6LOO_g&scope=email+profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+openid&authuser=0&prompt=none HTTP/1.0" 500 Internal Server Error
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/home/ec2-user/.local/lib/python3.7/site-packages/uvicorn/protocols/http/h11_impl.py", line 396, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/home/ec2-user/.local/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in call
return await self.app(scope, receive, send)
File "/home/ec2-user/.local/lib/python3.7/site-packages/fastapi/applications.py", line 261, in call
await super().call(scope, receive, send)
File "/home/ec2-user/.local/lib/python3.7/site-packages/starlette/applications.py", line 112, in call
await self.middleware_stack(scope, receive, send)
File "/home/ec2-user/.local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 181, in call
raise exc
File "/home/ec2-user/.local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 159, in call
await self.app(scope, receive, _send)
File "/home/ec2-user/.local/lib/python3.7/site-packages/starlette/exceptions.py", line 82, in call
raise exc
File "/home/ec2-user/.local/lib/python3.7/site-packages/starlette/exceptions.py", line 71, in call
await self.app(scope, receive, sender)
File "/home/ec2-user/.local/lib/python3.7/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in call
raise e
File "/home/ec2-user/.local/lib/python3.7/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in call
await self.app(scope, receive, send)
File "/home/ec2-user/.local/lib/python3.7/site-packages/starlette/routing.py", line 656, in call
await route.handle(scope, receive, send)
File "/home/ec2-user/.local/lib/python3.7/site-packages/starlette/routing.py", line 259, in handle
await self.app(scope, receive, send)
File "/home/ec2-user/.local/lib/python3.7/site-packages/starlette/routing.py", line 61, in app
response = await func(request)
File "/home/ec2-user/.local/lib/python3.7/site-packages/fastapi/routing.py", line 228, in app
dependant=dependant, values=values, is_coroutine=is_coroutine
File "/home/ec2-user/.local/lib/python3.7/site-packages/fastapi/routing.py", line 160, in run_endpoint_function
return await dependant.call(**values)
File "temp.py", line 21, in google_callback
user = await google_sso.verify_and_process(request)
File "/home/ec2-user/.local/lib/python3.7/site-packages/fastapi_sso/sso/base.py", line 144, in verify_and_process
return await self.process_login(code, request)
File "/home/ec2-user/.local/lib/python3.7/site-packages/fastapi_sso/sso/base.py", line 170, in process_login
self.oauth_client.parse_request_body_response(json.dumps(content))
File "/home/ec2-user/.local/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/clients/base.py", line 448, in parse_request_body_response
self.token = parse_token_response(body, scope=scope)
File "/home/ec2-user/.local/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 441, in parse_token_response
validate_token_parameters(params)
File "/home/ec2-user/.local/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/parameters.py", line 448, in validate_token_parameters
raise_from_error(params.get('error'), params)
File "/home/ec2-user/.local/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/errors.py", line 400, in raise_from_error
raise CustomOAuth2Error(error=error, **kwargs)
oauthlib.oauth2.rfc6749.errors.CustomOAuth2Error: (redirect_uri_mismatch) Bad Request

Never mind. It started working after i restarted the EC2.