Search code examples
vbscriptoauth-2.0asp-classicaccess-token

How to get access token for GoToWebinar using Classic ASP and Strict OAuth 2.0


We are currently using GoToWebinars API to create webinars and registrants via the legacy OAuth method.

We are late in the game to change over to Strict OAuth 2.0 and need some guidance on how to quickly change over to the new method.

We have a web application written in classic ASP which requests the access token and then creates webinars and registrants.

Can you provide some code examples on how we can move to Strict OAuth 2.0?

Here is an example of our current ASP code to create tokens using the legacy method:

 Function getAccessToken()
   postURL = "https://api.getgo.com/oauth/access_token?grant_type=password&user_id={userId}&password={password}&client_id=" & client_id

   Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
   ServerXmlHttp.open "POST", postURL
   ServerXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
   ServerXmlHttp.setRequestHeader "Content-Length", Len(PostData)
   ServerXmlHttp.send PostData

   jsonResponse = ServerXmlHttp.responseText

   'Get Access Token
   set myJson = JSON.parse(jsonResponse)
   access_token = myJson.access_token

   getAccessToken = access_token

   Set ServerXmlHttp = Nothing
End Function

I have limited knowledge around strict OAuth 2.0 and can't get my head around creating access tokens programmatically.


Solution

  • Using the following ASP classic code it worked with OAuth 2.0.

    <script language="javascript" runat="server" src="/global/json2.min.asp"></script>
    
    Function getCitrixAccessToken()
    
    postURL = "https://api.getgo.com/oauth/v2/token"
    postData = "grant_type=password&username={username}&password={password}"
    
    Set ServerXmlHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
    ServerXmlHttp.open "POST", postURL
    ServerXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    ServerXmlHttp.setRequestHeader "Authorization", "Basic " & encodedAuthHeader
    ServerXmlHttp.setRequestHeader "Content-Length", Len(PostData)
    ServerXmlHttp.send PostData
    
    jsonResponse = ServerXmlHttp.responseText
    
    'Get Access Token
    set myJson = JSON.parse(jsonResponse)
    access_token = myJson.access_token
    
    getCitrixAccessToken = access_token
    
    Set ServerXmlHttp = Nothing
    
    End Function
    

    Hope this will help someone else with the same issue.