Terbau / fortnitepy

Async python library for interacting with Fortnite's API and XMPP services.
MIT License
146 stars 52 forks source link

Add support for device code auth #185

Open Luc1412 opened 1 year ago

Luc1412 commented 1 year ago

This auth type includes:

POST https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/token grant_type: client_credentials (form-urlencoded) Basic auth_client_token

-> Get access_token

POST https://account-public-service-prod.ol.epicgames.com/account/api/oauth/deviceAuthorization?prompt=login Bearer access_token (from prev client credential grant)

-> get verification_uri_complete that the user has to verify + save device_code for next request + interval for check

POST https://account-public-service-prod.ol.epicgames.com/account/api/oauth/token (every interval seconds) grant_type: device_code device_code: device_code from prev request (form-urlencoded) Basic auth_client_token

This type of auth may be more difficult to implement due to the consistent checks, however it provides a great and easy workflow. Possible workflow:

auth = DeviceCodeAuth() # provides option to customize auth client. New Switch might be a good default
client = Client(auth)
user_code = await auth.get_code()
# Now the code get passed to the user
client.run() # The auth will now check for code verification every `interval` seconds until `await auth.get_code()` + `expires_in` seconds is reached