当前位置: 首页>>代码示例>>Golang>>正文


Golang goth.UseProviders函数代码示例

本文整理汇总了Golang中github.com/markbates/goth.UseProviders函数的典型用法代码示例。如果您正苦于以下问题:Golang UseProviders函数的具体用法?Golang UseProviders怎么用?Golang UseProviders使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了UseProviders函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	flag.Parse()

	err := godotenv.Load(fmt.Sprintf("config/%s.env", *env))
	if err != nil {
		log.Fatal(err)
		return
	}

	goth.UseProviders(
		github.New(os.Getenv("GITHUB_CLIENT_KEY"), os.Getenv("GITHUB_SECRET"), os.Getenv("GITHUB_CALLBACK")),
	)

	p := pat.New()

	r := newRoom()
	r.tracer = trace.New(os.Stdout)
	p.Add("GET", "/chat", MustAuth(&templateHandler{filename: "chat.html"}))
	p.Add("GET", "/login", &templateHandler{filename: "login.html"})
	p.Get("/auth/{action}/{provider}", loginHandler)
	p.Add("GET", "/room", r)

	// チャットルームの開始
	go r.run()
	// Webサーバの起動
	log.Println("Webサーバーを開始します。ポート: ", *addr)
	if err := http.ListenAndServe(*addr, p); err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
开发者ID:kakawamura,项目名称:donuts-tech-calendar,代码行数:30,代码来源:main.go

示例2: init

func init() {
	gothic.Store = sessions.NewFilesystemStore(os.TempDir(), []byte("goth-example"))
	goth.UseProviders(
		twitter.New(os.Getenv("TWITTER_KEY"), os.Getenv("TWITTER_SECRET"), "http://localhost:3000/auth/twitter/callback"),
		// If you'd like to use authenticate instead of authorize in Twitter provider, use this instead.
		// twitter.NewAuthenticate(os.Getenv("TWITTER_KEY"), os.Getenv("TWITTER_SECRET"), "http://localhost:3000/auth/twitter/callback"),

		facebook.New(os.Getenv("FACEBOOK_KEY"), os.Getenv("FACEBOOK_SECRET"), "http://localhost:3000/auth/facebook/callback"),
		gplus.New("281140391713-b1dskle4dtsi6nn4ce01tbkpcp3aovs6.apps.googleusercontent.com", "cIM92vsFvLyfhIZASmAo2ZaE", "http://localhost:8080/auth/gplus/callback"),
		github.New(os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"), "http://localhost:3000/auth/github/callback"),
		spotify.New(os.Getenv("SPOTIFY_KEY"), os.Getenv("SPOTIFY_SECRET"), "http://localhost:3000/auth/spotify/callback"),
		linkedin.New(os.Getenv("LINKEDIN_KEY"), os.Getenv("LINKEDIN_SECRET"), "http://localhost:3000/auth/linkedin/callback"),
		lastfm.New(os.Getenv("LASTFM_KEY"), os.Getenv("LASTFM_SECRET"), "http://localhost:3000/auth/lastfm/callback"),
		twitch.New(os.Getenv("TWITCH_KEY"), os.Getenv("TWITCH_SECRET"), "http://localhost:3000/auth/twitch/callback"),
		dropbox.New(os.Getenv("DROPBOX_KEY"), os.Getenv("DROPBOX_SECRET"), "http://localhost:3000/auth/dropbox/callback"),
		digitalocean.New(os.Getenv("DIGITALOCEAN_KEY"), os.Getenv("DIGITALOCEAN_SECRET"), "http://localhost:3000/auth/digitalocean/callback", "read"),
		bitbucket.New(os.Getenv("BITBUCKET_KEY"), os.Getenv("BITBUCKET_SECRET"), "http://localhost:3000/auth/bitbucket/callback"),
		instagram.New(os.Getenv("INSTAGRAM_KEY"), os.Getenv("INSTAGRAM_SECRET"), "http://localhost:3000/auth/instagram/callback"),
		box.New(os.Getenv("BOX_KEY"), os.Getenv("BOX_SECRET"), "http://localhost:3000/auth/box/callback"),
		salesforce.New(os.Getenv("SALESFORCE_KEY"), os.Getenv("SALESFORCE_SECRET"), "http://localhost:3000/auth/salesforce/callback"),
		amazon.New(os.Getenv("AMAZON_KEY"), os.Getenv("AMAZON_SECRET"), "http://localhost:3000/auth/amazon/callback"),
		yammer.New(os.Getenv("YAMMER_KEY"), os.Getenv("YAMMER_SECRET"), "http://localhost:3000/auth/yammer/callback"),
		onedrive.New(os.Getenv("ONEDRIVE_KEY"), os.Getenv("ONEDRIVE_SECRET"), "http://localhost:3000/auth/onedrive/callback"),
	)

	//set a global session
	globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "sessionIDHashFunc": "sha1", "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`)
	go globalSessions.GC()
}
开发者ID:eraserxp,项目名称:coedit,代码行数:29,代码来源:auth.go

示例3: init

func init() {
	goth.UseProviders(
		twitter.New(os.Getenv("TWITTER_KEY"),
			os.Getenv("TWITTER_SECRET"),
			"http://localhost:8080/auth/twitter/callback?provider=twitter"),
	)
}
开发者ID:khirayama,项目名称:bulletin-board-with-go,代码行数:7,代码来源:app.go

示例4: Service

func Service() helios.ServiceHandler {
	return func(h *helios.Engine) {
		g := &GithubService{
			Users:        make(map[string]User),
			EventChan:    h.NewBroadcastChannel("github", true),
			githubKey:    h.Config.GetString("github.apiKey"),
			githubSecret: h.Config.GetString("github.apiSecret"),
		}

		// Set the initial last event time to now
		g.LastEvent.EventTime = time.Now()

		// Setup Goth Authentication
		goth.UseProviders(
			githubProvider.New(g.githubKey, g.githubSecret, fmt.Sprintf("http://%s:%s/auth/github/callback", h.Config.GetString("host"), h.Config.GetString("port")), "repo", "user:email"),
		)

		// Setup github auth routes
		h.HTTPEngine.GET("/auth/github/callback", providerCallback(h, g))
		h.HTTPEngine.GET("/auth/github", providerAuth)

		// Load registered users
		err := loadUsersCSV(g)
		if err != nil {
			h.Error("Failed to load users from csv", "error", err.Error())
		}

		// Start Existing Users
		h.Debug("Starting existing github user go routines")
		startExistingUsers(g)
	}
}
开发者ID:joelhawksley,项目名称:helios,代码行数:32,代码来源:github.go

示例5: main

func main() {

	workingDirectory, err := os.Getwd()

	if err != nil {
		fmt.Println("working directory error")
		return
	}

	gothic.GetProviderName = func(req *http.Request) (string, error) {
		return "amazon", nil
	}

	goth.UseProviders(
		amazon.New(os.Getenv("AMAZON_KEY"), os.Getenv("AMAZON_SECRET"), "https://ecloud.nimbostrati.com:9898/auth/amazon/callback", "profile"),
	)

	router.HandleFunc("/", makeIndexPageHandler(workingDirectory+"/app/splash.html"))
	router.HandleFunc("/auth/amazon/callback", callbackPageHandler)
	router.HandleFunc("/auth/amazon", startAuthHandler)

	ServeStatic(router, workingDirectory)

	http.Handle("/", router)

	fmt.Println("About to listen and serve from(", workingDirectory, ").")
	http.ListenAndServeTLS(":9898", os.Getenv("GOTH_SSL_CERT"), os.Getenv("GOTH_SSL_KEY"), nil)
}
开发者ID:ggrajek,项目名称:pynn,代码行数:28,代码来源:server.go

示例6: Test_UseProviders

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()
}
开发者ID:drathier,项目名称:goth,代码行数:9,代码来源:provider_test.go

示例7: InitGothic

func (s *Server) InitGothic() {
	goth.UseProviders(
		facebook.New(s.Config.Facebook.AppId, s.Config.Facebook.Secret, s.Config.Facebook.CallbackURL),
	)
	// Since we are using only ONE provider, FACEBOOK - it doesn't have make sense to parse url for provider name
	gothic.GetProviderName = func(req *http.Request) (string, error) {
		return "facebook", nil
	}
}
开发者ID:dkondratovych,项目名称:goapi-example,代码行数:9,代码来源:server.go

示例8: main

func main() {
	const BaseURL = "http://localhost:8000"
	goth.UseProviders(
		twitter.New(os.Getenv("TWITTER_KEY"), os.Getenv("TWITTER_SECRET"), BaseURL+"/auth/twitter/callback"),
		facebook.New(os.Getenv("FACEBOOK_KEY"), os.Getenv("FACEBOOK_SECRET"), BaseURL+"/auth/facebook/callback"),
		gplus.New(os.Getenv("GPLUS_KEY"), os.Getenv("GPLUS_SECRET"), BaseURL+"/auth/gplus/callback"),
		github.New(os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"), BaseURL+"/auth/github/callback"),
		spotify.New(os.Getenv("SPOTIFY_KEY"), os.Getenv("SPOTIFY_SECRET"), BaseURL+"/auth/spotify/callback"),
		linkedin.New(os.Getenv("LINKEDIN_KEY"), os.Getenv("LINKEDIN_SECRET"), BaseURL+"/auth/linkedin/callback"),
		lastfm.New(os.Getenv("LASTFM_KEY"), os.Getenv("LASTFM_SECRET"), BaseURL+"/auth/lastfm/callback"),
		twitch.New(os.Getenv("TWITCH_KEY"), os.Getenv("TWITCH_SECRET"), BaseURL+"/auth/twitch/callback"),
	)

	tpl := template.New("")
	template.Must(tpl.New("index.html").Parse(`
<p><a href="/auth/twitter">Log in with Twitter</a></p>
<p><a href="/auth/facebook">Log in with Facebook</a></p>
<p><a href="/auth/gplus">Log in with GPlus</a></p>
<p><a href="/auth/github">Log in with Github</a></p>
<p><a href="/auth/spotify">Log in with Spotify</a></p>
<p><a href="/auth/lastfm">Log in with LastFM</a></p>
<p><a href="/auth/twitch">Log in with Twitch</a></p>
`))
	template.Must(tpl.New("user.html").Parse(`
<p>Name: {{.Name}}</p>
<p>Email: {{.Email}}</p>
<p>NickName: {{.NickName}}</p>
<p>Location: {{.Location}}</p>
<p>AvatarURL: {{.AvatarURL}} <img src="{{.AvatarURL}}"></p>
<p>Description: {{.Description}}</p>
<p>UserID: {{.UserID}}</p>
<p>AccessToken: {{.AccessToken}}</p>
`))

	r := gin.Default()
	r.SetHTMLTemplate(tpl)
	r.GET("/auth/:provider", func(c *gin.Context) {
		err := gothic.BeginAuth(c.Param("provider"), c.Writer, c.Request)
		if err != nil {
			c.AbortWithError(http.StatusInternalServerError, err)
			return
		}
	})
	r.GET("/auth/:provider/callback", func(c *gin.Context) {
		user, err := gothic.CompleteAuth(c.Param("provider"), c.Writer, c.Request)
		if err != nil {
			c.AbortWithError(http.StatusInternalServerError, err)
			return
		}
		c.HTML(http.StatusOK, "user.html", user)
	})
	r.GET("/", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.html", nil)
	})
	log.Fatal(r.Run(":8000"))
}
开发者ID:oov,项目名称:gothic,代码行数:56,代码来源:gin.go

示例9: Init

// Init initializes the API, setting up the OAuth providers whose required
// information is contained within the given config.
func Init(config *config.Config) {
	apiConfig = config
	indexTemplate = template.Must(template.ParseFiles(apiConfig.Website.Directory + "index.html"))
	rest.ErrorFieldName = "error"
	goth.UseProviders(
		gplus.New(config.Google.ClientID, config.Google.ClientSecret, config.Google.CallbackURL),
		// facebook.New(config.Facebook.ClientID, config.Facebook.ClientSecret, config.Facebook.CallbackURL),
		// twitter.New(config.Twitter.ClientID, config.Twitter.ClientSecret, config.Twitter.CallbackURL),
	)
}
开发者ID:joshheinrichs,项目名称:geosource,代码行数:12,代码来源:api.go

示例10: main

func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	beego.SetLogFuncCall(true)
	beego.SessionOn = true
	goth.UseProviders(
		gplus.New(
			beego.AppConfig.String("CLIENT_ID"),
			beego.AppConfig.String("CLIENT_SECRET"),
			beego.AppConfig.String("CLIENT_CALLBACK"),
		),
	)
	SessionTimeout, err := beego.AppConfig.Int("SESSION_TIMEOUT")
	if err != nil {
		beego.Critical(err)
	}
	SessionRefreshInterval, err := beego.AppConfig.Int("SESSION_REFRESH_INTERVAL")
	if err != nil {
		beego.Critical(err)
	}
	goJwt.Conf = goJwt.JwtConf{
		PrivateKeyFile:         beego.AppConfig.String("PrivateKeyFile"),
		PublicKeyFile:          beego.AppConfig.String("PublicKeyFile"),
		Algorithm:              beego.AppConfig.String("Algorithm"),
		SessionSecret:          beego.AppConfig.String("SESSION_SECRET"),
		SessionName:            beego.AppConfig.String("SESSION_NAME"),
		SessionTimeout:         SessionTimeout,
		SessionRefreshInterval: SessionRefreshInterval,
	}
	goJwt.Configure()
	goJwt.Store = sessions.NewCookieStore([]byte(beego.AppConfig.String("SESSION_SECRET")))

	ldapPort, err := beego.AppConfig.Int("Ldap_port")
	if err != nil {
		beego.Critical(err)
	}
	tim.Conf = tim.LdapConf{
		Ldap_server: beego.AppConfig.String("Ldap_server"),
		Ldap_port:   uint16(ldapPort),
		Base_dn:     beego.AppConfig.String("Base_dn"),
		Ldap_user:   beego.AppConfig.String("Ldap_user"),
		Ldap_pass:   beego.AppConfig.String("Ldap_pass"),
	}

	beego.SetStaticPath("/public", "static")

	if err != nil {
		beego.Critical("Cannot connect to Redis: ", err)
		return
	}

	beego.Run()
}
开发者ID:ovino,项目名称:goSkeleton,代码行数:52,代码来源:main.go

示例11: main

func main() {
	goth.UseProviders(gplus.New(gPlusClientID, gPlusClientSecret, "http://localhost:8080/auth/gplus/callback"))

	mainRouter := http.NewServeMux()
	mainRouter.HandleFunc("/", logInHandler)
	mainRouter.HandleFunc("/auth/gplus", beginAuthHandler)
	mainRouter.HandleFunc("/auth/gplus/callback", callbackHandler)
	mainRouter.HandleFunc("/hello", helloHandler)
	fmt.Println("Serving http://localhost" + port)
	if err := http.ListenAndServe(port, mainRouter); err != nil {
		panic(err)
	}
}
开发者ID:niukey,项目名称:learn,代码行数:13,代码来源:00_authentication.go

示例12: main

func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)

	googleJsonKey, err := ioutil.ReadFile(GOOGLE_CLIENT_SECRET_FILE_PATH)
	if err != nil {
		log.Fatalln("unable to read file ", GOOGLE_CLIENT_SECRET_FILE_PATH,
			":", err)
	}
	facebookJsonKey, err := ioutil.ReadFile(FACEBOOK_CLIENT_SECRET_FILE_PATH)
	if err != nil {
		log.Fatalln("unable to read file ", FACEBOOK_CLIENT_SECRET_FILE_PATH,
			":", err)
	}

	// do I need more scopes?
	// https://developers.google.com/+/domains/authentication/scopes
	googleConfig, err := google.ConfigFromJSON(googleJsonKey)
	if err != nil {
		log.Fatalln("unable to get google provider config:", err)
	}
	facebookConfig := &genericConfig{}
	err = json.Unmarshal(facebookJsonKey, facebookConfig)
	if err != nil {
		log.Fatalln("unable to get facebook provider config:", err)
	}

	//I need "profile", "email", scopes. gplus and facebook provide these by
	//default.
	goth.UseProviders(
		gplus.New(googleConfig.ClientID, googleConfig.ClientSecret,
			AUTH_CALLBACK_URL),
		facebook.New(facebookConfig.Client_id, facebookConfig.Client_secret, AUTH_CALLBACK_URL),
	)

	chat = NewChat()
	router = pat.New()

	router.Get("/ws", WsHandler)
	router.Get("/oauth2callback", AuthCallbackHandler)
	router.Get("/auth/{provider}", BeginAuthHandler)
	router.Get("/", AuthChoiceHandler)
	// router.Add("GET", "/app", http.FileServer(http.Dir("app/")))
	// router.PathPrefix("/app").Handler(http.FileServer(http.Dir("app/")))
	http.Handle("/", router)
	http.Handle("/app/", http.StripPrefix("/app/",
		http.FileServer(http.Dir("app/"))))

	go http.ListenAndServeTLS(":8080", "cert.crt", "key.key", nil)
	http.ListenAndServe(":8000", http.HandlerFunc(redirectHandler))
}
开发者ID:joshheinrichs,项目名称:cmpt436-project,代码行数:50,代码来源:main.go

示例13: Test_GetProvider

func Test_GetProvider(t *testing.T) {
	a := assert.New(t)

	provider := &faux.Provider{}
	goth.UseProviders(provider)

	p, err := goth.GetProvider(provider.Name())
	a.NoError(err)
	a.Equal(p, provider)

	p, err = goth.GetProvider("unknown")
	a.Error(err)
	a.Equal(err.Error(), "no provider for unknown exists")
	goth.ClearProviders()
}
开发者ID:drathier,项目名称:goth,代码行数:15,代码来源:provider_test.go

示例14: PostPopulate

// PostPopulate sets up the oauth provider
func (s *authService) PostPopulate() error {
	goth.UseProviders(gplus.New(
		s.Config.GoogleKey,
		s.Config.GoogleSecret,
		s.Config.CallbackUrl,
	))

	var err error
	s.provider, err = goth.GetProvider("gplus")
	if err != nil {
		log.Error(fmt.Sprintf("Could not get gplus provider: %v", err))
		return err
	}

	return nil
}
开发者ID:gnidan,项目名称:foodtastechess,代码行数:17,代码来源:auth.go

示例15: Start

func Start(port, templatesDir string, publicDir string) error {
	dbmap = setupDb()
	defer dbmap.Db.Close()

	// Process our templates
	TemplatesDir = templatesDir
	var err error
	Templates, err = tmpl.ParseDir(TemplatesDir)
	if err != nil {
		logging.ErrorWithTags([]string{"templates"}, "Failed to parse templates", err.Error())
		return err
	}

	// Setup Goth Authentication
	goth.UseProviders(
		github.New(os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"), "http://localhost:3000/auth/github/callback", "repo", "user:email"),
	)

	// Setup Socket.io server and related activity fetching
	socketServer, err := SetupSocketIO()
	if err != nil {
		return err
	}

	err = StartSocketPusher(socketServer, activityChan)
	if err != nil {
		return err
	}

	err = StartExistingUsers(activityChan)
	if err != nil {
		return err
	}

	// Start up gin and its friends
	r := gin.Default()
	r.Use(cors.Middleware(cors.Options{AllowCredentials: true}))

	// Serve static assets
	r.Use(static.Serve("/", static.LocalFile(publicDir, false)))

	SetupRoutes(r, socketServer)
	r.Run(fmt.Sprintf(":%s", port))

	return nil
}
开发者ID:davidwinton,项目名称:feedbag,代码行数:46,代码来源:feedbag.go


注:本文中的github.com/markbates/goth.UseProviders函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。