Skip to content

Commit 356fd9c

Browse files
rarevalo13ron
andauthored
removed duplicate "func signon" that was cuasing the app to crash on start (#33)
Co-authored-by: ron <[email protected]>
1 parent f123552 commit 356fd9c

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

go-sso-example/main.go

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ var conf struct {
3535
Connection string
3636
Provider string
3737
}
38+
3839
func loadEnvVariables() {
3940
err := godotenv.Load()
4041
if err != nil {
41-
log.Fatal("Error loading .env file")
42+
log.Fatal("Error loading .env file")
4243
}
43-
44+
4445
// Assign the environment variables to the `conf` struct fields
4546
flag.StringVar(&conf.Addr, "addr", ":8000", "The server addr.")
4647
flag.StringVar(&conf.APIKey, "api-key", os.Getenv("WORKOS_API_KEY"), "The WorkOS API key.")
@@ -53,27 +54,13 @@ func loadEnvVariables() {
5354
log.Printf("launching sso demo with configuration: %+v", conf)
5455

5556
sso.Configure(conf.APIKey, conf.ClientID)
56-
}
57-
58-
func init() {
57+
}
58+
59+
func init() {
5960
loadEnvVariables()
60-
}
61+
}
6162

6263
func signin(w http.ResponseWriter, r *http.Request) {
63-
func signin(w http.ResponseWriter, r *http.Request) {
64-
session, err := store.Get(r, sessionName)
65-
if err != nil {
66-
log.Println(err)
67-
return
68-
}
69-
70-
if auth, ok := session.Values["authenticated"].(bool); !ok || !auth {
71-
http.Redirect(w, r, "/signin", http.StatusSeeOther)
72-
return
73-
}
74-
75-
http.Redirect(w, r, "/logged_in", http.StatusSeeOther)
76-
}
7764
session, err := store.Get(r, "cookie-name")
7865
if err != nil {
7966
log.Println(err)
@@ -104,7 +91,7 @@ func getAuthorizationURL(loginType string) (*url.URL, error) {
10491
}
10592

10693
if loginType == "saml" {
107-
opts.Connection = conf.Connection
94+
opts.Connection = conf.Connection
10895
} else {
10996
opts.Provider = sso.ConnectionType(loginType)
11097
}
@@ -154,8 +141,8 @@ func callback(w http.ResponseWriter, r *http.Request) {
154141

155142
thisProfile := Profile{
156143
session.Values["first_name"].(string),
157-
session.Values["last_name"].(string),
158-
string(session.Values["raw_profile"].([]byte)),
144+
session.Values["last_name"].(string),
145+
string(session.Values["raw_profile"].([]byte)),
159146
}
160147

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

187-
188174
router.HandleFunc("/login", login)
189175
router.HandleFunc("/callback", callback)
190176
router.HandleFunc("/logged_in", loggedin)

0 commit comments

Comments
 (0)