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

Implement OAuth2 authentication with aiohttp to prevent blocking #433

Merged
merged 19 commits into from
Jun 19, 2019

Conversation

Askaholic
Copy link
Collaborator

Closes #409
Closes #404
Closes #406
Closes #402

Tested this on the test server and it appears to work correctly. The server continues to print debug info while the API request is happening. Would like to test it with more people though.

@Askaholic Askaholic requested review from Rackover and Sheeo June 1, 2019 00:45
@Rackover
Copy link
Member

Rackover commented Jun 12, 2019

DEBUG    Jun 12  09:36:06 LobbyConnection                Login from: 53471, axel12, 3013059539
INFO     Jun 12  09:36:06 aiomysql                       UPDATE login SET ip = '68.98.11.83', user_agent = 'downlords-faf-client', last_login = NOW() WHERE id = 53471
INFO     Jun 12  09:36:06 aiomysql                       {'ip': '68.98.11.83', 'user_agent': 'downlords-faf-client', 'player_id': 53471}
ERROR    Jun 12  09:36:06 LobbyConnection                Use async with instead
Traceback (most recent call last):
  File "/code/server/lobbyconnection.py", line 144, in on_message_received
    await handler(message)
  File "/code/server/lobbyconnection.py", line 526, in command_hello
    conforms_policy = await self.check_policy_conformity(player_id, message['unique_id'], self.session)
  File "/code/server/lobbyconnection.py", line 465, in check_policy_conformity
    with aiohttp.ClientSession(raise_for_status=True) as session:
  File "/usr/local/lib/python3.6/site-packages/aiohttp/client.py", line 883, in __enter__
    raise TypeError("Use async with instead")
TypeError: Use async with instead
WARNING  Jun 12  09:36:06 LobbyConnection                Aborting 68.98.11.83. Error processing command
ERROR    Jun 12  09:36:06 asyncio                        Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7fe7e10386d8>

@Rackover
Copy link
Member

Apart from that, it's working.

@Askaholic Askaholic removed the request for review from Sheeo June 14, 2019 20:24
@Rackover Rackover merged commit 23a8594 into FAForever:develop Jun 19, 2019
@Askaholic Askaholic deleted the api-authentication branch June 20, 2019 07:23
Brutus5000 pushed a commit that referenced this pull request Jun 24, 2019
* Implement oauth2 using aiohttp

* Connect to policy server using aiohttp not requests

* Modify ApiAccessor for aiohttp response objects

* Use .startswith for https check

* Test that missing tokens are checked

* Add test for SessionManager

* Add error handling in event and achievemnt service

* Add tests for Oauth2Session

* Add tests for more error conditions

* Let pytest handle skiping slow tests

* Replace call to deprecated aiohttp api

* Add test for policy server connection code

* Use `async with` for aiohttp session

* Add more tests for check_policy_conformity

This actually uncovered a bug which prevented fradulent logins from 
receiving an auto-ban

* Add test for player signing in from two machines at the same time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The server freezes waiting for the API to answer APIAccessor NoneType error
2 participants