From 6edba8d9fb0218bf61a7f255922f1e98b54f5f41 Mon Sep 17 00:00:00 2001 From: Pavel Sorokin Date: Thu, 16 Nov 2017 13:14:27 +0000 Subject: [PATCH] More debug and workaround for accessing GRAPH --- api/api.go | 1 + oauthproxy.go | 12 ++++++++++-- providers/azure.go | 17 +++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/api/api.go b/api/api.go index e8378ff9..425ef98e 100644 --- a/api/api.go +++ b/api/api.go @@ -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) diff --git a/oauthproxy.go b/oauthproxy.go index a101d81c..edb47613 100644 --- a/oauthproxy.go +++ b/oauthproxy.go @@ -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")) diff --git a/providers/azure.go b/providers/azure.go index baff0bc3..c836f3bb 100644 --- a/providers/azure.go +++ b/providers/azure.go @@ -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() {