lichess-org / lila

♞ lichess.org: the forever free, adless and open source chess server ♞
https://lichess.org
GNU Affero General Public License v3.0
15.51k stars 2.26k forks source link

setup/ai endpoint to accept Bearer authorization #6449

Closed jrwaine closed 4 years ago

jrwaine commented 4 years ago

I am trying to automate the creation of a game against computer, but investigating the berserk no function for that was available.

So by investigating the source code, I found the endpoint to setup/ai, which opens the page for a new game for GET and uses the parameters to send a POST to the same endpoint.

The problem is that for creating a new game against the computer with a user, it is necessary to login. I could only create a new game for my user by passing a cookie in the header of the request.

I believe a more secure way to do this is to allow the user to pass the token as a header for authorization. This way a function in berserk for creating a game against the computer can be created as well.

niklasf commented 4 years ago

Can you please explain more about the use case?

jrwaine commented 4 years ago

I am making a bot to play chess using Twitch chat, so I upgraded my account to a Bot and use the board endpoints to make moves.

The problem is that there is no available endpoints to search games for bot accounts (except Challenge, but a username must be provided).

The only reliable opponent I found was Lichess Stockfish, but since there are no endpoint to create a game with it, every time a game ends I have to manually start another game against Stockfish. Permitting the setup/ai to accept Bearer token authorization would allow to automate that.

ornicar commented 4 years ago

https://lichess.org/api#operation/challengeAi

jrwaine commented 4 years ago

I tried to use the endpoint and it returns a created game as expected, but the game against AI is not created. The game ID redirects to an usual challenge link.

ornicar commented 4 years ago

It's not deployed yet.

jrwaine commented 4 years ago

Ok, please let me know when it is deployed.

ornicar commented 4 years ago

done