More debug and workaround for accessing GRAPH

This commit is contained in:
Pavel Sorokin 2017-11-16 13:14:27 +00:00
parent 51ac937bcc
commit 6edba8d9fb
3 changed files with 26 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import (
)
func Request(req *http.Request) (*simplejson.Json, error) {
log.Printf("New request to: '%s'", req.URL)
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Printf("%s %s %s", req.Method, req.URL, err)

View File

@ -521,9 +521,14 @@ func (p *OAuthProxy) OAuthStart(rw http.ResponseWriter, req *http.Request) {
}
func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
log.Printf("[OAuthCallback] Starting OAuthCallback")
remoteAddr := getRemoteAddr(req)
log.Printf("[OAuthCallback] remoteAddr = %s", remoteAddr)
// finish the oauth cycle
log.Printf("[OAuthCallback] req.ParseForm")
err := req.ParseForm()
if err != nil {
p.ErrorPage(rw, 500, "Internal Error", err.Error())
@ -532,8 +537,11 @@ func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
errorString := req.Form.Get("error")
if errorString != "" {
p.ErrorPage(rw, 403, "Permission Denied", errorString)
return
log.Printf("[OAuthCallback] error in parsed form (REQ) : %s", req)
log.Printf("[OAuthCallback] error in parsed form (REQ.Form) : %s", req.Form)
log.Printf("[OAuthCallback] error in parsed form (REQ.error string) : %s", errorString)
p.ErrorPage(rw, 403, "Permission Denied", errorString)
return
}
session, err := p.redeemCode(req.Host, req.Form.Get("code"))

View File

@ -155,21 +155,34 @@ func (p *AzureProvider) GetGroups(s *SessionState, f string) (string, error) {
// substring - not supported | "https://graph.microsoft.com/v1.0/me/memberOf?$filter=substring(displayName,0,2)%20eq%20%27groupname%27"
requestUrl := "https://graph.microsoft.com/v1.0/me/memberOf?$select=displayName"
workaround_set := false
groups := make([]string, 0)
for {
req, err := http.NewRequest("GET", requestUrl, nil)
// err = errors.New("fake error")
if err != nil {
return "", err
return "", err
}
req.Header = getAzureHeader(s.AccessToken)
req.Header.Add("Content-Type", "application/json")
groupData, err := api.Request(req)
if err != nil {
return "", err
// If workaround already tried, just fail the execution
if workaround_set {
log.Printf("[GetGroups] We tried hard, but still receive error: '%s'", err)
return "", err
}
// It might be that it is a Graph bug, try to workaround it by accessing another URL
log.Printf("[GetGroups] Failed to get groups details: %s", err)
requestUrl = "https://graph.microsoft.com/v1.0/users/" + s.Email + "/memberOf"
log.Printf("[GetGroups] Try to workaround by accessing: '%s'", requestUrl)
workaround_set = true
continue
}
for _, groupInfo := range groupData.Get("value").MustArray() {