Simplified authentication negotiation
This commit is contained in:
parent
a739a9b4bb
commit
7ca7675a85
|
@ -66,13 +66,11 @@ type EWSRoundTripper struct {
|
|||
}
|
||||
|
||||
func (er EWSRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
if er.authType == authTypeBasic {
|
||||
r.SetBasicAuth(er.username, er.password)
|
||||
}
|
||||
|
||||
er.initMutex.Lock()
|
||||
resp, err := er.delegate.RoundTrip(r)
|
||||
if err == nil && resp.StatusCode == http.StatusUnauthorized && er.authType == authTypeUnknown {
|
||||
if er.authType == authTypeUnknown {
|
||||
// Find authentication scheme.
|
||||
resp, err := http.DefaultClient.Get(r.URL.String())
|
||||
if err == nil && resp.StatusCode == http.StatusUnauthorized {
|
||||
// This is a good time to find out what the server prefers.
|
||||
authHeaders := resp.Header["Www-Authenticate"]
|
||||
if authHeaders != nil {
|
||||
|
@ -86,8 +84,6 @@ func (er EWSRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// So, do we know more than before? If so, try again.
|
||||
if er.authType > authTypeUnknown {
|
||||
if er.authType == authTypeNTLM {
|
||||
// We need to replace the delegator.
|
||||
er.delegate = &httpntlm.NtlmTransport{
|
||||
|
@ -96,13 +92,15 @@ func (er EWSRoundTripper) RoundTrip(r *http.Request) (*http.Response, error) {
|
|||
Password: er.password,
|
||||
}
|
||||
}
|
||||
er.initMutex.Unlock()
|
||||
return er.RoundTrip(r)
|
||||
}
|
||||
}
|
||||
er.initMutex.Unlock()
|
||||
|
||||
if er.authType == authTypeBasic {
|
||||
r.SetBasicAuth(er.username, er.password)
|
||||
}
|
||||
|
||||
er.initMutex.Unlock()
|
||||
return resp, err
|
||||
return er.delegate.RoundTrip(r)
|
||||
}
|
||||
|
||||
func NewEWSCalendar(url, username, password string) *EWSCalendar {
|
||||
|
|
Loading…
Reference in New Issue