-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock.go
49 lines (37 loc) · 946 Bytes
/
mock.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
package verifier
import (
"net/http"
"net/url"
)
type mockProvider struct{}
func (m *mockProvider) Verify(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
scheme := r.Header.Get("X-Forwarded-Proto")
if scheme == "" {
if r.TLS != nil {
scheme = "https"
} else {
scheme = "http"
}
}
// q := r.URL.Query()
q := url.Values{}
q.Set("code", r.URL.Query().Get("request_id"))
verificationURL := &url.URL{
Scheme: scheme,
Host: r.Host,
Path: "/auth/oauth2/callback",
RawQuery: q.Encode(),
}
http.Redirect(w, r, verificationURL.String(), 302)
}
func (m *mockProvider) Callback(w http.ResponseWriter, r *http.Request) (*AuthResult, error) {
w.Write([]byte("authentication successful"))
return &AuthResult{
Code: r.URL.Query().Get("code"),
Email: "mock@kartusche.com",
}, nil
}
func NewMockProvider() AuthenticationProvider {
return &mockProvider{}
}