handle code better, refresh fixes
This commit is contained in:
parent
c5777c0d13
commit
a8b5c70739
2 changed files with 8 additions and 6 deletions
|
@ -76,7 +76,7 @@ class MinecraftClient(CallbacksHolder, Runnable):
|
||||||
|
|
||||||
self.options = ClientOptions(**kwargs)
|
self.options = ClientOptions(**kwargs)
|
||||||
|
|
||||||
self.code = login_code
|
self.code = login_code or None # TODO put this directly in the authenticator maybe?
|
||||||
self._username = username
|
self._username = username
|
||||||
self._authenticator = MicrosoftAuthenticator(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
|
self._authenticator = MicrosoftAuthenticator(client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
|
||||||
self.online_mode = online_mode
|
self.online_mode = online_mode
|
||||||
|
@ -122,12 +122,13 @@ class MinecraftClient(CallbacksHolder, Runnable):
|
||||||
try:
|
try:
|
||||||
await self._authenticator.validate() # will raise an exc if token is invalid
|
await self._authenticator.validate() # will raise an exc if token is invalid
|
||||||
except AuthException:
|
except AuthException:
|
||||||
if self._authenticator.refreshable:
|
if self.code:
|
||||||
|
await self._authenticator.login(self.code)
|
||||||
|
self.code = None
|
||||||
|
self._logger.info("Logged in with OAuth code")
|
||||||
|
elif self._authenticator.refreshable:
|
||||||
await self._authenticator.refresh()
|
await self._authenticator.refresh()
|
||||||
self._logger.warning("Refreshed Token")
|
self._logger.warning("Refreshed Token")
|
||||||
elif self.code:
|
|
||||||
await self._authenticator.login(self.code)
|
|
||||||
self._logger.info("Logged in with OAuth code")
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("No refreshable auth or code to login")
|
raise ValueError("No refreshable auth or code to login")
|
||||||
self._authenticated = True
|
self._authenticated = True
|
||||||
|
|
|
@ -94,12 +94,13 @@ class MicrosoftAuthenticator(AuthInterface):
|
||||||
"client_id": self.client_id,
|
"client_id": self.client_id,
|
||||||
"client_secret": self.client_secret,
|
"client_secret": self.client_secret,
|
||||||
"redirect_uri": self.redirect_uri,
|
"redirect_uri": self.redirect_uri,
|
||||||
"grant_type": "authorization_code",
|
|
||||||
}
|
}
|
||||||
if code:
|
if code:
|
||||||
payload['code'] = code
|
payload['code'] = code
|
||||||
|
payload['grant_type'] = 'authorization_code'
|
||||||
elif self.refreshToken:
|
elif self.refreshToken:
|
||||||
payload['refresh_token'] = self.refreshToken
|
payload['refresh_token'] = self.refreshToken
|
||||||
|
payload['grant_type'] = 'refresh_token'
|
||||||
else:
|
else:
|
||||||
raise InvalidStateError("Missing auth code and refresh token")
|
raise InvalidStateError("Missing auth code and refresh token")
|
||||||
auth_response = await self._post(
|
auth_response = await self._post(
|
||||||
|
|
Loading…
Reference in a new issue