Example #1
0
func InitHandlers() {

	initCodeBaseDir()

	// Register datatypes such that it can be saved in the session.
	gob.Register(SessionUserKey(0))
	gob.Register(&User{})

	// Initialize XSRF token key.
	xsrfKey = "My personal very secure XSRF token key"

	sessKey := []byte("secure-key-234002395432-wsasjasfsfsfsaa-234002395432-wsasjasfsfsfsaa-234002395432-wsasjasfsfsfsaa")

	// Create a session cookie store.
	cookieStore = sessions.NewCookieStore(
		sessKey[:64],
		sessKey[:32],
	)

	cookieStore.Options = &sessions.Options{
		MaxAge:   maxSessionIDAge, // Session valid for 30 Minutes.
		HttpOnly: true,
	}

	// Create identity toolkit client.
	c := &gitkit.Config{
		ServerAPIKey: getConfig(siteName, "serverAPIKey"),
		ClientID:     getConfig(siteName, "clientID"),
		WidgetURL:    WidgetSigninAuthorizedRedirectURL,
	}
	// Service account and private key are not required in GAE Prod.
	// GAE App Identity API is used to identify the app.
	if appengine.IsDevAppServer() {
		c.ServiceAccount = getConfig(siteName, "serviceAccount")
		c.PEMKeyPath = privateKeyPath
	}
	var err error
	gitkitClient, err = gitkit.New(c)
	if err != nil {
		log.Fatal(err)
	}

	// The gorilla sessions use gorilla request context
	ClearHandler := func(fc http.HandlerFunc) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			defer gorillaContext.Clear(r)
			fc(w, r)
		})
	}

	http.Handle(homeURL, ClearHandler(handleHome))

	http.Handle(WidgetSigninAuthorizedRedirectURL, ClearHandler(handleWidget))
	http.Handle(signOutURL, ClearHandler(handleSignOut))

	http.Handle(signinLandingDefaultURL, ClearHandler(handleSigninSuccessLanding))
	http.Handle(signoutLandingDefaultURL, ClearHandler(handleSignOutLanding))

	http.HandleFunc(accountChooserBrandingURL, accountChooserBranding)
}
func initClient(c *cli.Context) error {
	configFile := c.String("config_file")
	var config *gitkit.Config
	var err error
	if configFile != "" {
		config, err = gitkit.LoadConfig(configFile)
		if err != nil {
			return err
		}
	} else {
		config = &gitkit.Config{}
	}
	// It is required but not used.
	config.WidgetURL = "http://localhost"
	// Command line flags overwrite the values in config file.
	if c.IsSet("client_id") {
		config.ClientID = c.String("client_id")
	}
	if c.IsSet("server_api_key") {
		config.ServerAPIKey = c.String("server_api_key")
	}
	if c.IsSet("service_account") {
		config.ServiceAccount = c.String("service_account")
	}
	if c.IsSet("key_path") {
		config.PEMKeyPath = c.String("key_path")
	}

	if client, err = gitkit.New(config); err != nil {
		return err
	}
	return nil
}
func initClient(c *cli.Context) error {
	configFile := c.String("config_file")
	config := &gitkit.Config{}
	var err error
	if configFile != "" {
		var b []byte
		b, err = ioutil.ReadFile(configFile)
		if err != nil {
			return err
		}
		var c CliConfig
		if err = json.Unmarshal(b, &c); err != nil {
			return err
		}
		clientID = c.ClientID
		config.GoogleAppCredentialsPath = c.GoogleAppCredentialsPath
	}
	// It is required but not used.
	config.WidgetURL = "http://localhost"
	// Command line flags overwrite the values in config file.
	if c.IsSet("client_id") {
		clientID = c.String("client_id")
	}
	if c.IsSet("google_app_credentials_path") {
		config.GoogleAppCredentialsPath = c.String("google_app_credentials_path")
	}

	if client, err = gitkit.New(context.Background(), config); err != nil {
		return err
	}
	return nil
}
func initClient(c *cli.Context) error {
	configFile := c.String("config_file")
	var config *gitkit.Config
	var err error
	if configFile != "" {
		config, err = gitkit.LoadConfig(configFile)
		if err != nil {
			return err
		}
	} else {
		config = &gitkit.Config{}
	}
	// It is required but not used.
	config.WidgetURL = "http://localhost"
	// Command line flags overwrite the values in config file.
	if c.IsSet("client_id") {
		config.ClientID = c.String("client_id")
	}
	if c.IsSet("google_app_credentials_path") {
		config.GoogleAppCredentialsPath = c.String("google_app_credentials_path")
	}

	if client, err = gitkit.New(context.Background(), config); err != nil {
		return err
	}
	return nil
}
func init() {
	// Register datatypes such that it can be saved in the session.
	gob.Register(SessionUserKey(0))
	gob.Register(&User{})

	// Initialize XSRF token key.
	xsrfKey = "My very secure XSRF token key"

	// Create a session cookie store.
	cookieStore = sessions.NewCookieStore(
		[]byte("My very secure authentication key for cookie store or generate one using securecookies.GenerateRamdonKey()")[:64],
		[]byte("My very secure encryption key for cookie store or generate one using securecookies.GenerateRamdonKey()")[:32])
	cookieStore.Options = &sessions.Options{
		MaxAge:   86400 * 7, // Session valid for one week.
		HttpOnly: true,
	}

	// Create identity toolkit client.
	c := &gitkit.Config{
		ServerAPIKey: serverAPIKey,
		ClientID:     clientID,
		WidgetURL:    widgetURL,
	}
	// Service account and private key are not required in GAE Prod.
	// GAE App Identity API is used to identify the app.
	if appengine.IsDevAppServer() {
		c.ServiceAccount = serviceAccount
		c.PEMKeyPath = privateKeyPath
	}
	var err error
	gitkitClient, err = gitkit.New(c)
	if err != nil {
		log.Fatal(err)
	}

	r := mux.NewRouter()
	r.HandleFunc(homeURL, handleHome)
	r.HandleFunc(widgetURL, handleWidget)
	r.HandleFunc(signOutURL, handleSignOut)
	r.HandleFunc(oobActionURL, handleOOBAction)
	r.HandleFunc(updateURL, handleUpdate)
	r.HandleFunc(deleteAccountURL, handleDeleteAccount)
	http.Handle("/", r)
}
func init() {
	// Register datatypes such that it can be saved in the session.
	gob.Register(SessionUserKey(0))
	gob.Register(&User{})

	// Initialize XSRF token key.
	xsrfKey = "My very secure XSRF token key"

	// Create a session cookie store.
	cookieStore = sessions.NewCookieStore(
		[]byte("My very secure authentication key for cookie store or generate one using securecookies.GenerateRamdonKey()")[:64],
		[]byte("My very secure encryption key for cookie store or generate one using securecookies.GenerateRamdonKey()")[:32])
	cookieStore.Options = &sessions.Options{
		MaxAge:   86400 * 7, // Session valid for one week.
		HttpOnly: true,
	}

	// Create identity toolkit client.
	c := &gitkit.Config{
		ClientID:  clientID,
		WidgetURL: widgetURL,
	}
	if appengine.IsDevAppServer() {
		c.GoogleAppCredentialsPath = googleAppCredentialsPath
	}
	var err error
	gitkitClient, err = gitkit.New(context.Background(), c)
	if err != nil {
		log.Fatal(err)
	}

	r := mux.NewRouter()
	r.HandleFunc(homeURL, handleHome)
	r.HandleFunc(widgetURL, handleWidget)
	r.HandleFunc(signOutURL, handleSignOut)
	r.HandleFunc(oobActionURL, handleOOBAction)
	r.HandleFunc(updateURL, handleUpdate)
	r.HandleFunc(deleteAccountURL, handleDeleteAccount)
	http.Handle("/", r)
}