-
Notifications
You must be signed in to change notification settings - Fork 0
/
activeDirectorySSO.go
35 lines (26 loc) · 1.04 KB
/
activeDirectorySSO.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package auth
import (
"fmt"
"net/http"
"github.com/vjeantet/ldapserver"
)
/*
You can use this module by importing it in your application and calling the ActiveDirectoryAuth function with an http.ResponseWriter and http.Request as arguments. This function will extract the username and password from the form values and authenticate against the active directory server using the ldapserver package. Once the user is logged in, the callback function will be executed
*/
// ActiveDirectoryAuth performs authentication using SSO with Active Directory
func ActiveDirectoryAuth(w http.ResponseWriter, r *http.Request) {
ldapServer := ldapserver.NewServer()
defer ldapServer.Stop()
authenticated, username, err := ldapServer.Authenticate(r.FormValue("username"), r.FormValue("password"))
if err != nil {
fmt.Fprintln(w, err)
return
}
if !authenticated {
http.Redirect(w, r, "/login", http.StatusFound)
return
}
// Perform any additional actions here, such as storing the
// user's information in a database
fmt.Fprintln(w, "Welcome,", username)
}