-
Bug
-
Resolution: Not a bug
-
Low
-
None
-
None
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
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
- relates to
-
CONFCLOUD-39391 Access to confluence apis that has authenication enforced
-
- Closed
-
[CONFSERVER-39391] Access to confluence apis that has authenication enforced
Workflow | Original: JAC Bug Workflow v3 [ 2898772 ] | New: CONFSERVER Bug Workflow v4 [ 2993007 ] |
Workflow | Original: JAC Bug Workflow v2 [ 2791311 ] | New: JAC Bug Workflow v3 [ 2898772 ] |
Status | Original: Resolved [ 5 ] | New: Closed [ 6 ] |
Workflow | Original: JAC Bug Workflow [ 2721320 ] | New: JAC Bug Workflow v2 [ 2791311 ] |
Workflow | Original: Confluence Workflow - Public Facing - Restricted v5 - TEMP [ 2391205 ] | New: JAC Bug Workflow [ 2721320 ] |
Workflow | Original: Confluence Workflow - Public Facing - Restricted v5 [ 2271040 ] | New: Confluence Workflow - Public Facing - Restricted v5 - TEMP [ 2391205 ] |
Workflow | Original: Confluence Workflow - Public Facing - Restricted v5.1 - TEMP [ 2221310 ] | New: Confluence Workflow - Public Facing - Restricted v5 [ 2271040 ] |
Workflow | Original: Confluence Workflow - Public Facing - Restricted v5 - TEMP [ 2164520 ] | New: Confluence Workflow - Public Facing - Restricted v5.1 - TEMP [ 2221310 ] |
Workflow | Original: Confluence Workflow - Public Facing - Restricted v5 [ 1946712 ] | New: Confluence Workflow - Public Facing - Restricted v5 - TEMP [ 2164520 ] |
Workflow | Original: Confluence Workflow - Public Facing - Restricted v3 [ 1736499 ] | New: Confluence Workflow - Public Facing - Restricted v5 [ 1946712 ] |
Description |
Original:
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 |
New:
{panel:bgColor=#e7f4fa} *NOTE:* This bug report is for *Confluence Server*. Using *Confluence Cloud*? [See the corresponding bug report|http://jira.atlassian.com/browse/CONFCLOUD-39391]. {panel} 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 |