removed callbackfunc, it was unnecessary

This commit is contained in:
Colin Henry 2019-09-30 11:46:13 -07:00
parent 291a3f80c3
commit ea921a3b65
3 changed files with 11 additions and 13 deletions

View File

@ -54,8 +54,6 @@ func NewCallbackHandler(c Config) http.HandlerFunc {
// Getting now the userInfo // Getting now the userInfo
user := User{} user := User{}
// var profile map[string]interface{}
if err := idToken.Claims(&user); err != nil { if err := idToken.Claims(&user); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
@ -80,12 +78,12 @@ func NewCallbackHandler(c Config) http.HandlerFunc {
// - by email address domain? // - by email address domain?
//set tenant ID on application ID in App Metadata on user //set tenant ID on application ID in App Metadata on user
if c.CallbackFunc != nil { // if c.CallbackFunc != nil {
c.CallbackFunc(c, user) // c.CallbackFunc(c, user)
} else { // } else {
// Redirect to logged in page // Redirect to logged in page
http.Redirect(w, r, "/user", http.StatusSeeOther) http.Redirect(w, r, c.RedirectURL, http.StatusSeeOther)
} // }
} }
} }

View File

@ -10,21 +10,21 @@ type Config struct {
ClientID string ClientID string
ClientSecret string ClientSecret string
CallbackURL string CallbackURL string
CallbackFunc CallbackFunc RedirectURL string
} }
func FromEnv(c CallbackFunc) Config { func FromEnv() Config {
return Config{ return Config{
Domain: os.Getenv("AUTH_DOMAIN"), Domain: os.Getenv("AUTH_DOMAIN"),
ClientID: os.Getenv("AUTH_CLIENT_ID"), ClientID: os.Getenv("AUTH_CLIENT_ID"),
ClientSecret: os.Getenv("AUTH_CLIENT_SECRET"), ClientSecret: os.Getenv("AUTH_CLIENT_SECRET"),
CallbackURL: os.Getenv("AUTH_CALLBACK_URL"), CallbackURL: os.Getenv("AUTH_CALLBACK_URL"),
CallbackFunc: c, RedirectURL: "/user",
} }
} }
func PrintConfig() { func PrintConfig() {
fmt.Printf("%#v\n", FromEnv(nil)) fmt.Printf("%#v\n", FromEnv())
} }
type CallbackFunc func(c Config, u User) error type CallbackFunc func(c Config, u User) error

View File

@ -18,7 +18,7 @@ func StartServer() {
auth.PrintConfig() auth.PrintConfig()
s := jch_http.NewServer(negroni.New()). s := jch_http.NewServer(negroni.New()).
Static("/public/*filepath", http.Dir("public/")). Static("/public/*filepath", http.Dir("public/")).
Service("", auth.Service(auth.FromEnv(nil))). Service("", auth.Service(auth.FromEnv())).
GET("/", "", http.HandlerFunc(HomeHandler)) GET("/", "", http.HandlerFunc(HomeHandler))
port := os.Getenv("PORT") port := os.Getenv("PORT")