-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.go
65 lines (53 loc) · 2.35 KB
/
server.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
package main
import (
"log"
"github.com/ChandraNarreddy/sniproxy"
"github.com/ChandraNarreddy/sniproxy/example/authenticators"
)
var (
//Path to which the proxy should redirect the user for authz errors
myAuthorizationErrorRedirectPath = "https://myproxy.domain.com/authorizationError"
//Path to which the proxy should redirect the user for authz failures
myAuthorizationFailedRedirectPath = "https://myproxy.domain.com/requestUnauthorized"
//path to the keyStore file. How to generate here -
// https://github.com/ChandraNarreddy/sillyproxy#generating-the-keystore
myKeyStoreFilePath = "./keystore"
//password to the keystore, please do not use the below
myKeyStorePassword = "test"
//routemap file for sniproxy. More information here -
// https://github.com/ChandraNarreddy/sillyproxy#defining-routes
myRouteMapFilePath = "./routeMapFile.json"
//address to bind
myProxyServerAddr = "0.0.0.0:443"
)
func main() {
//create the Google openIDC authenticator
googleOauthenticator := authenticators.NewGoogleAuth()
//register your authenticator
sniproxy.RegisterAuthenticator("googleAuth", googleOauthenticator)
sniproxy.RegisterAuthenticator("passthrough", &authenticators.PassthroughAuthenticator{})
//Override the authorization error cum failure redirection paths of sniproxy here
sniproxy.AuthorizationErrorRedirectPath = myAuthorizationErrorRedirectPath
sniproxy.AuthorizationFailedRedirectPath = myAuthorizationFailedRedirectPath
//register handlers for default paths
sniproxy.RegisterLocalHandler("defaultAuthorizationErrorLocalHandler",
&sniproxy.DefaultAuthorizationErrorRedirectPathLocalHandler{})
sniproxy.RegisterLocalHandler("defaultAuthorizationFailureLocalHandler",
&sniproxy.DefaultAuthorizationFailedRedirectPathLocalHandler{})
//create your own authToken and authCheckers here or use the defaults
authToken := sniproxy.NewDefaultAuthToken("", nil)
authChecker := sniproxy.NewDefaultAuthChecker(authToken)
//Minimum TLS version we will support
minTLSVersion := uint(2)
//Create the SniProxy here
sniProxy, sniProxyErr := sniproxy.SniProxy(&myKeyStoreFilePath,
&myKeyStorePassword,
&minTLSVersion,
&myProxyServerAddr,
&myRouteMapFilePath,
authChecker)
if sniProxyErr != nil {
log.Fatalf("Setup fail: failed to fire sniProxy - %#v", sniProxyErr.Error())
}
log.Fatalf("SniProxy failure - %#v", sniProxy.ListenAndServeTLS("", ""))
}