nitweb: add API user login/logout end points
authorAlexandre Terrasa <alexandre@moz-code.org>
Sun, 14 Aug 2016 18:39:24 +0000 (14:39 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Sun, 14 Aug 2016 18:39:24 +0000 (14:39 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/nitweb.nit

index a953fcb..9484425 100644 (file)
 module nitweb
 
 import popcorn::pop_config
+import popcorn::pop_auth
 import frontend
 import web
 
+redef class NitwebConfig
+
+       # Github client id used for Github OAuth login.
+       #
+       # * key: `github.client_id`
+       # * default: ``
+       var github_client_id: String is lazy do return value_or_default("github.client.id", "")
+
+       # Github client secret used for Github OAuth login.
+       #
+       # * key: `github.client_secret`
+       # * default: ``
+       var github_client_secret: String is lazy do
+               return value_or_default("github.client.secret", "")
+       end
+end
+
 redef class ToolContext
 
        # Path to app config file.
@@ -91,6 +109,9 @@ private class NitwebPhase
                app.use_before("/*", new SessionInit)
                app.use_before("/*", new RequestClock)
                app.use("/api", new NitwebAPIRouter(config, catalog))
+               app.use("/login", new GithubLogin(config.github_client_id))
+               app.use("/oauth", new GithubOAuthCallBack(config.github_client_id, config.github_client_secret))
+               app.use("/logout", new GithubLogout)
                app.use("/*", new StaticHandler(toolcontext.share_dir / "nitweb", "index.html"))
                app.use_after("/*", new ConsoleLog)
 
@@ -120,6 +141,7 @@ class NitwebAPIRouter
                use("/graph/", new APIGraphRouter(config))
                use("/docdown/", new APIDocdown(config))
                use("/metrics/", new APIMetricsRouter(config))
+               use("/user", new GithubUser)
        end
 end