NOTE: This bug report is for Confluence Server. Using Confluence Cloud? See the corresponding bug report.

      Hi there,

      I was trying a bit of code that accesses confluence API which has authentication enforced on it. Sample is below

      static void Main()

      { string url = @"http://dubconfluence800:8090/rest/api/content/?os_authType=basic/?spaceKey=DOL&title=Dolphin+Test+Cases"; Uri myUri = new Uri(url); WebRequest myWebRequest = HttpWebRequest.Create(myUri); HttpWebRequest myHttpWebRequest = (HttpWebRequest)myWebRequest; string uN = Base64Encode("Brannick"); string pW = Base64Encode("Brannick"); NetworkCredential myNetworkCredential = new NetworkCredential(uN, pW); CredentialCache myCredentialCache = new CredentialCache(); myCredentialCache.Add(myUri, "Basic", myNetworkCredential); myHttpWebRequest.PreAuthenticate = true; myHttpWebRequest.Credentials = myCredentialCache; WebResponse myWebResponse = myWebRequest.GetResponse(); Stream responseStream = myWebResponse.GetResponseStream(); StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default); string pageContent = myStreamReader.ReadToEnd(); responseStream.Close(); myWebResponse.Close(); Console.WriteLine(pageContent); }

      public static string Base64Encode(string plainText)

      { var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); return Convert.ToBase64String(plainTextBytes); }

      I'm writing this in C# as it is a requirement for the task i'm doing. As you can see from the code the url in question is the folllowing

      http://dubconfluence800:8090/rest/api/content/?spaceKey=DOL&title=Dolphin+Test+Cases

      when I try that manually in the browser or via code I get the following

      {"statusCode":404,"message":"No space with key : DOL"}

      which is as expected as per manual steps as the page has authentication enabled. However. I would have thought via code I would be ok based on content in the folllowing link

      https://developer.atlassian.com/confdev/confluence-rest-api/confluence-rest-apis-prototype-only/using-the-rest-apis-prototype-only

      Would you have any guidance on the above as to what I may be doing wrong? thanks in advance.

      Btw I got redirected to yourselves by a person from a different team...you can see the details in the folllowing link

      https://ecosystem.atlassian.net/browse/REL-325

            [CONFSERVER-39391] Access to confluence apis that has authenication enforced

            bhrein.brannick1734596588 added a comment -

            I think I found the problem....this ticket can be closed...it was to do with the way I was passing in credentials

            The problem code was this part...first 3 lines work...last 3 lines fails if you do it that way...
            //New Way
            request.Method = WebRequestMethods.Http.Get;
            string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(@"admin:12345"));
            request.Headers[HttpRequestHeader.Authorization] = string.Format("Basic

            {0}

            ", credentials);
            //Old Way
            //NetworkCredential networkCredential = new NetworkCredential(@"admin", @"12345"); // logon in format "domain\username"
            //CredentialCache myCredentialCache = new CredentialCache {{ new Uri(url), "Basic", networkCredential }};
            //request.Credentials = myCredentialCache;

            First answer in this post details the reason.....
            http://stackoverflow.com/questions/16044313/webclient-httpwebrequest-with-basic-authentication-returns-404-not-found-for-v
            apologies this isn't a confluence issue at all...

            bhrein.brannick1734596588 added a comment - I think I found the problem....this ticket can be closed...it was to do with the way I was passing in credentials The problem code was this part...first 3 lines work...last 3 lines fails if you do it that way... //New Way request.Method = WebRequestMethods.Http.Get; string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(@"admin:12345")); request.Headers [HttpRequestHeader.Authorization] = string.Format("Basic {0} ", credentials); //Old Way //NetworkCredential networkCredential = new NetworkCredential(@"admin", @"12345"); // logon in format "domain\username" //CredentialCache myCredentialCache = new CredentialCache {{ new Uri(url), "Basic", networkCredential }}; //request.Credentials = myCredentialCache; First answer in this post details the reason..... http://stackoverflow.com/questions/16044313/webclient-httpwebrequest-with-basic-authentication-returns-404-not-found-for-v apologies this isn't a confluence issue at all...

            Bhrein,

            Sorry for the delay it looks like there was a reply to this ticket back in September but it was restricted to Atlassian only for some reason. Here is what they are requesting.

            Dear Bhrein Brannick,
            Thanks for submitting the ticket
            Would you please let me know what affect version of Confluence that you met this issue?
            Could you help attach the Confluence log into ticket?
            Thanks,
            Minh Tran
            Confluence BugMaster
            Atlassian

            Ralph

            Ralph Whitbeck (Inactive) added a comment - Bhrein, Sorry for the delay it looks like there was a reply to this ticket back in September but it was restricted to Atlassian only for some reason. Here is what they are requesting. Dear Bhrein Brannick, Thanks for submitting the ticket Would you please let me know what affect version of Confluence that you met this issue? Could you help attach the Confluence log into ticket? Thanks, Minh Tran Confluence BugMaster Atlassian Ralph

            bhrein.brannick1734596588 added a comment -

            Hi,

            Can somebody help with the following query please? I still haven't received a response to this which is disappointing and I work for a company that currently holds approximately 500 licenses for Confluence & Jira

            ~Bhréin

            bhrein.brannick1734596588 added a comment - Hi, Can somebody help with the following query please? I still haven't received a response to this which is disappointing and I work for a company that currently holds approximately 500 licenses for Confluence & Jira ~Bhréin

            bhrein.brannick1734596588 added a comment -

            Hi there,

            is there anybody that can provide guidance on the above? I would greatly appreciate if somebody can help with the above. Many thanks in advance.

            ~Bhréin

            bhrein.brannick1734596588 added a comment - Hi there, is there anybody that can provide guidance on the above? I would greatly appreciate if somebody can help with the above. Many thanks in advance. ~Bhréin

            bhrein.brannick1734596588 added a comment -

            Hi there,

            Is there anyone that provide any guidance on the above query? Many thanks in advance.

            ~Bhréin

            bhrein.brannick1734596588 added a comment - Hi there, Is there anyone that provide any guidance on the above query? Many thanks in advance. ~Bhréin

              Unassigned Unassigned
              bhrein.brannick1734596588 bhrein.brannick1734596588
              Affected customers:
              0 This affects my team
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: