-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes.go
93 lines (74 loc) · 2.23 KB
/
routes.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//routes.go
package main
import (
"github.com/gin-gonic/gin"
p "github.com/pe5er/mmindia-website/pages"
"fmt"
"net/http"
)
func routes() *gin.Engine {
e := gin.Default()
e.NoRoute(func(c *gin.Context) {
c.Redirect(301, "/")
})
// Static Pages
e.GET("/", p.Home)
e.GET("/gallery", p.Gallery)
e.GET("/news", p.News)
e.GET("/robots.txt", p.Robots)
e.GET("/privacy", p.Privacy)
e.GET("/contact", p.Contact)
e.GET("/team", p.Team)
e.GET("/pm", p.Pm)
e.GET("/ethics", p.Ethics)
e.GET("/docs", p.Documents)
e.GET("/blog", p.Blog)
e.GET("/login", p.Login)
e.GET("/userarea", p.Userarea)
e.Static("/css", "static/css/")
e.GET("/auth/github", redirectHandler)
e.GET("/auth/github/callback", callbackHandler)
return e
}
func redirectHandler(c *gin.Context) {
// Define our settings
appSettings := map[string]string{
"clientID": "c5d5ccfa293ba72d15c9",
"clientSecret": "dc96f2fa2f9d41b3eb95ed57b9b57dc7394b1855",
"redirectURL": "http://www.mmindia.uk/auth/github/callback",
}
// Retrieve the URL
authURL, err := gocial.New().
Driver("github").
Scopes([]string{"public_repo"}). // Specify custom scopes
Redirect(
appSettings["clientID"],
appSettings["clientSecret"],
appSettings["redirectURL"],
)
// Check for errors
if err != nil {
c.Writer.Write([]byte("Error: " + err.Error()))
return
}
// Redirect to authURL with status 302
c.Redirect(http.StatusFound, authURL)
}
// Collect user info
func callbackHandler(c *gin.Context) {
// Retrieve query params for state and code
state := c.Query("state")
code := c.Query("code")
// Handle callback and check for errors
user, token, err := gocial.Handle(state, code)
if err != nil {
c.Writer.Write([]byte("Error: " + err.Error()))
return
}
// Print token information
fmt.Printf("%#v", token)
// Print in terminal user information
fmt.Printf("%#v", user)
// If no errors, show provider name
c.Writer.Write([]byte("Hi, " + user.FullName))
}