Esempio n. 1
0
func Test_UseProviders(t *testing.T) {
	a := assert.New(t)

	provider := &faux.Provider{}
	goth.UseProviders(provider)
	a.Equal(len(goth.GetProviders()), 1)
	a.Equal(goth.GetProviders()[provider.Name()], provider)
	goth.ClearProviders()
}
func main_() {
	log.Println("fff")
	providers := goth.GetProviders()
	log.Printf("%v", providers)
	for _, provider := range providers {
		log.Println(provider.Name())
	}
}
//GetProviders ...
func GetProviders() goth.Providers {
	return goth.GetProviders()
}
Esempio n. 4
0
func Serve(s *server.Server) {
	config, err := NewConfigFromJSON(options.ConfigFile)
	if err != nil {
		log.Fatal("no config file")
	}

	gauthConfig := server.GoogleAuthConfig(config.GAuthKeyFile, options.Debug)
	goth.UseProviders(
		twitter.New(config.TwitterApiKey, config.TwitterApiSecret, config.TwitterApiCallback),
		gplus.New(gauthConfig.ClientID, gauthConfig.ClientSecret, gauthConfig.RedirectURL),
	)
	providers := goth.GetProviders()
	providers["google"] = providers["gplus"]

	// Assign the GetState function variable so we can return the
	// state string we want to get back at the end of the oauth process.
	// Only works with facebook and gplus providers.
	gothic.GetState = func(req *http.Request) string {
		// Get the state string from the query parameters.
		return req.URL.Query().Get("next")
	}

	r := gin.Default()
	r.HTMLRender = NewRender()
	// session
	store := sessions.NewCookieStore([]byte(options.SecretKey))
	r.Use(sessions.Sessions("ffsession", store))

	// Serve static assets
	if options.Debug {
		log.Println("==> debug mode")
		r.Static("/static", "./static")
	} else {
		r.GET("/static/*path", AssetHandler)
	}

	// oauth2
	r.GET("/auth/:provider/callback", s.AuthCallback)
	r.GET("/auth/:provider", server.AuthProvider)

	// authed
	authorized := r.Group("/account", server.LoginRequired())
	{
		authorized.GET("/", s.AccountHandler)
		authorized.GET("/import/", s.ImportHandler)
		// authorized.POST("/ffimport/", s.FriendFeedImportHandler)
		authorized.GET("/import/twitter", s.TwitterImportHandler)
		// TODO: fix get
		authorized.GET("/service/:service/delete", s.DeleteServiceHandler)
	}

	r.GET("/", s.HomeHandler)
	r.GET("favicon.ico", FaviconHandler)
	r.GET("/logout", server.LogoutHandler)

	// TODO: httproute not support "/:name" to catch all
	// see: gin #205
	r.GET("/feed/:name", s.FeedHandler)
	r.GET("/e/:uuid", s.EntryHandler)

	r.GET("/a/entry/:uuid", s.ExpandCommentHandler)
	r.GET("/a/expandlikes/:uuid", s.ExpandLikeHandler)
	action := r.Group("/a", server.LoginRequired())
	{
		action.POST("/share", s.EntryPostHandler)
		action.POST("/like", s.LikeHandler)
		action.POST("/like/delete", s.LikeDeleteHandler)
		action.POST("/comment", s.CommentHandler)
		action.POST("/comment/delete", s.CommentDeleteHandler)
	}

	r.GET("/public", s.PublicHandler)

	r.NotFound404(NotFoundHandler)

	fmt.Println("Starting server...")
	r.Run(fmt.Sprintf(":%v", options.Port))
}