Authenticate ASP VBScript Sample
This page contains ASP VBScript code sample for xWeb. You can refer to these code samples and incorporate these into your own application as needed.
This code shows how to work with:
- Authenticate web method, including getting and setting a token
- GetIndividualInformation
- WebLogin
Code
Global Variables
This section of code sets certain global constants. The other code samples below assume that the global variables are available.
<%
'===================================================================================================================================================='
' declare global constants
' these values from Avectra:
Public Const gC_AvectraServicesServer = "http://www.netforumsite.com"
Public Const gC_AvectraServicesPath = "/xweb/secure/netForumXML.asmx"
Public Const gC_AvectraServicesHost = "www.netforumsite.com"
Public Const gC_AvectraServicesLogin = "[your site login]"
Public Const gC_AvectraServicesPassword = "[your site password]"
Public Const gC_AvectraKeyOverride = "[your site key override]"
' declare global variables
Dim xmlhttp
Dim strSoap
Dim strResponse
Dim xmlDoc
Dim strToken
Dim strUserToken
Dim oNode
Dim strAvectraUserLogin
Dim strAvectraUserPassword
' initialize user credential variables
strAvectraUserLogin = Request("[post varaible with valid user login]")
strAvectraUserPassword = Request("[post varaible with valid user password]")
'===================================================================================================================================================='
[edit] Function for Getting Token
'===================================================================================================================================================='
' this function logs into the Avectra Services and retrieves the initial Authorization Token
' this initial call to the Authenticate service is required prior to using other services
Function GetAuthToken()
' declare variables
'Dim xmlhttp, strSoap, strResponse, xmlDoc, strToken, strUserToken, oNode
' initialize result
GetAuthToken = ""
' concatenate soap string
strSoap = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf
strSoap = strSoap & "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" "
strSoap = strSoap & " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" "
strSoap = strSoap & " xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" & vbCrLf
strSoap = strSoap & " <soap:Body>" & vbCrLf
strSoap = strSoap & " <Authenticate xmlns=""http://www.avectra.com/2005/"">" & vbCrLf
strSoap = strSoap & " <userName>" & gC_AvectraServicesLogin & "</userName>" & vbCrLf
strSoap = strSoap & " <password>" & gC_AvectraServicesPassword & "</password>" & vbCrLf
strSoap = strSoap & " </Authenticate>" & vbCrLf
strSoap = strSoap & " </soap:Body>" & vbCrLf
strSoap = strSoap & "</soap:Envelope>" & vbCrLf
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
' post the XML to Avectra's Authenticate service
xmlhttp.Open "POST", gC_AvectraServicesServer & gC_AvectraServicesPath, false
xmlhttp.setRequestHeader "Host", gC_AvectraServicesHost
xmlhttp.setRequestHeader "Content-type", "text/xml; charset=utf-8"
xmlhttp.setRequestHeader "Content-Length", len (strSoap)+1
xmlhttp.setRequestHeader "SOAPAction", "http://www.avectra.com/2005/Authenticate"
xmlhttp.send(strSoap)
' capture response
strResponse = xmlhttp.responseText
' load response into xml DOM object
set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.loadXML(strResponse)
' get token if one was returned
Set oNode = xmlDoc.selectSingleNode("//Token")
If Not oNode Is Nothing Then GetAuthToken = xmlDoc.selectSingleNode("//Token").text
End Function
'===================================================================================================================================================='
Calling this function:
'===================================================================================================================================================='
' set intial token variable
strToken = GetAuthToken()
' use below for debugging
' Response.Write("<hr>Auth Token: [" & strToken & "]") & vbCrLf
'===================================================================================================================================================='
Calling WebLogin method
'===================================================================================================================================================='
' this section uses the WebLogin service get an individual user token
' this uses the key override
' note strToken variable must first be set using the Authenticate service
' concatenate xml string
strSoap = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf
strSoap = strSoap & "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" & vbCrLf
strSoap = strSoap & " <soap:Header>" & vbCrLf
strSoap = strSoap & " <AuthorizationToken xmlns=""http://www.avectra.com/2005/"">" & vbCrLf
strSoap = strSoap & " <Token>" & strToken & "</Token>" & vbCrLf
strSoap = strSoap & " </AuthorizationToken>" & vbCrLf
strSoap = strSoap & " </soap:Header>" & vbCrLf
strSoap = strSoap & " <soap:Body>" & vbCrLf
strSoap = strSoap & " <WebLogin xmlns=""http://www.avectra.com/2005/"">" & vbCrLf
strSoap = strSoap & " <userLoginPlain>" & strAvectraUserLogin & "</userLoginPlain>" & vbCrLf
strSoap = strSoap & " <passwordPlain>" & strAvectraUserPassword & "</passwordPlain>" & vbCrLf
strSoap = strSoap & " <keyOverride>" & gC_AvectraKeyOverride & "</keyOverride>" & vbCrLf
strSoap = strSoap & " </WebLogin>" & vbCrLf
strSoap = strSoap & " </soap:Body>" & vbCrLf
strSoap = strSoap & "</soap:Envelope>" & vbCrLf
Set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
' post the XML to Avectra's WebLogin service
xmlhttp.Open "POST",gC_AvectraServicesServer & gC_AvectraServicesPath,false
xmlhttp.setRequestHeader "Host", gC_AvectraServicesHost
xmlhttp.setRequestHeader "Content-type", "text/xml; charset=utf-8"
xmlhttp.setRequestHeader "Content-Length", len (strSoap)+1
xmlhttp.setRequestHeader "SOAPAction", "http://www.avectra.com/2005/WebLogin"
xmlhttp.send(strSoap)
' capture response
strResponse = xmlhttp.responseText
' load response into xml DOM object
set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.loadXML(strResponse)
' grab new authorization token for use in subsequent service call
strToken = xmlDoc.selectSingleNode("//Token").text
' set user token variable for use in subsequent service call
strUserToken = xmlDoc.selectSingleNode("//WebLoginResult").text
' use below for debugging
' Response.Write("<hr>Auth Token: [" & strToken & "]<br />") & vbCrLf
' Response.Write("<hr>Web Login Result: [" & strResponse & "]") & vbCrLf
'===================================================================================================================================================='
Code for calling GetIndividualInformation method
'===================================================================================================================================================='
' this section uses the GetIndividualInformation service and captures the result
' note strToken variable must first be set using the Authenticate service
' note strUserToken variable must first be set using the WebLogin service
' concatenate xml string
strSoap = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf
strSoap = strSoap & "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" & vbCrLf
strSoap = strSoap & " <soap:Header>" & vbCrLf
strSoap = strSoap & " <AuthorizationToken xmlns=""http://www.avectra.com/2005/"">" & vbCrLf
strSoap = strSoap & " <Token>" & strToken & "</Token>" & vbCrLf
strSoap = strSoap & " </AuthorizationToken>" & vbCrLf
strSoap = strSoap & " </soap:Header>" & vbCrLf
strSoap = strSoap & " <soap:Body>" & vbCrLf
strSoap = strSoap & " <GetIndividualInformation xmlns=""http://www.avectra.com/2005/"">" & vbCrLf
strSoap = strSoap & " <IndividualKey>" & strUserToken & "</IndividualKey>" & vbCrLf
strSoap = strSoap & " </GetIndividualInformation>" & vbCrLf
strSoap = strSoap & " </soap:Body>" & vbCrLf
strSoap = strSoap & "</soap:Envelope>" & vbCrLf
' post the XML to Avectra's GetIndividualInformation service
xmlhttp.Open "POST",gC_AvectraServicesServer & gC_AvectraServicesPath, false
xmlhttp.setRequestHeader "Host", gC_AvectraServicesHost
xmlhttp.setRequestHeader "Content-type", "text/xml; charset=utf-8"
xmlhttp.setRequestHeader "Content-Length", len (strSoap)+1
xmlhttp.setRequestHeader "SOAPAction", "http://www.avectra.com/2005/GetIndividualInformation"
xmlhttp.send(strSoap)
' capture response
strResponse = xmlhttp.responseText
' load response into xml DOM object
xmlDoc.loadXML(strResponse)
' grab new authorization token for use in subsequent service call
strToken = xmlDoc.selectSingleNode("//Token").text
' crawl through other nodes here as necessary to grab individual information
' use below for debugging
' Response.Write("<hr>GetIndividualInformation Result: [" & strResponse & "]") & vbCrLf
' Response.Write("<hr>Auth Token: [" & strToken & "]<br />") & vbCrLf
'===================================================================================================================================================='
%>