Skip to content

Commit

Permalink
removed duplicate "func signon" that was cuasing the app to crash on …
Browse files Browse the repository at this point in the history
…start (#33)

Co-authored-by: ron <[email protected]>
  • Loading branch information
rarevalo13 and ron authored Dec 20, 2023
1 parent f123552 commit 356fd9c
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions go-sso-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ var conf struct {
Connection string
Provider string
}

func loadEnvVariables() {
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
log.Fatal("Error loading .env file")
}

// Assign the environment variables to the `conf` struct fields
flag.StringVar(&conf.Addr, "addr", ":8000", "The server addr.")
flag.StringVar(&conf.APIKey, "api-key", os.Getenv("WORKOS_API_KEY"), "The WorkOS API key.")
Expand All @@ -53,27 +54,13 @@ func loadEnvVariables() {
log.Printf("launching sso demo with configuration: %+v", conf)

sso.Configure(conf.APIKey, conf.ClientID)
}
func init() {
}

func init() {
loadEnvVariables()
}
}

func signin(w http.ResponseWriter, r *http.Request) {
func signin(w http.ResponseWriter, r *http.Request) {
session, err := store.Get(r, sessionName)
if err != nil {
log.Println(err)
return
}

if auth, ok := session.Values["authenticated"].(bool); !ok || !auth {
http.Redirect(w, r, "/signin", http.StatusSeeOther)
return
}

http.Redirect(w, r, "/logged_in", http.StatusSeeOther)
}
session, err := store.Get(r, "cookie-name")
if err != nil {
log.Println(err)
Expand Down Expand Up @@ -104,7 +91,7 @@ func getAuthorizationURL(loginType string) (*url.URL, error) {
}

if loginType == "saml" {
opts.Connection = conf.Connection
opts.Connection = conf.Connection
} else {
opts.Provider = sso.ConnectionType(loginType)
}
Expand Down Expand Up @@ -154,8 +141,8 @@ func callback(w http.ResponseWriter, r *http.Request) {

thisProfile := Profile{
session.Values["first_name"].(string),
session.Values["last_name"].(string),
string(session.Values["raw_profile"].([]byte)),
session.Values["last_name"].(string),
string(session.Values["raw_profile"].([]byte)),
}

if err := tmpl.Execute(w, thisProfile); err != nil {
Expand Down Expand Up @@ -184,7 +171,6 @@ func main() {
log.Fatal("Error loading .env file")
}


router.HandleFunc("/login", login)
router.HandleFunc("/callback", callback)
router.HandleFunc("/logged_in", loggedin)
Expand Down

0 comments on commit 356fd9c

Please sign in to comment.