-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
auth.go
51 lines (43 loc) · 1.3 KB
/
auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package actions
import (
"fmt"
"os"
//"net/http"
"github.com/gobuffalo/buffalo"
"github.com/markbates/goth"
"github.com/markbates/goth/gothic"
"github.com/markbates/goth/providers/github"
)
func init() {
gothic.Store = App().SessionStore
goth.UseProviders(
github.New(os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"), fmt.Sprintf("%s%s", App().Host, "/auth/github/callback")),
)
}
//func AuthCallback(c buffalo.Context) error {
// user, err := gothic.CompleteUserAuth(c.Response(), c.Request())
// if err != nil {
// return c.Error(401, err)
// }
// // Do something with the user, maybe register them/sign them in
// // Adding the userID to the session to remember the logged in user
// session := c.Session()
// session.Set("userID", user.UserID)
// err = session.Save()
// if err != nil {
// return c.Error(401, err)
// }
// // The default value jus renders the data we get by GitHub
// // return c.Render(200, r.JSON(user))
//
// // After the user is logged in we add a redirect
// return c.Redirect(http.StatusMovedPermanently, "/secure")
//}
func AuthCallback(c buffalo.Context) error {
user, err := gothic.CompleteUserAuth(c.Response(), c.Request())
if err != nil {
return c.Error(401, err)
}
// Do something with the user, maybe register them/sign them in
return c.Render(200, r.JSON(user))
}