Esempio n. 1
0
func setup() (*httptest.Server, goth.AuthHandler) {
	// Reset test muxer each run
	testMux = http.NewServeMux()
	authHandler := goth.DefaultAuthHandler
	authHandler.UserStore = gobstore.NewUserGobStore(testUserStorePath)
	testMux.HandleFunc(authHandler.RoutePath, authHandler.ServeHTTP)
	testMux.HandleFunc("/", makeHelloUserHandler(authHandler))
	return httptest.NewServer(testMux), authHandler
}
Esempio n. 2
0
File: goth.go Progetto: jroes/goth
	// sessions. It should be kept private from any source repositories. You could
	// use os.Getenv() for this and store it in an environment variable.
	SessionSecret string
	SessionStore  *sessions.CookieStore
	UserStore     UserStore
}

var DefaultAuthHandler = AuthHandler{
	RoutePath:        "/auth/",
	TemplatePath:     "tmpl/",
	AfterSignupPath:  "/",
	AfterSigninPath:  "/",
	AfterSignoutPath: "/",
	SessionSecret:    "change-me-please",
	SessionStore:     sessions.NewCookieStore([]byte("change-me-please")),
	UserStore:        gobstore.NewUserGobStore("users/"),
}

// ServeHTTP implements the http.Handler interface to delegate
// authentication-related routing to the proper handler.
func (handler AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	actionRegexp := regexp.MustCompile(".*\\/(.*)")
	actionMatches := actionRegexp.FindStringSubmatch(r.URL.Path)
	if actionMatches == nil || len(actionMatches) != 2 {
		fmt.Printf("Unexpected request: %s", r.URL.Path)
		http.NotFound(w, r)
		return
	}

	action := actionMatches[1]