{"action":"created","comment":{"url":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/comments/129237479","pull_request_review_id":51988012,"id":129237479,"diff_hunk":"@@ -582,17 +587,150 @@ def on_sso_disable_renewal(self, event):\n ################################################################################\n \n \n-def _decode_cookies(app_cookies):\n-    sg_cookies = []\n-    if app_cookies:\n-        sg_cookies = json.loads(base64.b64decode(app_cookies))\n-        sg_cookies = [cookie.encode(\"utf-8\") for cookie in sg_cookies]\n-    return sg_cookies\n+def _decode_cookies(encoded_cookies):\n+    \"\"\"\n+    Extract the cookies from a base64 encoded string.\n+\n+    :param encoded_cookies: An encoded string representing the cookie jar.\n+\n+    :returns: A SimpleCookie containing all the cookies.\n+    \"\"\"\n+    cookies = SimpleCookie()\n+    if encoded_cookies:\n+        try:\n+            decoded_cookies = base64.b64decode(encoded_cookies)\n+            cookies.load(decoded_cookies)\n+        except TypeError, e:\n+            log.error(\"Unable to decode the cookies: %s\" % e.message)\n+    return cookies\n+\n+\n+def _encode_cookies(cookies):\n+    \"\"\"\n+    Extract the cookies from a base64 encoded string.\n+\n+    :param cookies: A Cookie.SimpleCookie instance representing the cookie jar.\n+\n+    :returns: An encoded string representing the cookie jar.\n+    \"\"\"\n+    encoded_cookies = base64.b64encode(cookies.output())\n+    return encoded_cookies\n+\n+\n+def _get_shotgun_user_id(cookies):\n+    \"\"\"\n+    Returns the id of the user in the shotgun instance, based on the cookies.\n+\n+    :param cookies: A Cookie.SimpleCookie instance representing the cookie jar.\n+\n+    :returns: A string user id value, or None.\n+    \"\"\"\n+    user_id = None\n+    for cookie in cookies:\n+        if cookie.startswith(\"shotgun_sso_session_userid_u\"):\n+            if user_id is not None:\n+                # Should we find multiple cookies with the same prefix, it means\n+                # that we are using cookies from a multi-session environment. We\n+                # have no way to identify the proper user id in the lot.\n+                raise Saml2SssoMultiSessionNotSupportedError('Multi-session not supported')","path":"python/tank/authentication/shotgun_shared/saml2_sso.py","position":null,"original_position":148,"commit_id":"073e1b5c09c84d51d2fba878a37366e85cabd901","original_commit_id":"8f184df9534de0cc4550a181cc4a724f3826c565","user":{"login":"manneohrstrom","id":337710,"avatar_url":"https://avatars3.githubusercontent.com/u/337710?v=4","gravatar_id":"","url":"https://api.github.com/users/manneohrstrom","html_url":"https://github.com/manneohrstrom","followers_url":"https://api.github.com/users/manneohrstrom/followers","following_url":"https://api.github.com/users/manneohrstrom/following{/other_user}","gists_url":"https://api.github.com/users/manneohrstrom/gists{/gist_id}","starred_url":"https://api.github.com/users/manneohrstrom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manneohrstrom/subscriptions","organizations_url":"https://api.github.com/users/manneohrstrom/orgs","repos_url":"https://api.github.com/users/manneohrstrom/repos","events_url":"https://api.github.com/users/manneohrstrom/events{/privacy}","received_events_url":"https://api.github.com/users/manneohrstrom/received_events","type":"User","site_admin":false},"body":"I would love if we could take that text you just wrote ^ here and turned that into a comment in the code. ","created_at":"2017-07-25T08:08:16Z","updated_at":"2017-07-25T08:08:17Z","html_url":"https://github.com/shotgunsoftware/tk-core/pull/487#discussion_r129237479","pull_request_url":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/487","_links":{"self":{"href":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/comments/129237479"},"html":{"href":"https://github.com/shotgunsoftware/tk-core/pull/487#discussion_r129237479"},"pull_request":{"href":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/487"}}},"pull_request":{"url":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/487","id":128410761,"html_url":"https://github.com/shotgunsoftware/tk-core/pull/487","diff_url":"https://github.com/shotgunsoftware/tk-core/pull/487.diff","patch_url":"https://github.com/shotgunsoftware/tk-core/pull/487.patch","issue_url":"https://api.github.com/repos/shotgunsoftware/tk-core/issues/487","number":487,"state":"open","locked":false,"title":"Ticket/43145 add session refresh loop in desktop","user":{"login":"patrick-hubert-adsk","id":8060460,"avatar_url":"https://avatars2.githubusercontent.com/u/8060460?v=4","gravatar_id":"","url":"https://api.github.com/users/patrick-hubert-adsk","html_url":"https://github.com/patrick-hubert-adsk","followers_url":"https://api.github.com/users/patrick-hubert-adsk/followers","following_url":"https://api.github.com/users/patrick-hubert-adsk/following{/other_user}","gists_url":"https://api.github.com/users/patrick-hubert-adsk/gists{/gist_id}","starred_url":"https://api.github.com/users/patrick-hubert-adsk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patrick-hubert-adsk/subscriptions","organizations_url":"https://api.github.com/users/patrick-hubert-adsk/orgs","repos_url":"https://api.github.com/users/patrick-hubert-adsk/repos","events_url":"https://api.github.com/users/patrick-hubert-adsk/events{/privacy}","received_events_url":"https://api.github.com/users/patrick-hubert-adsk/received_events","type":"User","site_admin":false},"body":"This work is required by the branch of the same name in repo tk-framework-desktopstartup.\r\n\r\nWe need a way to discriminate if sso is being used or not. Using the claims expiration as the indicator.\r\n\r\nAlternatively it would have been possible to contact the site itself and infer from the info() call.\r\n\r\nThis being said, I felt that having the expiration set to 0 when we were not using SSO was bad.","created_at":"2017-06-30T16:54:35Z","updated_at":"2017-07-25T08:08:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1455d2d585032f57ccec5326d8082841c2b01205","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/487/commits","review_comments_url":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/487/comments","review_comment_url":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/shotgunsoftware/tk-core/issues/487/comments","statuses_url":"https://api.github.com/repos/shotgunsoftware/tk-core/statuses/073e1b5c09c84d51d2fba878a37366e85cabd901","head":{"label":"shotgunsoftware:ticket/43145_add_session_refresh_loop_in_desktop","ref":"ticket/43145_add_session_refresh_loop_in_desktop","sha":"073e1b5c09c84d51d2fba878a37366e85cabd901","user":{"login":"shotgunsoftware","id":317894,"avatar_url":"https://avatars1.githubusercontent.com/u/317894?v=4","gravatar_id":"","url":"https://api.github.com/users/shotgunsoftware","html_url":"https://github.com/shotgunsoftware","followers_url":"https://api.github.com/users/shotgunsoftware/followers","following_url":"https://api.github.com/users/shotgunsoftware/following{/other_user}","gists_url":"https://api.github.com/users/shotgunsoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/shotgunsoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shotgunsoftware/subscriptions","organizations_url":"https://api.github.com/users/shotgunsoftware/orgs","repos_url":"https://api.github.com/users/shotgunsoftware/repos","events_url":"https://api.github.com/users/shotgunsoftware/events{/privacy}","received_events_url":"https://api.github.com/users/shotgunsoftware/received_events","type":"Organization","site_admin":false},"repo":{"id":4270061,"name":"tk-core","full_name":"shotgunsoftware/tk-core","owner":{"login":"shotgunsoftware","id":317894,"avatar_url":"https://avatars1.githubusercontent.com/u/317894?v=4","gravatar_id":"","url":"https://api.github.com/users/shotgunsoftware","html_url":"https://github.com/shotgunsoftware","followers_url":"https://api.github.com/users/shotgunsoftware/followers","following_url":"https://api.github.com/users/shotgunsoftware/following{/other_user}","gists_url":"https://api.github.com/users/shotgunsoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/shotgunsoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shotgunsoftware/subscriptions","organizations_url":"https://api.github.com/users/shotgunsoftware/orgs","repos_url":"https://api.github.com/users/shotgunsoftware/repos","events_url":"https://api.github.com/users/shotgunsoftware/events{/privacy}","received_events_url":"https://api.github.com/users/shotgunsoftware/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/shotgunsoftware/tk-core","description":"The Shotgun Pipeline Toolkit Core API","fork":false,"url":"https://api.github.com/repos/shotgunsoftware/tk-core","forks_url":"https://api.github.com/repos/shotgunsoftware/tk-core/forks","keys_url":"https://api.github.com/repos/shotgunsoftware/tk-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shotgunsoftware/tk-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shotgunsoftware/tk-core/teams","hooks_url":"https://api.github.com/repos/shotgunsoftware/tk-core/hooks","issue_events_url":"https://api.github.com/repos/shotgunsoftware/tk-core/issues/events{/number}","events_url":"https://api.github.com/repos/shotgunsoftware/tk-core/events","assignees_url":"https://api.github.com/repos/shotgunsoftware/tk-core/assignees{/user}","branches_url":"https://api.github.com/repos/shotgunsoftware/tk-core/branches{/branch}","tags_url":"https://api.github.com/repos/shotgunsoftware/tk-core/tags","blobs_url":"https://api.github.com/repos/shotgunsoftware/tk-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shotgunsoftware/tk-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shotgunsoftware/tk-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/shotgunsoftware/tk-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shotgunsoftware/tk-core/statuses/{sha}","languages_url":"https://api.github.com/repos/shotgunsoftware/tk-core/languages","stargazers_url":"https://api.github.com/repos/shotgunsoftware/tk-core/stargazers","contributors_url":"https://api.github.com/repos/shotgunsoftware/tk-core/contributors","subscribers_url":"https://api.github.com/repos/shotgunsoftware/tk-core/subscribers","subscription_url":"https://api.github.com/repos/shotgunsoftware/tk-core/subscription","commits_url":"https://api.github.com/repos/shotgunsoftware/tk-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/shotgunsoftware/tk-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/shotgunsoftware/tk-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/shotgunsoftware/tk-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/shotgunsoftware/tk-core/contents/{+path}","compare_url":"https://api.github.com/repos/shotgunsoftware/tk-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shotgunsoftware/tk-core/merges","archive_url":"https://api.github.com/repos/shotgunsoftware/tk-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shotgunsoftware/tk-core/downloads","issues_url":"https://api.github.com/repos/shotgunsoftware/tk-core/issues{/number}","pulls_url":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls{/number}","milestones_url":"https://api.github.com/repos/shotgunsoftware/tk-core/milestones{/number}","notifications_url":"https://api.github.com/repos/shotgunsoftware/tk-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shotgunsoftware/tk-core/labels{/name}","releases_url":"https://api.github.com/repos/shotgunsoftware/tk-core/releases{/id}","deployments_url":"https://api.github.com/repos/shotgunsoftware/tk-core/deployments","created_at":"2012-05-09T09:12:06Z","updated_at":"2017-06-06T18:25:38Z","pushed_at":"2017-07-24T22:38:40Z","git_url":"git://github.com/shotgunsoftware/tk-core.git","ssh_url":"git@github.com:shotgunsoftware/tk-core.git","clone_url":"https://github.com/shotgunsoftware/tk-core.git","svn_url":"https://github.com/shotgunsoftware/tk-core","homepage":"","size":57986,"stargazers_count":35,"watchers_count":35,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":34,"mirror_url":null,"open_issues_count":23,"forks":34,"open_issues":23,"watchers":35,"default_branch":"master"}},"base":{"label":"shotgunsoftware:feature/sso","ref":"feature/sso","sha":"3de3064d14ff00a446e2e383291306a0c604e55d","user":{"login":"shotgunsoftware","id":317894,"avatar_url":"https://avatars1.githubusercontent.com/u/317894?v=4","gravatar_id":"","url":"https://api.github.com/users/shotgunsoftware","html_url":"https://github.com/shotgunsoftware","followers_url":"https://api.github.com/users/shotgunsoftware/followers","following_url":"https://api.github.com/users/shotgunsoftware/following{/other_user}","gists_url":"https://api.github.com/users/shotgunsoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/shotgunsoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shotgunsoftware/subscriptions","organizations_url":"https://api.github.com/users/shotgunsoftware/orgs","repos_url":"https://api.github.com/users/shotgunsoftware/repos","events_url":"https://api.github.com/users/shotgunsoftware/events{/privacy}","received_events_url":"https://api.github.com/users/shotgunsoftware/received_events","type":"Organization","site_admin":false},"repo":{"id":4270061,"name":"tk-core","full_name":"shotgunsoftware/tk-core","owner":{"login":"shotgunsoftware","id":317894,"avatar_url":"https://avatars1.githubusercontent.com/u/317894?v=4","gravatar_id":"","url":"https://api.github.com/users/shotgunsoftware","html_url":"https://github.com/shotgunsoftware","followers_url":"https://api.github.com/users/shotgunsoftware/followers","following_url":"https://api.github.com/users/shotgunsoftware/following{/other_user}","gists_url":"https://api.github.com/users/shotgunsoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/shotgunsoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shotgunsoftware/subscriptions","organizations_url":"https://api.github.com/users/shotgunsoftware/orgs","repos_url":"https://api.github.com/users/shotgunsoftware/repos","events_url":"https://api.github.com/users/shotgunsoftware/events{/privacy}","received_events_url":"https://api.github.com/users/shotgunsoftware/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/shotgunsoftware/tk-core","description":"The Shotgun Pipeline Toolkit Core API","fork":false,"url":"https://api.github.com/repos/shotgunsoftware/tk-core","forks_url":"https://api.github.com/repos/shotgunsoftware/tk-core/forks","keys_url":"https://api.github.com/repos/shotgunsoftware/tk-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shotgunsoftware/tk-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shotgunsoftware/tk-core/teams","hooks_url":"https://api.github.com/repos/shotgunsoftware/tk-core/hooks","issue_events_url":"https://api.github.com/repos/shotgunsoftware/tk-core/issues/events{/number}","events_url":"https://api.github.com/repos/shotgunsoftware/tk-core/events","assignees_url":"https://api.github.com/repos/shotgunsoftware/tk-core/assignees{/user}","branches_url":"https://api.github.com/repos/shotgunsoftware/tk-core/branches{/branch}","tags_url":"https://api.github.com/repos/shotgunsoftware/tk-core/tags","blobs_url":"https://api.github.com/repos/shotgunsoftware/tk-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shotgunsoftware/tk-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shotgunsoftware/tk-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/shotgunsoftware/tk-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shotgunsoftware/tk-core/statuses/{sha}","languages_url":"https://api.github.com/repos/shotgunsoftware/tk-core/languages","stargazers_url":"https://api.github.com/repos/shotgunsoftware/tk-core/stargazers","contributors_url":"https://api.github.com/repos/shotgunsoftware/tk-core/contributors","subscribers_url":"https://api.github.com/repos/shotgunsoftware/tk-core/subscribers","subscription_url":"https://api.github.com/repos/shotgunsoftware/tk-core/subscription","commits_url":"https://api.github.com/repos/shotgunsoftware/tk-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/shotgunsoftware/tk-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/shotgunsoftware/tk-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/shotgunsoftware/tk-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/shotgunsoftware/tk-core/contents/{+path}","compare_url":"https://api.github.com/repos/shotgunsoftware/tk-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shotgunsoftware/tk-core/merges","archive_url":"https://api.github.com/repos/shotgunsoftware/tk-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shotgunsoftware/tk-core/downloads","issues_url":"https://api.github.com/repos/shotgunsoftware/tk-core/issues{/number}","pulls_url":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls{/number}","milestones_url":"https://api.github.com/repos/shotgunsoftware/tk-core/milestones{/number}","notifications_url":"https://api.github.com/repos/shotgunsoftware/tk-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shotgunsoftware/tk-core/labels{/name}","releases_url":"https://api.github.com/repos/shotgunsoftware/tk-core/releases{/id}","deployments_url":"https://api.github.com/repos/shotgunsoftware/tk-core/deployments","created_at":"2012-05-09T09:12:06Z","updated_at":"2017-06-06T18:25:38Z","pushed_at":"2017-07-24T22:38:40Z","git_url":"git://github.com/shotgunsoftware/tk-core.git","ssh_url":"git@github.com:shotgunsoftware/tk-core.git","clone_url":"https://github.com/shotgunsoftware/tk-core.git","svn_url":"https://github.com/shotgunsoftware/tk-core","homepage":"","size":57986,"stargazers_count":35,"watchers_count":35,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":34,"mirror_url":null,"open_issues_count":23,"forks":34,"open_issues":23,"watchers":35,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/487"},"html":{"href":"https://github.com/shotgunsoftware/tk-core/pull/487"},"issue":{"href":"https://api.github.com/repos/shotgunsoftware/tk-core/issues/487"},"comments":{"href":"https://api.github.com/repos/shotgunsoftware/tk-core/issues/487/comments"},"review_comments":{"href":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/487/comments"},"review_comment":{"href":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/shotgunsoftware/tk-core/pulls/487/commits"},"statuses":{"href":"https://api.github.com/repos/shotgunsoftware/tk-core/statuses/073e1b5c09c84d51d2fba878a37366e85cabd901"}}}}
{"actor":{"display_login":"manneohrstrom"}}