forked from G-Node/gin-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.go
74 lines (69 loc) · 3.02 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
// Copyright (c) 2016, German Neuroinformatics Node (G-Node),
// Adrian Stoewer <adrian.stoewer@rz.ifi.lmu.de>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted under the terms of the BSD License. See
// LICENSE file in the root of the Project.
package web
import (
"net/http"
"github.com/dchest/captcha"
"github.com/gorilla/mux"
)
// RegisterRoutes adds all registered routes for this app to the
// main router. This should make it easier to get a quick overview
// over all routes.
func RegisterRoutes(r *mux.Router) {
// all for /oauth
oauth := r.PathPrefix("/oauth").Subrouter()
oauth.HandleFunc("/authorize", Authorize).
Methods("GET")
oauth.HandleFunc("/login_page", LoginPage).
Methods("GET")
oauth.HandleFunc("/login", LoginWithCredentials).
Methods("POST")
oauth.HandleFunc("/login", LoginWithSession).
Methods("GET")
oauth.HandleFunc("/approve_page", ApprovePage).
Methods("GET")
oauth.HandleFunc("/approve", Approve).
Methods("POST")
oauth.HandleFunc("/logout/{token}", Logout).
Methods("GET")
oauth.HandleFunc("/registration_page", RegistrationPage).Methods("GET")
oauth.Handle("/registration", RegistrationHandler(captcha.VerifyString)).Methods("POST")
oauth.HandleFunc("/registered_page", RegisteredPage).Methods("GET")
oauth.HandleFunc("/activation", Activation).Methods("GET")
oauth.HandleFunc("/reset_init_page", ResetInitPage).Methods("GET")
oauth.HandleFunc("/reset_init", ResetInit).Methods("POST")
oauth.HandleFunc("/reset_page", ResetPage).Methods("GET")
oauth.HandleFunc("/reset", Reset).Methods("POST")
oauth.HandleFunc("/token", Token).
Methods("POST")
oauth.HandleFunc("/validate/{token}", Validate).
Methods("GET")
// all for /api
api := r.PathPrefix("/api").Subrouter()
api.Handle("/accounts", OAuthHandlerPermissive()(http.HandlerFunc(ListAccounts))).
Methods("GET")
api.Handle("/accounts/{login}", OAuthHandlerPermissive()(http.HandlerFunc(GetAccount))).
Methods("GET")
api.Handle("/accounts/{login}", OAuthHandler("account-write", "account-admin")(http.HandlerFunc(UpdateAccount))).
Methods("PUT")
api.Handle("/accounts/{login}/password", OAuthHandler("account-write")(http.HandlerFunc(UpdateAccountPassword))).
Methods("PUT")
api.Handle("/accounts/{login}/email", OAuthHandler("account-write")(http.HandlerFunc(UpdateAccountEmail))).
Methods("PUT")
api.Handle("/accounts/{login}/keys", OAuthHandler("account-read", "account-admin")(http.HandlerFunc(ListAccountKeys))).
Methods("GET")
api.Handle("/accounts/{login}/keys", OAuthHandler("account-write")(http.HandlerFunc(CreateKey))).
Methods("POST")
api.Handle("/keys/{fingerprint}", OAuthHandler("account-read", "account-admin")(http.HandlerFunc(GetKey))).
Methods("GET")
api.Handle("/keys/{fingerprint}", OAuthHandler("account-write")(http.HandlerFunc(DeleteKey))).
Methods("DELETE")
// captcha service
cpt := r.PathPrefix("/captcha").Subrouter()
cpt.Handle("/{id}", captcha.Server(captcha.StdWidth, captcha.StdHeight)).Methods("GET")
}