Created
March 10, 2017 11:05
-
-
Save as27/49f251d010ae6b5f00fc4f58c13c61aa to your computer and use it in GitHub Desktop.
Buffalo auth tutorial auth.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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