{"action":"created","comment":{"url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/comments/176983808","pull_request_review_id":106775539,"id":176983808,"diff_hunk":"@@ -89,11 +111,91 @@ func HandleSessionRequest(\n \t\t\tpanic(err)\n \t\t}\n \n+\t\t// Set cerealNotesCookieName to have value as a our JWT Token\n+\t\t{\n+\t\t\tuserId, err := userservice.GetIdForUserWithEmailAddress(loginForm.EmailAddress)\n+\t\t\tif err != nil {\n+\t\t\t\tpanic(err)\n+\t\t\t}\n+\n+\t\t\ttoken, err := createTokenAsString(userId, oneWeekInMinutes)\n+\t\t\tif err != nil {\n+\t\t\t\tpanic(err)\n+\t\t\t}\n+\n+\t\t\texpirationTime := time.Now().Add(oneWeekInMinutes * time.Minute)\n+\n+\t\t\tcookie := http.Cookie{\n+\t\t\t\tName:     cerealNotesCookieName,\n+\t\t\t\tValue:    token,\n+\t\t\t\tExpires:  expirationTime,\n+\t\t\t\tHttpOnly: true,\n+\t\t\t}\n+\n+\t\t\thttp.SetCookie(responseWriter, &cookie)\n+\t\t}\n+\n \t\tresponseWriter.WriteHeader(http.StatusCreated)\n \t\tresponseWriter.Write([]byte(fmt.Sprint(\"passward email combo was correct\")))\n \n+\tcase http.MethodDelete:\n+\t\t// Cookie will overwrite existing cookie then delete itself\n+\t\tcookie := http.Cookie{\n+\t\t\tName:     cerealNotesCookieName,\n+\t\t\tValue:    \"\",\n+\t\t\tHttpOnly: true,\n+\t\t\tMaxAge:   -1,\n+\t\t}\n+\n+\t\thttp.SetCookie(responseWriter, &cookie)\n+\t\tresponseWriter.WriteHeader(http.StatusOK)\n+\t\tresponseWriter.Write([]byte(fmt.Sprint(\"user succefully logged out\")))\n \tdefault:\n-\t\trespondWithMethodNotAllowed(responseWriter, []string{http.MethodPost})\n+\t\trespondWithMethodNotAllowed(\n+\t\t\tresponseWriter,\n+\t\t\t[]string{http.MethodPost, http.MethodDelete})\n+\t}\n+}\n+\n+type AuthentictedRequestHandlerType func(\n+\thttp.ResponseWriter,\n+\t*http.Request,\n+\tmodels.UserId)\n+\n+func AuthenticateOrRedirectToLogin(\n+\tauthenticatedHandlerFunc AuthentictedRequestHandlerType,\n+) func(http.ResponseWriter, *http.Request) {\n+\treturn http.HandlerFunc(\n+\t\tfunc(responseWriter http.ResponseWriter, request *http.Request) {\n+\t\t\tif userId, err := getUserIdFromJwtToken(request); err != nil {\n+\t\t\t\t// If not loggedin redirect to login page\n+\t\t\t\thttp.Redirect(\n+\t\t\t\t\tresponseWriter,\n+\t\t\t\t\trequest,\n+\t\t\t\t\tpaths.LoginOrSignupPath,\n+\t\t\t\t\thttp.StatusSeeOther)","path":"handlers/handlers.go","position":111,"original_position":111,"commit_id":"681e25c842d8b31b348521fa93bf153dafd81e07","original_commit_id":"681e25c842d8b31b348521fa93bf153dafd81e07","user":{"login":"atmiguel","id":549631,"avatar_url":"https://avatars0.githubusercontent.com/u/549631?v=4","gravatar_id":"","url":"https://api.github.com/users/atmiguel","html_url":"https://github.com/atmiguel","followers_url":"https://api.github.com/users/atmiguel/followers","following_url":"https://api.github.com/users/atmiguel/following{/other_user}","gists_url":"https://api.github.com/users/atmiguel/gists{/gist_id}","starred_url":"https://api.github.com/users/atmiguel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atmiguel/subscriptions","organizations_url":"https://api.github.com/users/atmiguel/orgs","repos_url":"https://api.github.com/users/atmiguel/repos","events_url":"https://api.github.com/users/atmiguel/events{/privacy}","received_events_url":"https://api.github.com/users/atmiguel/received_events","type":"User","site_admin":false},"body":"wrong http code","created_at":"2018-03-26T05:29:22Z","updated_at":"2018-03-26T05:34:54Z","html_url":"https://github.com/atmiguel/cerealnotes/pull/14#discussion_r176983808","pull_request_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/14","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/comments/176983808"},"html":{"href":"https://github.com/atmiguel/cerealnotes/pull/14#discussion_r176983808"},"pull_request":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/14","id":177279260,"html_url":"https://github.com/atmiguel/cerealnotes/pull/14","diff_url":"https://github.com/atmiguel/cerealnotes/pull/14.diff","patch_url":"https://github.com/atmiguel/cerealnotes/pull/14.patch","issue_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/14","number":14,"state":"open","locked":false,"title":"Jwt Authentication","user":{"login":"zingales","id":796540,"avatar_url":"https://avatars3.githubusercontent.com/u/796540?v=4","gravatar_id":"","url":"https://api.github.com/users/zingales","html_url":"https://github.com/zingales","followers_url":"https://api.github.com/users/zingales/followers","following_url":"https://api.github.com/users/zingales/following{/other_user}","gists_url":"https://api.github.com/users/zingales/gists{/gist_id}","starred_url":"https://api.github.com/users/zingales/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zingales/subscriptions","organizations_url":"https://api.github.com/users/zingales/orgs","repos_url":"https://api.github.com/users/zingales/repos","events_url":"https://api.github.com/users/zingales/events{/privacy}","received_events_url":"https://api.github.com/users/zingales/received_events","type":"User","site_admin":false},"body":"Create, save, validate JWT on login. ","created_at":"2018-03-25T08:50:44Z","updated_at":"2018-03-26T05:34:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4a4a3e8b36e1ed727982f5beabfcc75294af8d9f","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/14/commits","review_comments_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/14/comments","review_comment_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/14/comments","statuses_url":"https://api.github.com/repos/atmiguel/cerealnotes/statuses/681e25c842d8b31b348521fa93bf153dafd81e07","head":{"label":"atmiguel:jwt","ref":"jwt","sha":"681e25c842d8b31b348521fa93bf153dafd81e07","user":{"login":"atmiguel","id":549631,"avatar_url":"https://avatars0.githubusercontent.com/u/549631?v=4","gravatar_id":"","url":"https://api.github.com/users/atmiguel","html_url":"https://github.com/atmiguel","followers_url":"https://api.github.com/users/atmiguel/followers","following_url":"https://api.github.com/users/atmiguel/following{/other_user}","gists_url":"https://api.github.com/users/atmiguel/gists{/gist_id}","starred_url":"https://api.github.com/users/atmiguel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atmiguel/subscriptions","organizations_url":"https://api.github.com/users/atmiguel/orgs","repos_url":"https://api.github.com/users/atmiguel/repos","events_url":"https://api.github.com/users/atmiguel/events{/privacy}","received_events_url":"https://api.github.com/users/atmiguel/received_events","type":"User","site_admin":false},"repo":{"id":124090269,"name":"cerealnotes","full_name":"atmiguel/cerealnotes","owner":{"login":"atmiguel","id":549631,"avatar_url":"https://avatars0.githubusercontent.com/u/549631?v=4","gravatar_id":"","url":"https://api.github.com/users/atmiguel","html_url":"https://github.com/atmiguel","followers_url":"https://api.github.com/users/atmiguel/followers","following_url":"https://api.github.com/users/atmiguel/following{/other_user}","gists_url":"https://api.github.com/users/atmiguel/gists{/gist_id}","starred_url":"https://api.github.com/users/atmiguel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atmiguel/subscriptions","organizations_url":"https://api.github.com/users/atmiguel/orgs","repos_url":"https://api.github.com/users/atmiguel/repos","events_url":"https://api.github.com/users/atmiguel/events{/privacy}","received_events_url":"https://api.github.com/users/atmiguel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/atmiguel/cerealnotes","description":null,"fork":false,"url":"https://api.github.com/repos/atmiguel/cerealnotes","forks_url":"https://api.github.com/repos/atmiguel/cerealnotes/forks","keys_url":"https://api.github.com/repos/atmiguel/cerealnotes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/atmiguel/cerealnotes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/atmiguel/cerealnotes/teams","hooks_url":"https://api.github.com/repos/atmiguel/cerealnotes/hooks","issue_events_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/events{/number}","events_url":"https://api.github.com/repos/atmiguel/cerealnotes/events","assignees_url":"https://api.github.com/repos/atmiguel/cerealnotes/assignees{/user}","branches_url":"https://api.github.com/repos/atmiguel/cerealnotes/branches{/branch}","tags_url":"https://api.github.com/repos/atmiguel/cerealnotes/tags","blobs_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/refs{/sha}","trees_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/atmiguel/cerealnotes/statuses/{sha}","languages_url":"https://api.github.com/repos/atmiguel/cerealnotes/languages","stargazers_url":"https://api.github.com/repos/atmiguel/cerealnotes/stargazers","contributors_url":"https://api.github.com/repos/atmiguel/cerealnotes/contributors","subscribers_url":"https://api.github.com/repos/atmiguel/cerealnotes/subscribers","subscription_url":"https://api.github.com/repos/atmiguel/cerealnotes/subscription","commits_url":"https://api.github.com/repos/atmiguel/cerealnotes/commits{/sha}","git_commits_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/commits{/sha}","comments_url":"https://api.github.com/repos/atmiguel/cerealnotes/comments{/number}","issue_comment_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/comments{/number}","contents_url":"https://api.github.com/repos/atmiguel/cerealnotes/contents/{+path}","compare_url":"https://api.github.com/repos/atmiguel/cerealnotes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/atmiguel/cerealnotes/merges","archive_url":"https://api.github.com/repos/atmiguel/cerealnotes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/atmiguel/cerealnotes/downloads","issues_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues{/number}","pulls_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls{/number}","milestones_url":"https://api.github.com/repos/atmiguel/cerealnotes/milestones{/number}","notifications_url":"https://api.github.com/repos/atmiguel/cerealnotes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/atmiguel/cerealnotes/labels{/name}","releases_url":"https://api.github.com/repos/atmiguel/cerealnotes/releases{/id}","deployments_url":"https://api.github.com/repos/atmiguel/cerealnotes/deployments","created_at":"2018-03-06T14:28:42Z","updated_at":"2018-03-24T23:20:37Z","pushed_at":"2018-03-26T04:11:08Z","git_url":"git://github.com/atmiguel/cerealnotes.git","ssh_url":"git@github.com:atmiguel/cerealnotes.git","clone_url":"https://github.com/atmiguel/cerealnotes.git","svn_url":"https://github.com/atmiguel/cerealnotes","homepage":null,"size":166,"stargazers_count":3,"watchers_count":3,"language":"Go","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":3,"default_branch":"master"}},"base":{"label":"atmiguel:master","ref":"master","sha":"7143f298506345a98715a7a50f009a2666c262d4","user":{"login":"atmiguel","id":549631,"avatar_url":"https://avatars0.githubusercontent.com/u/549631?v=4","gravatar_id":"","url":"https://api.github.com/users/atmiguel","html_url":"https://github.com/atmiguel","followers_url":"https://api.github.com/users/atmiguel/followers","following_url":"https://api.github.com/users/atmiguel/following{/other_user}","gists_url":"https://api.github.com/users/atmiguel/gists{/gist_id}","starred_url":"https://api.github.com/users/atmiguel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atmiguel/subscriptions","organizations_url":"https://api.github.com/users/atmiguel/orgs","repos_url":"https://api.github.com/users/atmiguel/repos","events_url":"https://api.github.com/users/atmiguel/events{/privacy}","received_events_url":"https://api.github.com/users/atmiguel/received_events","type":"User","site_admin":false},"repo":{"id":124090269,"name":"cerealnotes","full_name":"atmiguel/cerealnotes","owner":{"login":"atmiguel","id":549631,"avatar_url":"https://avatars0.githubusercontent.com/u/549631?v=4","gravatar_id":"","url":"https://api.github.com/users/atmiguel","html_url":"https://github.com/atmiguel","followers_url":"https://api.github.com/users/atmiguel/followers","following_url":"https://api.github.com/users/atmiguel/following{/other_user}","gists_url":"https://api.github.com/users/atmiguel/gists{/gist_id}","starred_url":"https://api.github.com/users/atmiguel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atmiguel/subscriptions","organizations_url":"https://api.github.com/users/atmiguel/orgs","repos_url":"https://api.github.com/users/atmiguel/repos","events_url":"https://api.github.com/users/atmiguel/events{/privacy}","received_events_url":"https://api.github.com/users/atmiguel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/atmiguel/cerealnotes","description":null,"fork":false,"url":"https://api.github.com/repos/atmiguel/cerealnotes","forks_url":"https://api.github.com/repos/atmiguel/cerealnotes/forks","keys_url":"https://api.github.com/repos/atmiguel/cerealnotes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/atmiguel/cerealnotes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/atmiguel/cerealnotes/teams","hooks_url":"https://api.github.com/repos/atmiguel/cerealnotes/hooks","issue_events_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/events{/number}","events_url":"https://api.github.com/repos/atmiguel/cerealnotes/events","assignees_url":"https://api.github.com/repos/atmiguel/cerealnotes/assignees{/user}","branches_url":"https://api.github.com/repos/atmiguel/cerealnotes/branches{/branch}","tags_url":"https://api.github.com/repos/atmiguel/cerealnotes/tags","blobs_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/refs{/sha}","trees_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/atmiguel/cerealnotes/statuses/{sha}","languages_url":"https://api.github.com/repos/atmiguel/cerealnotes/languages","stargazers_url":"https://api.github.com/repos/atmiguel/cerealnotes/stargazers","contributors_url":"https://api.github.com/repos/atmiguel/cerealnotes/contributors","subscribers_url":"https://api.github.com/repos/atmiguel/cerealnotes/subscribers","subscription_url":"https://api.github.com/repos/atmiguel/cerealnotes/subscription","commits_url":"https://api.github.com/repos/atmiguel/cerealnotes/commits{/sha}","git_commits_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/commits{/sha}","comments_url":"https://api.github.com/repos/atmiguel/cerealnotes/comments{/number}","issue_comment_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/comments{/number}","contents_url":"https://api.github.com/repos/atmiguel/cerealnotes/contents/{+path}","compare_url":"https://api.github.com/repos/atmiguel/cerealnotes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/atmiguel/cerealnotes/merges","archive_url":"https://api.github.com/repos/atmiguel/cerealnotes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/atmiguel/cerealnotes/downloads","issues_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues{/number}","pulls_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls{/number}","milestones_url":"https://api.github.com/repos/atmiguel/cerealnotes/milestones{/number}","notifications_url":"https://api.github.com/repos/atmiguel/cerealnotes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/atmiguel/cerealnotes/labels{/name}","releases_url":"https://api.github.com/repos/atmiguel/cerealnotes/releases{/id}","deployments_url":"https://api.github.com/repos/atmiguel/cerealnotes/deployments","created_at":"2018-03-06T14:28:42Z","updated_at":"2018-03-24T23:20:37Z","pushed_at":"2018-03-26T04:11:08Z","git_url":"git://github.com/atmiguel/cerealnotes.git","ssh_url":"git@github.com:atmiguel/cerealnotes.git","clone_url":"https://github.com/atmiguel/cerealnotes.git","svn_url":"https://github.com/atmiguel/cerealnotes","homepage":null,"size":166,"stargazers_count":3,"watchers_count":3,"language":"Go","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/14"},"html":{"href":"https://github.com/atmiguel/cerealnotes/pull/14"},"issue":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/issues/14"},"comments":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/statuses/681e25c842d8b31b348521fa93bf153dafd81e07"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"atmiguel"}}