mirror of
https://github.com/famedly/ansible-collection-matrix
synced 2024-12-12 20:22:28 +00:00
fix(modules/matrix): fix regression in access token handling
52785ab768
refactored the login logic,
which, switching to nio's token login when being passed a token. The
token being passed is an *access* token though, not a *login* token, so
that fails and thereby breaks any tasks that use access tokens instead
of username/password for authenticating to matrix.
It also accidentally negated the logic on when to invalidate a token
upon logout, so that has been resolved as well.
This commit is contained in:
parent
45b4aa85b4
commit
71f289c1d0
1 changed files with 19 additions and 15 deletions
|
@ -90,7 +90,7 @@ class AnsibleNioModule:
|
|||
|
||||
if user_logout is None:
|
||||
# If a user/password login is provided, should we logout when exiting?
|
||||
self.user_logout = self.module.params.get('token') is not None
|
||||
self.user_logout = self.module.params.get("token") is None
|
||||
else:
|
||||
self.user_logout = user_logout
|
||||
|
||||
|
@ -105,21 +105,25 @@ class AnsibleNioModule:
|
|||
|
||||
async def matrix_login(self):
|
||||
# Login with token or supplied user account
|
||||
if self.module.params.get('token') is None:
|
||||
self.client = AsyncClient(self.module.params.get('hs_url'), self.module.params.get('user_id'))
|
||||
login_response = await self.client.login(password=self.module.params.get('password'))
|
||||
if self.module.params.get("token") is None:
|
||||
self.client = AsyncClient(
|
||||
self.module.params.get("hs_url"), self.module.params.get("user_id")
|
||||
)
|
||||
login_response = await self.client.login(
|
||||
password=self.module.params.get("password")
|
||||
)
|
||||
if isinstance(login_response, LoginResponse):
|
||||
self.access_token = login_response.access_token
|
||||
self.device_id = login_response.device_id
|
||||
else:
|
||||
result = {
|
||||
"msg": login_response.message,
|
||||
"http_status_code": login_response.status_code,
|
||||
}
|
||||
self.module.fail_json(**result)
|
||||
else:
|
||||
self.client = AsyncClient(self.module.params.get('hs_url'))
|
||||
login_response = await self.client.login(token=self.module.params.get('token'))
|
||||
if isinstance(login_response, LoginResponse):
|
||||
self.access_token = login_response.access_token
|
||||
self.device_id = login_response.device_id
|
||||
else:
|
||||
result = {
|
||||
'msg': login_response.message,
|
||||
'http_status_code': login_response.status_code
|
||||
}
|
||||
self.module.fail_json(**result)
|
||||
self.client = AsyncClient(self.module.params.get("hs_url"))
|
||||
self.client.access_token = self.module.params.get("token")
|
||||
|
||||
async def matrix_logout(self):
|
||||
if self.client.logged_in:
|
||||
|
|
Loading…
Reference in a new issue