Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed duplicate "func signin" that was causing the app to crash on on start #33

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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