summaryrefslogtreecommitdiff
path: root/app/controllers/sessions/controller.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/sessions/controller.go')
-rw-r--r--app/controllers/sessions/controller.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/controllers/sessions/controller.go b/app/controllers/sessions/controller.go
new file mode 100644
index 0000000..9340ab6
--- /dev/null
+++ b/app/controllers/sessions/controller.go
@@ -0,0 +1,26 @@
+package sessions
+
+import (
+ "net/http"
+
+ "golang.org/x/oauth2"
+)
+
+type Controller struct {
+ cfg *oauth2.Config
+}
+
+func New(cfg *oauth2.Config) *Controller {
+ return &Controller{cfg: cfg}
+}
+
+func (c *Controller) MountTo(mux *http.ServeMux) {
+ mux.HandleFunc("GET /session/new", c.New)
+}
+
+func (c *Controller) New(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(http.StatusFound)
+
+ url := c.cfg.AuthCodeURL("csrf-token", oauth2.SetAuthURLParam("audience", "sparklelab.example.com"))
+ http.Redirect(w, r, url, http.StatusFound)
+}