{"action":"created","comment":{"url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/comments/25814912","id":25814912,"diff_hunk":"@@ -1,5 +1,69 @@\n 'use strict';\n \n+var superagent = require('superagent');\n+\n+global.D2LAccessTokenExpiresAt = 0;\n+\n+function now() {\n+\treturn Date.now()/1000 | 0;\n+}\n+\n+function addHeaders(req) {\n+\treq.set('X-Csrf-Token', localStorage['XSRF.Token']);","path":"index.js","position":12,"original_position":12,"commit_id":"560c201e5311d22d3eafb2866c741e15e6a3476b","original_commit_id":"af995c10b6a4686b58be124cf0b3f7641bd1ffff","user":{"login":"j3parker","id":597907,"avatar_url":"https://avatars.githubusercontent.com/u/597907?v=3","gravatar_id":"","url":"https://api.github.com/users/j3parker","html_url":"https://github.com/j3parker","followers_url":"https://api.github.com/users/j3parker/followers","following_url":"https://api.github.com/users/j3parker/following{/other_user}","gists_url":"https://api.github.com/users/j3parker/gists{/gist_id}","starred_url":"https://api.github.com/users/j3parker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j3parker/subscriptions","organizations_url":"https://api.github.com/users/j3parker/orgs","repos_url":"https://api.github.com/users/j3parker/repos","events_url":"https://api.github.com/users/j3parker/events{/privacy}","received_events_url":"https://api.github.com/users/j3parker/received_events","type":"User","site_admin":false},"body":"Haha yeah.","created_at":"2015-03-04T21:19:39Z","updated_at":"2015-03-04T21:19:39Z","html_url":"https://github.com/Brightspace/superagent-d2l-session-auth/pull/16#discussion_r25814912","pull_request_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/16","_links":{"self":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/comments/25814912"},"html":{"href":"https://github.com/Brightspace/superagent-d2l-session-auth/pull/16#discussion_r25814912"},"pull_request":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/16"}}},"pull_request":{"url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/16","id":30498251,"html_url":"https://github.com/Brightspace/superagent-d2l-session-auth/pull/16","diff_url":"https://github.com/Brightspace/superagent-d2l-session-auth/pull/16.diff","patch_url":"https://github.com/Brightspace/superagent-d2l-session-auth/pull/16.patch","issue_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/issues/16","number":16,"state":"open","locked":false,"title":"Add refreshcookie preflight","user":{"login":"j3parker","id":597907,"avatar_url":"https://avatars.githubusercontent.com/u/597907?v=3","gravatar_id":"","url":"https://api.github.com/users/j3parker","html_url":"https://github.com/j3parker","followers_url":"https://api.github.com/users/j3parker/followers","following_url":"https://api.github.com/users/j3parker/following{/other_user}","gists_url":"https://api.github.com/users/j3parker/gists{/gist_id}","starred_url":"https://api.github.com/users/j3parker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j3parker/subscriptions","organizations_url":"https://api.github.com/users/j3parker/orgs","repos_url":"https://api.github.com/users/j3parker/repos","events_url":"https://api.github.com/users/j3parker/events{/privacy}","received_events_url":"https://api.github.com/users/j3parker/received_events","type":"User","site_admin":false},"body":"Ok, this is obviously a big change. This should be \"non-breaking\" to consumers of this plugin: if anyone can think up scenarios which are not totally contrived but where client JS code would notice we should discuss it.\r\n\r\nWhy this:\r\nWe are adding a new cookie which contains an access token that has a finite lifespan. To keep that token fresh the browser will send a custom pre-flight before API calls that will use your session (no hard expiry) cookie (d2l(Secure)SessionVal) to authenticate you and (re)provision you an access token. The service handling that route will set a Cache-Control to communicate when the client must do a new pre-flight (the max-age will match that of the cookie, and will be \"well before\" the token actually expires so that we can support \"proxy\" auth scenarios - come by my desk and ask.)\r\n\r\nThis was designed so that there would be no ambiguity over whether an API call could fail due to an expired access token, while at the same time hiding this logic from clients. The downsides to this approach is it is nice piece of implementation-detail that could be hidden from clients - people who want to use Angular's `$http` for example are going to have to re-solve this. If you want to discuss how we could make services do this lets discuss it not on Github ;)\r\n\r\nThe browser should avoid doing the pre-flight when possible.\r\n\r\nAbout versioning: I've bumped this to 0.9.0 arbitrarily (0.10.0 comes next.) Once we have a suitable solution for #15 I'd like to switch this to 1.0.0.\r\n\r\nTODO: I need to test this in a free-range app with our feature toggle turned on.","created_at":"2015-03-04T19:53:33Z","updated_at":"2015-03-04T21:19:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ab0e56fdcce78a5eb9d5011e5a7fab7a32f1b8c6","assignee":{"login":"cpacey","id":5035309,"avatar_url":"https://avatars.githubusercontent.com/u/5035309?v=3","gravatar_id":"","url":"https://api.github.com/users/cpacey","html_url":"https://github.com/cpacey","followers_url":"https://api.github.com/users/cpacey/followers","following_url":"https://api.github.com/users/cpacey/following{/other_user}","gists_url":"https://api.github.com/users/cpacey/gists{/gist_id}","starred_url":"https://api.github.com/users/cpacey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpacey/subscriptions","organizations_url":"https://api.github.com/users/cpacey/orgs","repos_url":"https://api.github.com/users/cpacey/repos","events_url":"https://api.github.com/users/cpacey/events{/privacy}","received_events_url":"https://api.github.com/users/cpacey/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/16/commits","review_comments_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/16/comments","review_comment_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/issues/16/comments","statuses_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/statuses/560c201e5311d22d3eafb2866c741e15e6a3476b","head":{"label":"j3parker:RefreshCookiePreflight","ref":"RefreshCookiePreflight","sha":"560c201e5311d22d3eafb2866c741e15e6a3476b","user":{"login":"j3parker","id":597907,"avatar_url":"https://avatars.githubusercontent.com/u/597907?v=3","gravatar_id":"","url":"https://api.github.com/users/j3parker","html_url":"https://github.com/j3parker","followers_url":"https://api.github.com/users/j3parker/followers","following_url":"https://api.github.com/users/j3parker/following{/other_user}","gists_url":"https://api.github.com/users/j3parker/gists{/gist_id}","starred_url":"https://api.github.com/users/j3parker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j3parker/subscriptions","organizations_url":"https://api.github.com/users/j3parker/orgs","repos_url":"https://api.github.com/users/j3parker/repos","events_url":"https://api.github.com/users/j3parker/events{/privacy}","received_events_url":"https://api.github.com/users/j3parker/received_events","type":"User","site_admin":false},"repo":{"id":27134683,"name":"superagent-d2l-session-auth","full_name":"j3parker/superagent-d2l-session-auth","owner":{"login":"j3parker","id":597907,"avatar_url":"https://avatars.githubusercontent.com/u/597907?v=3","gravatar_id":"","url":"https://api.github.com/users/j3parker","html_url":"https://github.com/j3parker","followers_url":"https://api.github.com/users/j3parker/followers","following_url":"https://api.github.com/users/j3parker/following{/other_user}","gists_url":"https://api.github.com/users/j3parker/gists{/gist_id}","starred_url":"https://api.github.com/users/j3parker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j3parker/subscriptions","organizations_url":"https://api.github.com/users/j3parker/orgs","repos_url":"https://api.github.com/users/j3parker/repos","events_url":"https://api.github.com/users/j3parker/events{/privacy}","received_events_url":"https://api.github.com/users/j3parker/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/j3parker/superagent-d2l-session-auth","description":"A superagent plugin that adds D2L auth headers","fork":true,"url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth","forks_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/forks","keys_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/keys{/key_id}","collaborators_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/teams","hooks_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/hooks","issue_events_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/issues/events{/number}","events_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/events","assignees_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/assignees{/user}","branches_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/branches{/branch}","tags_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/tags","blobs_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/git/refs{/sha}","trees_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/git/trees{/sha}","statuses_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/statuses/{sha}","languages_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/languages","stargazers_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/stargazers","contributors_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/contributors","subscribers_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/subscribers","subscription_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/subscription","commits_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/commits{/sha}","git_commits_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/git/commits{/sha}","comments_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/comments{/number}","issue_comment_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/issues/comments{/number}","contents_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/contents/{+path}","compare_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/compare/{base}...{head}","merges_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/merges","archive_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/downloads","issues_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/issues{/number}","pulls_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/pulls{/number}","milestones_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/milestones{/number}","notifications_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/labels{/name}","releases_url":"https://api.github.com/repos/j3parker/superagent-d2l-session-auth/releases{/id}","created_at":"2014-11-25T16:22:29Z","updated_at":"2015-03-04T19:27:03Z","pushed_at":"2015-03-04T21:13:09Z","git_url":"git://github.com/j3parker/superagent-d2l-session-auth.git","ssh_url":"git@github.com:j3parker/superagent-d2l-session-auth.git","clone_url":"https://github.com/j3parker/superagent-d2l-session-auth.git","svn_url":"https://github.com/j3parker/superagent-d2l-session-auth","homepage":null,"size":154,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Brightspace:master","ref":"master","sha":"44390c0d6efd86f48b376497688a226fe9503efa","user":{"login":"Brightspace","id":5429170,"avatar_url":"https://avatars.githubusercontent.com/u/5429170?v=3","gravatar_id":"","url":"https://api.github.com/users/Brightspace","html_url":"https://github.com/Brightspace","followers_url":"https://api.github.com/users/Brightspace/followers","following_url":"https://api.github.com/users/Brightspace/following{/other_user}","gists_url":"https://api.github.com/users/Brightspace/gists{/gist_id}","starred_url":"https://api.github.com/users/Brightspace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Brightspace/subscriptions","organizations_url":"https://api.github.com/users/Brightspace/orgs","repos_url":"https://api.github.com/users/Brightspace/repos","events_url":"https://api.github.com/users/Brightspace/events{/privacy}","received_events_url":"https://api.github.com/users/Brightspace/received_events","type":"Organization","site_admin":false},"repo":{"id":27097719,"name":"superagent-d2l-session-auth","full_name":"Brightspace/superagent-d2l-session-auth","owner":{"login":"Brightspace","id":5429170,"avatar_url":"https://avatars.githubusercontent.com/u/5429170?v=3","gravatar_id":"","url":"https://api.github.com/users/Brightspace","html_url":"https://github.com/Brightspace","followers_url":"https://api.github.com/users/Brightspace/followers","following_url":"https://api.github.com/users/Brightspace/following{/other_user}","gists_url":"https://api.github.com/users/Brightspace/gists{/gist_id}","starred_url":"https://api.github.com/users/Brightspace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Brightspace/subscriptions","organizations_url":"https://api.github.com/users/Brightspace/orgs","repos_url":"https://api.github.com/users/Brightspace/repos","events_url":"https://api.github.com/users/Brightspace/events{/privacy}","received_events_url":"https://api.github.com/users/Brightspace/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Brightspace/superagent-d2l-session-auth","description":"A superagent plugin that adds D2L auth headers","fork":false,"url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth","forks_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/forks","keys_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/teams","hooks_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/hooks","issue_events_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/issues/events{/number}","events_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/events","assignees_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/assignees{/user}","branches_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/branches{/branch}","tags_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/tags","blobs_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/git/refs{/sha}","trees_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/statuses/{sha}","languages_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/languages","stargazers_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/stargazers","contributors_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/contributors","subscribers_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/subscribers","subscription_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/subscription","commits_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/commits{/sha}","git_commits_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/git/commits{/sha}","comments_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/comments{/number}","issue_comment_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/issues/comments{/number}","contents_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/contents/{+path}","compare_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/merges","archive_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/downloads","issues_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/issues{/number}","pulls_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls{/number}","milestones_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/milestones{/number}","notifications_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/labels{/name}","releases_url":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/releases{/id}","created_at":"2014-11-24T22:17:48Z","updated_at":"2015-03-03T15:38:28Z","pushed_at":"2015-03-03T15:38:28Z","git_url":"git://github.com/Brightspace/superagent-d2l-session-auth.git","ssh_url":"git@github.com:Brightspace/superagent-d2l-session-auth.git","clone_url":"https://github.com/Brightspace/superagent-d2l-session-auth.git","svn_url":"https://github.com/Brightspace/superagent-d2l-session-auth","homepage":null,"size":257,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/16"},"html":{"href":"https://github.com/Brightspace/superagent-d2l-session-auth/pull/16"},"issue":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/issues/16"},"comments":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/issues/16/comments"},"review_comments":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/16/comments"},"review_comment":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/pulls/16/commits"},"statuses":{"href":"https://api.github.com/repos/Brightspace/superagent-d2l-session-auth/statuses/560c201e5311d22d3eafb2866c741e15e6a3476b"}}}}