// Example way to run an goauth2 server func ExampleRunGoauth2ServerWithRedis(port int) { // Create your implementations of AuthCache ac := NewRedisAuthCache(redis_addr, redis_dbnum, redis_pass) // Create your implementation of AuthHandler auth := authhandler.NewWhiteList("client1") // Create the store and the server server := goauth2.NewServer(ac, auth) // Create the Serve Mux for http serving sm := http.NewServeMux() sm.Handle("/authorize", server.MasterHandler()) // You might have multiple uses, each should be wrapped using TokenVerifier sm.Handle("/api", server.TokenVerifier(http.HandlerFunc(TestApiHandler))) // Create the http server httpd := &http.Server{ Addr: fmt.Sprintf(":%d", port), Handler: sm, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, MaxHeaderBytes: 1 << 20, } // Start the server log.Fatal(httpd.ListenAndServe()) }
// Example way to run an goauth2 server func ExampleRunGoauth2ServerWithRedirecter(port int, redirectUrl string) { // Create your implementations of AuthCache ac := authcache.NewBasicAuthCache() // Create your implementation of AuthHandler auth, err := authhandler.NewRedirecter(redirectUrl, redirectUrl) if err != nil { log.Fatal("Error intializing Redirecter", err) } // Create the store and the server server := goauth2.NewServer(ac, auth) // Create the Serve Mux for http serving sm := http.NewServeMux() sm.Handle("/authorize", server.MasterHandler()) // You might have multiple uses, each should be wrapped using TokenVerifier sm.Handle("/api", server.TokenVerifier(http.HandlerFunc(TestApiHandler))) // Create the http server httpd := &http.Server{ Addr: fmt.Sprintf(":%d", port), Handler: sm, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, MaxHeaderBytes: 1 << 20, } // Start the server log.Fatal(httpd.ListenAndServe()) }