{"id":2072,"date":"2020-05-11T17:30:01","date_gmt":"2020-05-11T16:30:01","guid":{"rendered":"https:\/\/www.thenaylors.co.uk\/wordpress\/?p=2072"},"modified":"2020-05-11T17:30:04","modified_gmt":"2020-05-11T16:30:04","slug":"homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles","status":"publish","type":"post","link":"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/","title":{"rendered":"Homeassistant &#8211; Delete old\/abandoned refresh tokens from user profiles"},"content":{"rendered":"\n<p>I kept on finding there were loads of refresh tokens when logging into HA.  So I googled why&#8230;.. I am not logging out!  No surprise there but they are a pain to delete individually and so I found this page.<\/p>\n\n\n\n<p><a href=\"https:\/\/community.home-assistant.io\/t\/delete-old-abandoned-refresh-tokens-from-user-profiles\/126823\">Delete old\/abandoned refresh tokens from user profiles<\/a><\/p>\n\n\n\n<p>The tokens are in the .homeassistant\/.storage\/auth file and held as JSON.<\/p>\n\n\n\n<p>The link explains that something call &#8216;jq&#8217; can edit JSON from the command line&#8230; neat!  However I had trouble getting the script in the link to work and so created a new shell script like this&#8230;.<\/p>\n\n\n\n<p>authfile=\/home\/homeassistant\/.homeassistant\/.storage\/auth<br>tmp=&#8221;$(tempfile)&#8221;<br>echo &#8220;Copying from &#8221; $authfile &#8221; to &#8221; $tmp<br>jq &#8211;arg s &#8220;$(date -d &#8220;&#8221; +&#8221;%Y-%m-%dT%H:%M&#8221;)&#8221; &#8216;del( .data.refresh_tokens[] | select(.last_used_at &lt; $s) )&#8217; $authfile >$tmp<br>cp $tmp $authfile<br>rm $tmp<\/p>\n\n\n\n<p>This needs to be run as the homeassistant user to work and homeassistant needs to be stopped as the auth file seems to be loaded into memory when ha is running.<\/p>\n\n\n\n<p>What it does is call jq after setting up the auth file location and a system temp file using &#8211;args.  &#8211;args passes the &#8216;s&#8217; as a string of value &#8220;$(date -d &#8220;&#8221;+&#8230;) into the command &#8216;del(.data&#8230;.) using the $authfile as input.  The command deletes the part of the JSON file with the refresh token where the last used date is less than today and copies it to the temp file.<\/p>\n\n\n\n<p>When this is complete the temp file is copied over the authfile and then the temp is deleted.<\/p>\n\n\n\n<p>Works well.  Just need to remember to restart home assistant!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I kept on finding there were loads of refresh tokens when logging into HA. So I googled why&#8230;.. I am not logging out! No surprise there but they are a pain to delete individually and so I found this page. Delete old\/abandoned refresh tokens from user profiles The tokens are in the .homeassistant\/.storage\/auth file and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Homeassistant &#8211; Delete old\/abandoned refresh tokens from user profiles&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2072","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Homeassistant - Delete old\/abandoned refresh tokens from user profiles - Michael Naylor<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Homeassistant - Delete old\/abandoned refresh tokens from user profiles - Michael Naylor\" \/>\n<meta property=\"og:description\" content=\"I kept on finding there were loads of refresh tokens when logging into HA. So I googled why&#8230;.. I am not logging out! No surprise there but they are a pain to delete individually and so I found this page. Delete old\/abandoned refresh tokens from user profiles The tokens are in the .homeassistant\/.storage\/auth file and &hellip; Continue reading &quot;Homeassistant &#8211; Delete old\/abandoned refresh tokens from user profiles&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/\" \/>\n<meta property=\"og:site_name\" content=\"Michael Naylor\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-11T16:30:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-05-11T16:30:04+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mjnaylor\" \/>\n<meta name=\"twitter:site\" content=\"@mjnaylor\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/af4669b3ebc6341a4c069ea3381181ad\"},\"headline\":\"Homeassistant &#8211; Delete old\/abandoned refresh tokens from user profiles\",\"datePublished\":\"2020-05-11T16:30:01+00:00\",\"dateModified\":\"2020-05-11T16:30:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/\"},\"wordCount\":274,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/22e1ad271f44b7f71c8e1fbf982dcbe5\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/\",\"url\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/\",\"name\":\"Homeassistant - Delete old\/abandoned refresh tokens from user profiles - Michael Naylor\",\"isPartOf\":{\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/#website\"},\"datePublished\":\"2020-05-11T16:30:01+00:00\",\"dateModified\":\"2020-05-11T16:30:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Homeassistant &#8211; Delete old\/abandoned refresh tokens from user profiles\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/#website\",\"url\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/\",\"name\":\"Michael Naylor\",\"description\":\"Things which interest me.\",\"publisher\":{\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/22e1ad271f44b7f71c8e1fbf982dcbe5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/22e1ad271f44b7f71c8e1fbf982dcbe5\",\"name\":\"Michael Naylor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2aa27338833977999b7baeb1ee9e723e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2aa27338833977999b7baeb1ee9e723e?s=96&d=mm&r=g\",\"caption\":\"Michael Naylor\"},\"logo\":{\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/www.thenaylors.co.uk\/wordpress\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/af4669b3ebc6341a4c069ea3381181ad\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/71e280edd2a51a46cd545022235cdf48?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/71e280edd2a51a46cd545022235cdf48?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\/\/www.thenaylors.co.uk\/wordpress\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Homeassistant - Delete old\/abandoned refresh tokens from user profiles - Michael Naylor","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/","og_locale":"en_GB","og_type":"article","og_title":"Homeassistant - Delete old\/abandoned refresh tokens from user profiles - Michael Naylor","og_description":"I kept on finding there were loads of refresh tokens when logging into HA. So I googled why&#8230;.. I am not logging out! No surprise there but they are a pain to delete individually and so I found this page. Delete old\/abandoned refresh tokens from user profiles The tokens are in the .homeassistant\/.storage\/auth file and &hellip; Continue reading \"Homeassistant &#8211; Delete old\/abandoned refresh tokens from user profiles\"","og_url":"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/","og_site_name":"Michael Naylor","article_published_time":"2020-05-11T16:30:01+00:00","article_modified_time":"2020-05-11T16:30:04+00:00","author":"admin","twitter_card":"summary_large_image","twitter_creator":"@mjnaylor","twitter_site":"@mjnaylor","twitter_misc":{"Written by":"admin","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/#article","isPartOf":{"@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/"},"author":{"name":"admin","@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/af4669b3ebc6341a4c069ea3381181ad"},"headline":"Homeassistant &#8211; Delete old\/abandoned refresh tokens from user profiles","datePublished":"2020-05-11T16:30:01+00:00","dateModified":"2020-05-11T16:30:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/"},"wordCount":274,"commentCount":0,"publisher":{"@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/22e1ad271f44b7f71c8e1fbf982dcbe5"},"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/","url":"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/","name":"Homeassistant - Delete old\/abandoned refresh tokens from user profiles - Michael Naylor","isPartOf":{"@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/#website"},"datePublished":"2020-05-11T16:30:01+00:00","dateModified":"2020-05-11T16:30:04+00:00","breadcrumb":{"@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/homeassistant-delete-old-abandoned-refresh-tokens-from-user-profiles\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.thenaylors.co.uk\/wordpress\/"},{"@type":"ListItem","position":2,"name":"Homeassistant &#8211; Delete old\/abandoned refresh tokens from user profiles"}]},{"@type":"WebSite","@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/#website","url":"https:\/\/www.thenaylors.co.uk\/wordpress\/","name":"Michael Naylor","description":"Things which interest me.","publisher":{"@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/22e1ad271f44b7f71c8e1fbf982dcbe5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.thenaylors.co.uk\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/22e1ad271f44b7f71c8e1fbf982dcbe5","name":"Michael Naylor","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2aa27338833977999b7baeb1ee9e723e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2aa27338833977999b7baeb1ee9e723e?s=96&d=mm&r=g","caption":"Michael Naylor"},"logo":{"@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/www.thenaylors.co.uk\/wordpress"]},{"@type":"Person","@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/af4669b3ebc6341a4c069ea3381181ad","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.thenaylors.co.uk\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/71e280edd2a51a46cd545022235cdf48?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/71e280edd2a51a46cd545022235cdf48?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/www.thenaylors.co.uk\/wordpress\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.thenaylors.co.uk\/wordpress\/wp-json\/wp\/v2\/posts\/2072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thenaylors.co.uk\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thenaylors.co.uk\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thenaylors.co.uk\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thenaylors.co.uk\/wordpress\/wp-json\/wp\/v2\/comments?post=2072"}],"version-history":[{"count":1,"href":"https:\/\/www.thenaylors.co.uk\/wordpress\/wp-json\/wp\/v2\/posts\/2072\/revisions"}],"predecessor-version":[{"id":2073,"href":"https:\/\/www.thenaylors.co.uk\/wordpress\/wp-json\/wp\/v2\/posts\/2072\/revisions\/2073"}],"wp:attachment":[{"href":"https:\/\/www.thenaylors.co.uk\/wordpress\/wp-json\/wp\/v2\/media?parent=2072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thenaylors.co.uk\/wordpress\/wp-json\/wp\/v2\/categories?post=2072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thenaylors.co.uk\/wordpress\/wp-json\/wp\/v2\/tags?post=2072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}