-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmde_auth.go
52 lines (42 loc) · 1.72 KB
/
mde_auth.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"net/http"
)
// STS Auth Endpoint returns HTML content that gets render in a webview container
// The webview container expect a POST request to the appru URL with the wresult parameter set to the auth token
// The security token in wresult is later passed back in <wsse:BinarySecurityToken>
// This string is opaque to the enrollment client; the client does not interpret the string.
// The returned HTML content contains a JS script that will perform a POST request to the appru URL automatically
// This will set the wresult parameter to the value of auth token
func STSAuthHandler(w http.ResponseWriter, r *http.Request) {
// Print querystring
if r.Method == http.MethodGet {
fmt.Printf("====================Query String GET:\n%s\n====================", r.URL.RawQuery)
w.Header().Set("Content-Type", "text/html; charset=UTF-8")
w.Write([]byte(`
<h3>MDM Federated Login</h3>
<script>
function performPost() {
var form = document.createElement('form');
form.method = 'POST';
form.action = "` + r.URL.Query().Get("appru") + `"
// Add any form fields or data you want to send
var input1 = document.createElement('input');
input1.type = 'hidden';
input1.name = 'wresult';
input1.value = 'tokenmagic'; // this is the token paramenter passed through programmatic enrollment
form.appendChild(input1);
// Submit the form
document.body.appendChild(form);
form.submit();
}
// Call performPost() when the script is executed
performPost();
</script>
`))
return
} else if r.Method == http.MethodPost {
fmt.Printf("====================Query String POST:\n%s\n====================", r.URL.RawQuery)
}
}