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

Track refresh token last usage information #16408

Merged
merged 5 commits into from
Sep 12, 2018

Conversation

awarecan
Copy link
Contributor

@awarecan awarecan commented Sep 4, 2018

Description:

Add last_used_at (datetime) and last_used_by (IP address string) fields to refresh_token

Related issue (if applicable): fixes #15196

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.github.io#<home-assistant.github.io PR number goes here>

Example entry for configuration.yaml (if applicable):

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@@ -277,8 +277,11 @@ def get_auth_mfa_module(self, module_id: str) \

@callback
def async_create_access_token(self,
refresh_token: models.RefreshToken) -> str:
refresh_token: models.RefreshToken,
used_by: Optional[str] = None) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename last_used_by to last_used_ip just so it's more descriptive

@@ -224,7 +236,10 @@ def __init__(self, hass: HomeAssistant) -> None:
access_token_expiration=timedelta(
seconds=rt_dict['access_token_expiration']),
token=rt_dict['token'],
jwt_key=rt_dict['jwt_key']
jwt_key=rt_dict['jwt_key'],
last_used_at=dt_util.parse_datetime(last_used_at_str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of inline if-statements that wrap two lines.

@@ -1,6 +1,6 @@
"""Storage for auth models."""
from collections import OrderedDict
from datetime import timedelta
from datetime import timedelta, datetime

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'datetime.datetime' imported but unused

@awarecan awarecan changed the title Extend refresh_token to support last_used_at and last_used_by Track refresh token last usage information Sep 4, 2018
@balloob
Copy link
Member

balloob commented Sep 12, 2018

I forgot about this PR 😨

@balloob balloob merged commit ff78a5b into home-assistant:dev Sep 12, 2018
@ghost ghost removed the in progress label Sep 12, 2018
balloob pushed a commit that referenced this pull request Sep 12, 2018
* Extend refresh_token to support last_used_at and last_used_by

* Address code review comment

* Remove unused code

* Add it to websocket response

* Fix typing
@balloob balloob mentioned this pull request Sep 17, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
@awarecan awarecan deleted the extend-refresh-token-attr branch March 12, 2019 06:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Track when refresh tokens are last used
4 participants