troubleshooting Question

HTTP Basic Access Authentication

Avatar of slegy
slegy asked on
JavaVisual Basic ClassicXML
16 Comments1 Solution5498 ViewsLast Modified:
Based on prior questions and answers, I thought I'd finally gotten a handle on this, but I'm unable to get the code working. We are setting up with OneAll for social medial login. Based on setup parameters, their site returns a token detailing the result of the login, after which I need to do a site authentication. They have no examples in vbscript but do have one in Java. I can't seem to successfully make the conversion. Can anyone see what is wrong with the vbscript.

	If request("connection_token") <> "" Then

		'Get connection_token
		connection_token = request("connection_token")
		'Site Settings
        site_subdomain = "lightningclass"
        site_public_key = "MyPublicKey"
        site_private_key = "MyPrivateKey"
		'API Access Domain
		site_domain = site_subdomain + ""
		'Connection Resource
		resource_uri = "https://" + site_domain + "/connections/"+connection_token+".xml"
		site_authentication = site_public_key + ":" + site_private_key

		Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
	    xmlhttp.setTimeouts 30,500,1000,1000
		xmlhttp.Open "GET", resource_uri
	    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

		xmlhttp.Send site_authentication
		theResponse = xmlhttp.responseText

		Set xmlhttp = nothing
End If

Java example:
// Your Site Settings
String site_subdomain = 'REPLACE WITH YOUR SITE SUBDOMAIN';
String site_public_key = 'REPLACE WITH YOUR SITE PUBLIC KEY';
String site_private_key = 'REPLACE WITH YOUR SITE PRIVATE KEY';
// API Access Domain
String site_domain = site_subdomain + '';
// Connection Resource
resource_uri = 'https://' + site_domain + '/connections.json';
  // Result Container
String result_json = "";
  // Forge authentication string username:password
  String site_authentication = site_public_key + ":" + site_private_key;
  String encoded_site_authentication = new String(new Base64().encode(site_authentication.getBytes())).replaceAll("[\n\r]", "");
  // Setup connection
  URL url = new URL (resource_uri);
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  // Connect using basic auth
  connection.setRequestProperty("Authorization", "Basic " +  encoded_site_authentication);
  StringBuilder sb = new StringBuilder();
  String line = null;
  // Read result
  BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  while ((line = rd.readLine()) != null) {
  result = sb.toString();
catch (Exception e)
// Done
System.out.println (result);
Join our community to see this answer!
Unlock 1 Answer and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros