Skip to content

Instantly share code, notes, and snippets.

@as27
Created March 10, 2017 11:05
Show Gist options
  • Save as27/49f251d010ae6b5f00fc4f58c13c61aa to your computer and use it in GitHub Desktop.
Save as27/49f251d010ae6b5f00fc4f58c13c61aa to your computer and use it in GitHub Desktop.
Buffalo auth tutorial auth.go
package actions
import (
"fmt"
"os"
"github.com/gobuffalo/buffalo"
"github.com/markbates/goth"
"github.com/markbates/goth/gothic"
"github.com/markbates/goth/providers/github"
)
func init() {
gothic.Store = App().SessionStore
goth.UseProviders(
github.New(os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"), fmt.Sprintf("%s%s", App().Host, "/auth/github/callback")),
)
}
func AuthCallback(c buffalo.Context) error {
user, err := gothic.CompleteUserAuth(c.Response(), c.Request())
if err != nil {
return c.Error(401, err)
}
// Do something with the user, maybe register them/sign them in
return c.Render(200, r.JSON(user))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment