forked from HackIllinois/api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.go
78 lines (67 loc) · 2.18 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
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
package services
import (
"net/http"
"github.com/HackIllinois/api/gateway/config"
"github.com/HackIllinois/api/gateway/middleware"
"github.com/HackIllinois/api/gateway/models"
"github.com/arbor-dev/arbor"
"github.com/justinas/alice"
)
var AuthURL = config.AUTH_SERVICE
const AuthFormat string = "JSON"
var AuthRoutes = arbor.RouteCollection{
arbor.Route{
"OauthRedirect",
"GET",
"/auth/{provider}/",
alice.New(middleware.IdentificationMiddleware).ThenFunc(OauthRedirect).ServeHTTP,
},
arbor.Route{
"OauthCode",
"POST",
"/auth/code/{provider}/",
alice.New(middleware.IdentificationMiddleware).ThenFunc(OauthCode).ServeHTTP,
},
arbor.Route{
"GetUserRoles",
"GET",
"/auth/roles/{id}/",
alice.New(middleware.AuthMiddleware([]models.Role{models.AdminRole}), middleware.IdentificationMiddleware).ThenFunc(GetUserRoles).ServeHTTP,
},
arbor.Route{
"AddUserRole",
"PUT",
"/auth/roles/add/",
alice.New(middleware.AuthMiddleware([]models.Role{models.AdminRole}), middleware.IdentificationMiddleware).ThenFunc(AddUserRole).ServeHTTP,
},
arbor.Route{
"RemoveUserRole",
"PUT",
"/auth/roles/remove/",
alice.New(middleware.AuthMiddleware([]models.Role{models.AdminRole}), middleware.IdentificationMiddleware).ThenFunc(RemoveUserRole).ServeHTTP,
},
arbor.Route{
"RefreshToken",
"GET",
"/auth/token/refresh/",
alice.New(middleware.AuthMiddleware([]models.Role{models.UserRole}), middleware.IdentificationMiddleware).ThenFunc(RefreshToken).ServeHTTP,
},
}
func OauthRedirect(w http.ResponseWriter, r *http.Request) {
arbor.GET(w, AuthURL+r.URL.String(), AuthFormat, "", r)
}
func OauthCode(w http.ResponseWriter, r *http.Request) {
arbor.POST(w, AuthURL+r.URL.String(), AuthFormat, "", r)
}
func GetUserRoles(w http.ResponseWriter, r *http.Request) {
arbor.GET(w, AuthURL+r.URL.String(), AuthFormat, "", r)
}
func AddUserRole(w http.ResponseWriter, r *http.Request) {
arbor.PUT(w, AuthURL+r.URL.String(), AuthFormat, "", r)
}
func RemoveUserRole(w http.ResponseWriter, r *http.Request) {
arbor.PUT(w, AuthURL+r.URL.String(), AuthFormat, "", r)
}
func RefreshToken(w http.ResponseWriter, r *http.Request) {
arbor.GET(w, AuthURL+r.URL.String(), AuthFormat, "", r)
}