github.com/jasonish/buffalo@v0.8.2-0.20170413145823-bacbdd415f1b/generators/goth/templates/actions/auth.go.tmpl (about)

     1  package actions
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/gobuffalo/buffalo"
     8  	"github.com/markbates/goth"
     9  	"github.com/markbates/goth/gothic"
    10  	{{range .providers -}}
    11  	"github.com/markbates/goth/providers/{{ downcase . }}"
    12    {{end -}}
    13  )
    14  
    15  func init() {
    16  	gothic.Store = App().SessionStore
    17  
    18  	goth.UseProviders(
    19      {{range .providers -}}
    20  		{{downcase .}}.New(os.Getenv("{{upcase .}}_KEY"), os.Getenv("{{upcase .}}_SECRET"), fmt.Sprintf("%s%s", App().Host, "/auth/{{downcase .}}/callback")),
    21      {{end -}}
    22  	)
    23  }
    24  
    25  func AuthCallback(c buffalo.Context) error {
    26  	user, err := gothic.CompleteUserAuth(c.Response(), c.Request())
    27  	if err != nil {
    28  		return c.Error(401, err)
    29  	}
    30  	// Do something with the user, maybe register them/sign them in
    31  	return c.Render(200, r.JSON(user))
    32  }