payload: {"action":"created","comment":{"url":"https://api.github.com/repos/keratin/authn-server/pulls/comments/299628155","pull_request_review_id":257077912,"id":299628155,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI5OTYyODE1NQ==","diff_hunk":"@@ -0,0 +1,113 @@\n+package server\n+\n+import (\n+\t\"context\"\n+\t\"fmt\"\n+\t\"strings\"\n+\n+\t\"github.com/grpc-ecosystem/grpc-gateway/runtime\"\n+\tlog \"github.com/sirupsen/logrus\"\n+\t\"github.com/soheilhy/cmux\"\n+\n+\t\"net\"\n+\n+\t\"github.com/gorilla/mux\"\n+\tgrpc_prometheus \"github.com/grpc-ecosystem/go-grpc-prometheus\"\n+\t\"github.com/keratin/authn-server/app\"\n+\t\"github.com/keratin/authn-server/grpc/internal/errors\"\n+\t\"github.com/keratin/authn-server/grpc/private\"\n+\t\"github.com/keratin/authn-server/grpc/public\"\n+\t\"golang.org/x/sync/errgroup\"\n+\t\"google.golang.org/grpc\"\n+)\n+\n+func init() {\n+\truntime.HTTPError = errors.CustomHTTPError\n+}\n+\n+// RunPrivateService starts a gRPC server for the private API and accompanying gRPC-Gateway server\n+func runPrivateService(ctx context.Context, app *app.App, grpcListener net.Listener, httpListener net.Listener) error {\n+\n+\tprivateRouter := mux.NewRouter()\n+\n+\tg, ctx := errgroup.WithContext(ctx)\n+\n+\tg.Go(func() error {\n+\t\treturn private.RunPrivateGRPC(ctx, app, grpcListener)\n+\t})\n+\n+\tprivClientConn, err := grpc.DialContext(ctx, grpcListener.Addr().String(), grpc.WithInsecure())\n+\tif err != nil {\n+\t\tlog.Fatal(err)\n+\t}\n+\n+\tg.Go(func() error {\n+\t\treturn private.RunPrivateGateway(ctx, app, privateRouter, privClientConn, httpListener)\n+\t})\n+\n+\treturn g.Wait()\n+}\n+\n+// RunPublicService starts a gRPC server for the public API and accompanying gRPC-Gateway server\n+func runPublicService(ctx context.Context, app *app.App, grpcListener net.Listener, httpListener net.Listener) error {\n+\n+\tpublicRouter := mux.NewRouter()\n+\n+\tg, ctx := errgroup.WithContext(ctx)\n+\n+\tg.Go(func() error {\n+\t\treturn public.RunPublicGRPC(ctx, app, grpcListener)\n+\t})\n+\n+\tclientConn, err := grpc.DialContext(ctx, grpcListener.Addr().String(), grpc.WithInsecure())\n+\tif err != nil {\n+\t\tlog.Fatal(err)\n+\t}\n+\n+\tg.Go(func() error {\n+\t\treturn public.RunPublicGateway(ctx, app, publicRouter, clientConn, httpListener)\n+\t})\n+\n+\treturn g.Wait()\n+}\n+\n+func Server(ctx context.Context, app *app.App) {\n+\t// To record handling time of the RPCs\n+\tgrpc_prometheus.EnableHandlingTimeHistogram()\n+\n+\tif app.Config.PublicPort != 0 {\n+\t\ttcpl, err := net.Listen(\"tcp\", fmt.Sprintf(\":%d\", app.Config.PublicPort))\n+\t\tif err != nil {\n+\t\t\tlog.Fatalf(\"failed to listen: %v\", err)\n+\t\t}\n+\n+\t\ttcpm := cmux.New(tcpl)\n+\t\tgrpcl := tcpm.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings(\"content-type\", \"application/grpc\"))","path":"grpc/server/server.go","position":85,"original_position":85,"commit_id":"f4e4cddc564e1348683379d0ac68396930af2e75","original_commit_id":"f4e4cddc564e1348683379d0ac68396930af2e75","user":{"login":"cainlevy","id":4449,"node_id":"MDQ6VXNlcjQ0NDk=","avatar_url":"https://avatars3.githubusercontent.com/u/4449?v=4","gravatar_id":"","url":"https://api.github.com/users/cainlevy","html_url":"https://github.com/cainlevy","followers_url":"https://api.github.com/users/cainlevy/followers","following_url":"https://api.github.com/users/cainlevy/following{/other_user}","gists_url":"https://api.github.com/users/cainlevy/gists{/gist_id}","starred_url":"https://api.github.com/users/cainlevy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cainlevy/subscriptions","organizations_url":"https://api.github.com/users/cainlevy/orgs","repos_url":"https://api.github.com/users/cainlevy/repos","events_url":"https://api.github.com/users/cainlevy/events{/privacy}","received_events_url":"https://api.github.com/users/cainlevy/received_events","type":"User","site_admin":false},"body":"was looking at the [docs](https://godoc.org/github.com/soheilhy/cmux#HTTP2MatchHeaderFieldSendSettings) and noticed:\r\n\r\n> Prefer HTTP2HeaderField over this one, if the client does not block on receiving a SETTING frame.\r\n\r\nthoughts?","created_at":"2019-07-02T18:38:01Z","updated_at":"2019-07-02T18:53:06Z","html_url":"https://github.com/keratin/authn-server/pull/83#discussion_r299628155","pull_request_url":"https://api.github.com/repos/keratin/authn-server/pulls/83","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/keratin/authn-server/pulls/comments/299628155"},"html":{"href":"https://github.com/keratin/authn-server/pull/83#discussion_r299628155"},"pull_request":{"href":"https://api.github.com/repos/keratin/authn-server/pulls/83"}}},"pull_request":{"url":"https://api.github.com/repos/keratin/authn-server/pulls/83","id":231597820,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMxNTk3ODIw","html_url":"https://github.com/keratin/authn-server/pull/83","diff_url":"https://github.com/keratin/authn-server/pull/83.diff","patch_url":"https://github.com/keratin/authn-server/pull/83.patch","issue_url":"https://api.github.com/repos/keratin/authn-server/issues/83","number":83,"state":"open","locked":false,"title":"gRPC Support","user":{"login":"Mohammed90","id":2636183,"node_id":"MDQ6VXNlcjI2MzYxODM=","avatar_url":"https://avatars2.githubusercontent.com/u/2636183?v=4","gravatar_id":"","url":"https://api.github.com/users/Mohammed90","html_url":"https://github.com/Mohammed90","followers_url":"https://api.github.com/users/Mohammed90/followers","following_url":"https://api.github.com/users/Mohammed90/following{/other_user}","gists_url":"https://api.github.com/users/Mohammed90/gists{/gist_id}","starred_url":"https://api.github.com/users/Mohammed90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mohammed90/subscriptions","organizations_url":"https://api.github.com/users/Mohammed90/orgs","repos_url":"https://api.github.com/users/Mohammed90/repos","events_url":"https://api.github.com/users/Mohammed90/events{/privacy}","received_events_url":"https://api.github.com/users/Mohammed90/received_events","type":"User","site_admin":false},"body":"This PR introduces gRPC support with Protobuf. \r\n\r\nCloses #78 \r\n\r\nContinuous feedback is preferred instead of waiting for me to finish.\r\n\r\nTasks:\r\n\r\n- [x] refactor existing code so it can be reused more readily between HTTP and gRPC servers\r\n- [ ] remove the current server into authn-server/http\r\n- [x] work on a parallel authn-server/gRPC package that can be preferred with a command flag\r\n- [ ] if and when appropriate, bring in grpc-gateway to replace the authn-server/http package\r\n- [x] protect the gRPC API from abuse (existing REST API validates Origin header, gRPC does .... [insert something here])\r\n- [ ] tests, tests, tests\r\n- [N/A] Fix mTLS with with cmux & add tests for it (I feel this is going to be a giant test)\r\n- [x] Address comments [here](https://github.com/keratin/authn-server/pull/83#discussion_r272802380). It's pretty tricky to eliminate dependency on vendor directory. \r\n\r\nCritical bug in current branch:\r\n- [x] mounting on a subpath not working. My hunch is wrapping the handler with `http.StripPrefix` should fix it, but I'm yet to tackle it.\r\n- [x] Work around [this \"bug\"](https://github.com/grpc-ecosystem/grpc-gateway/issues/920).\r\n\r\nResources used and/or might need as reference to complete PR:\r\n\r\n- [So you want to use GoGo Protobuf](https://jbrandhorst.com/post/gogoproto/)\r\n- [Authentication in gRPC](https://mycodesmells.com/post/authentication-in-grpc)\r\n- [HTTP server from gRPC with Gateway](https://mycodesmells.com/post/http-server-from-grpc-with-gateway)\r\n- [gRPC-Gateway Error Handler](https://mycodesmells.com/post/grpc-gateway-error-handler)\r\n- [Advanced gRPC Error Usage](https://jbrandhorst.com/post/grpc-errors/)\r\n- [Workaround to marshal application/x-www-form-urlencoded w/ grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway/issues/7#issuecomment-358569373)\r\n- [https://github.com/grpc-ecosystem/go-grpc-prometheus](https://github.com/grpc-ecosystem/go-grpc-prometheus)","created_at":"2018-11-16T17:08:28Z","updated_at":"2019-07-02T18:53:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"57c63e62ac582d8327b94714a361de722dab63c6","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/keratin/authn-server/pulls/83/commits","review_comments_url":"https://api.github.com/repos/keratin/authn-server/pulls/83/comments","review_comment_url":"https://api.github.com/repos/keratin/authn-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/keratin/authn-server/issues/83/comments","statuses_url":"https://api.github.com/repos/keratin/authn-server/statuses/f4e4cddc564e1348683379d0ac68396930af2e75","head":{"label":"Mohammed90:grpc-api","ref":"grpc-api","sha":"f4e4cddc564e1348683379d0ac68396930af2e75","user":{"login":"Mohammed90","id":2636183,"node_id":"MDQ6VXNlcjI2MzYxODM=","avatar_url":"https://avatars2.githubusercontent.com/u/2636183?v=4","gravatar_id":"","url":"https://api.github.com/users/Mohammed90","html_url":"https://github.com/Mohammed90","followers_url":"https://api.github.com/users/Mohammed90/followers","following_url":"https://api.github.com/users/Mohammed90/following{/other_user}","gists_url":"https://api.github.com/users/Mohammed90/gists{/gist_id}","starred_url":"https://api.github.com/users/Mohammed90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mohammed90/subscriptions","organizations_url":"https://api.github.com/users/Mohammed90/orgs","repos_url":"https://api.github.com/users/Mohammed90/repos","events_url":"https://api.github.com/users/Mohammed90/events{/privacy}","received_events_url":"https://api.github.com/users/Mohammed90/received_events","type":"User","site_admin":false},"repo":{"id":131316288,"node_id":"MDEwOlJlcG9zaXRvcnkxMzEzMTYyODg=","name":"authn-server","full_name":"Mohammed90/authn-server","private":false,"owner":{"login":"Mohammed90","id":2636183,"node_id":"MDQ6VXNlcjI2MzYxODM=","avatar_url":"https://avatars2.githubusercontent.com/u/2636183?v=4","gravatar_id":"","url":"https://api.github.com/users/Mohammed90","html_url":"https://github.com/Mohammed90","followers_url":"https://api.github.com/users/Mohammed90/followers","following_url":"https://api.github.com/users/Mohammed90/following{/other_user}","gists_url":"https://api.github.com/users/Mohammed90/gists{/gist_id}","starred_url":"https://api.github.com/users/Mohammed90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mohammed90/subscriptions","organizations_url":"https://api.github.com/users/Mohammed90/orgs","repos_url":"https://api.github.com/users/Mohammed90/repos","events_url":"https://api.github.com/users/Mohammed90/events{/privacy}","received_events_url":"https://api.github.com/users/Mohammed90/received_events","type":"User","site_admin":false},"html_url":"https://github.com/Mohammed90/authn-server","description":"Authentication service that keeps you in control without forcing you to be an expert in web security.","fork":true,"url":"https://api.github.com/repos/Mohammed90/authn-server","forks_url":"https://api.github.com/repos/Mohammed90/authn-server/forks","keys_url":"https://api.github.com/repos/Mohammed90/authn-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Mohammed90/authn-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Mohammed90/authn-server/teams","hooks_url":"https://api.github.com/repos/Mohammed90/authn-server/hooks","issue_events_url":"https://api.github.com/repos/Mohammed90/authn-server/issues/events{/number}","events_url":"https://api.github.com/repos/Mohammed90/authn-server/events","assignees_url":"https://api.github.com/repos/Mohammed90/authn-server/assignees{/user}","branches_url":"https://api.github.com/repos/Mohammed90/authn-server/branches{/branch}","tags_url":"https://api.github.com/repos/Mohammed90/authn-server/tags","blobs_url":"https://api.github.com/repos/Mohammed90/authn-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Mohammed90/authn-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Mohammed90/authn-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/Mohammed90/authn-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Mohammed90/authn-server/statuses/{sha}","languages_url":"https://api.github.com/repos/Mohammed90/authn-server/languages","stargazers_url":"https://api.github.com/repos/Mohammed90/authn-server/stargazers","contributors_url":"https://api.github.com/repos/Mohammed90/authn-server/contributors","subscribers_url":"https://api.github.com/repos/Mohammed90/authn-server/subscribers","subscription_url":"https://api.github.com/repos/Mohammed90/authn-server/subscription","commits_url":"https://api.github.com/repos/Mohammed90/authn-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/Mohammed90/authn-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/Mohammed90/authn-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/Mohammed90/authn-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/Mohammed90/authn-server/contents/{+path}","compare_url":"https://api.github.com/repos/Mohammed90/authn-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Mohammed90/authn-server/merges","archive_url":"https://api.github.com/repos/Mohammed90/authn-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Mohammed90/authn-server/downloads","issues_url":"https://api.github.com/repos/Mohammed90/authn-server/issues{/number}","pulls_url":"https://api.github.com/repos/Mohammed90/authn-server/pulls{/number}","milestones_url":"https://api.github.com/repos/Mohammed90/authn-server/milestones{/number}","notifications_url":"https://api.github.com/repos/Mohammed90/authn-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Mohammed90/authn-server/labels{/name}","releases_url":"https://api.github.com/repos/Mohammed90/authn-server/releases{/id}","deployments_url":"https://api.github.com/repos/Mohammed90/authn-server/deployments","created_at":"2018-04-27T15:48:21Z","updated_at":"2018-06-12T20:38:39Z","pushed_at":"2019-06-28T21:10:09Z","git_url":"git://github.com/Mohammed90/authn-server.git","ssh_url":"git@github.com:Mohammed90/authn-server.git","clone_url":"https://github.com/Mohammed90/authn-server.git","svn_url":"https://github.com/Mohammed90/authn-server","homepage":"https://keratin.tech","size":1029,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"https://api.github.com/licenses/lgpl-3.0","node_id":"MDc6TGljZW5zZTEy"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"keratin:master","ref":"master","sha":"2201d5bb01bb5a49788c7cf122655d5124a9d978","user":{"login":"keratin","id":23507480,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIzNTA3NDgw","avatar_url":"https://avatars1.githubusercontent.com/u/23507480?v=4","gravatar_id":"","url":"https://api.github.com/users/keratin","html_url":"https://github.com/keratin","followers_url":"https://api.github.com/users/keratin/followers","following_url":"https://api.github.com/users/keratin/following{/other_user}","gists_url":"https://api.github.com/users/keratin/gists{/gist_id}","starred_url":"https://api.github.com/users/keratin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keratin/subscriptions","organizations_url":"https://api.github.com/users/keratin/orgs","repos_url":"https://api.github.com/users/keratin/repos","events_url":"https://api.github.com/users/keratin/events{/privacy}","received_events_url":"https://api.github.com/users/keratin/received_events","type":"Organization","site_admin":false},"repo":{"id":95243941,"node_id":"MDEwOlJlcG9zaXRvcnk5NTI0Mzk0MQ==","name":"authn-server","full_name":"keratin/authn-server","private":false,"owner":{"login":"keratin","id":23507480,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIzNTA3NDgw","avatar_url":"https://avatars1.githubusercontent.com/u/23507480?v=4","gravatar_id":"","url":"https://api.github.com/users/keratin","html_url":"https://github.com/keratin","followers_url":"https://api.github.com/users/keratin/followers","following_url":"https://api.github.com/users/keratin/following{/other_user}","gists_url":"https://api.github.com/users/keratin/gists{/gist_id}","starred_url":"https://api.github.com/users/keratin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keratin/subscriptions","organizations_url":"https://api.github.com/users/keratin/orgs","repos_url":"https://api.github.com/users/keratin/repos","events_url":"https://api.github.com/users/keratin/events{/privacy}","received_events_url":"https://api.github.com/users/keratin/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/keratin/authn-server","description":"Authentication service that keeps you in control without forcing you to be an expert in web security.","fork":false,"url":"https://api.github.com/repos/keratin/authn-server","forks_url":"https://api.github.com/repos/keratin/authn-server/forks","keys_url":"https://api.github.com/repos/keratin/authn-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/keratin/authn-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/keratin/authn-server/teams","hooks_url":"https://api.github.com/repos/keratin/authn-server/hooks","issue_events_url":"https://api.github.com/repos/keratin/authn-server/issues/events{/number}","events_url":"https://api.github.com/repos/keratin/authn-server/events","assignees_url":"https://api.github.com/repos/keratin/authn-server/assignees{/user}","branches_url":"https://api.github.com/repos/keratin/authn-server/branches{/branch}","tags_url":"https://api.github.com/repos/keratin/authn-server/tags","blobs_url":"https://api.github.com/repos/keratin/authn-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/keratin/authn-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/keratin/authn-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/keratin/authn-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/keratin/authn-server/statuses/{sha}","languages_url":"https://api.github.com/repos/keratin/authn-server/languages","stargazers_url":"https://api.github.com/repos/keratin/authn-server/stargazers","contributors_url":"https://api.github.com/repos/keratin/authn-server/contributors","subscribers_url":"https://api.github.com/repos/keratin/authn-server/subscribers","subscription_url":"https://api.github.com/repos/keratin/authn-server/subscription","commits_url":"https://api.github.com/repos/keratin/authn-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/keratin/authn-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/keratin/authn-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/keratin/authn-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/keratin/authn-server/contents/{+path}","compare_url":"https://api.github.com/repos/keratin/authn-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/keratin/authn-server/merges","archive_url":"https://api.github.com/repos/keratin/authn-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/keratin/authn-server/downloads","issues_url":"https://api.github.com/repos/keratin/authn-server/issues{/number}","pulls_url":"https://api.github.com/repos/keratin/authn-server/pulls{/number}","milestones_url":"https://api.github.com/repos/keratin/authn-server/milestones{/number}","notifications_url":"https://api.github.com/repos/keratin/authn-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/keratin/authn-server/labels{/name}","releases_url":"https://api.github.com/repos/keratin/authn-server/releases{/id}","deployments_url":"https://api.github.com/repos/keratin/authn-server/deployments","created_at":"2017-06-23T17:59:36Z","updated_at":"2019-07-01T02:22:08Z","pushed_at":"2019-06-28T21:10:10Z","git_url":"git://github.com/keratin/authn-server.git","ssh_url":"git@github.com:keratin/authn-server.git","clone_url":"https://github.com/keratin/authn-server.git","svn_url":"https://github.com/keratin/authn-server","homepage":"https://keratin.tech","size":806,"stargazers_count":774,"watchers_count":774,"language":"Go","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":44,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":17,"license":{"key":"lgpl-3.0","name":"GNU Lesser General Public License v3.0","spdx_id":"LGPL-3.0","url":"https://api.github.com/licenses/lgpl-3.0","node_id":"MDc6TGljZW5zZTEy"},"forks":44,"open_issues":17,"watchers":774,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/keratin/authn-server/pulls/83"},"html":{"href":"https://github.com/keratin/authn-server/pull/83"},"issue":{"href":"https://api.github.com/repos/keratin/authn-server/issues/83"},"comments":{"href":"https://api.github.com/repos/keratin/authn-server/issues/83/comments"},"review_comments":{"href":"https://api.github.com/repos/keratin/authn-server/pulls/83/comments"},"review_comment":{"href":"https://api.github.com/repos/keratin/authn-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/keratin/authn-server/pulls/83/commits"},"statuses":{"href":"https://api.github.com/repos/keratin/authn-server/statuses/f4e4cddc564e1348683379d0ac68396930af2e75"}},"author_association":"CONTRIBUTOR"}}
other: {"actor":{"display_login":"cainlevy"}}