Classic ASP VBScript OAuth

A generic OAuth library for Classic ASP, with a Twitter Sign-in example.

Source on GitHub · Download example project (.zip)


What this is

This page hosts an example of a generic Classic ASP VBScript OAuth library in action. The example uses Twitter’s OAuth flow (Sign in with Twitter) to illustrate usage. The full project, with source, is available for download.

What this is not

Although the Twitter REST API is used, this is a VBScript OAuth example, not a Twitter tutorial. The CSS and JavaScript that ship with the example are not production-ready — focus on the oauth/cLibOAuth.asp file.

Quick start

  1. Download the example project.
  2. Extract the files to a temp directory.
  3. Copy the oauth folder into the root of your project.
  4. Create a folder named OAuthTest at your project root, and a file default.asp inside it.
  5. Use the basic code example below as a starting point. Replace {TOKENS} with valid values.
  6. Browse to http://localhost/{YOUR_PROJECT_NAME}/OAuthTest/default.asp.

Basic code flow

  1. Instantiate an instance of the cLibOAuth object.
  2. Add proprietary request parameters.
  3. Call Send().
  4. Evaluate the response.

Basic code example

<!--#include file="../oauth/cLibOAuth.asp"-->
<%
' 1. Instantiate
Dim objOAuth : Set objOAuth = New cLibOAuth
    objOAuth.ConsumerKey   = {YOUR_CONSUMER_KEY}
    objOAuth.ConsumerSecret = {YOUR_CONSUMER_SECRET}
    objOAuth.EndPoint       = {SERVICE_PROVIDER_ENDPOINT_URL}
    objOAuth.Host           = {YOUR_HOST_HEADER_VALUE}
    objOAuth.RequestMethod  = OAUTH_REQUEST_METHOD_POST
    objOAuth.TimeoutURL     = {YOUR_TIMEOUT_URL}
    objOAuth.UserAgent      = {YOUR_USER_AGENT_HEADER_VALUE}

' 2. Add proprietary parameters
    objOAuth.Parameters.Add {PARAM_NAME_1}, {PARAM_VALUE_1}
    objOAuth.Parameters.Add {PARAM_NAME_2}, {PARAM_VALUE_2}

' 3. Make the call
    objOAuth.Send()

' 4. Evaluate the response
Dim strResponse : strResponse = objOAuth.Get_ResponseValue({RESPONSE_PARAM_NAME})
%>

Note: the example above is illustrative; for working code, refer to the example project files.

Public properties

ConsumerKey (Let, String, required)
Your consumer key from the service provider (e.g. Twitter).
ConsumerSecret (Let, String, required)
Your consumer secret from the service provider.
EndPoint (Let, String, required)
The URL of the OAuth request (e.g. http://twitter.com/statuses/update.json).
ErrorCode (Get, Integer)
ASP error code (Err.number) returned on error.
Host (Let, String)
The Host request-header value (required for Twitter).
LoggedIn (Get, Boolean)
Convenience property that returns logged-in state — requires you to save session variables (see twitter/callback.asp in the example).
Parameters (Set, Object)
Dictionary of proprietary request key=value pairs (unencoded).
RequestMethod (Let, String)
GET or POST. Default: POST.
ResponseText (Get, String)
The provider response string (e.g. JSON returned by Twitter).
TimeoutURL (Let, String)
Where to direct the user on timeout. Must be an absolute path.
UserAgent (Let, String)
The User-Agent request header value (required for Twitter).

Public methods

Get_ResponseValue(strParamName)
Extract a value from a key=value pair returned by the service provider. Returns a string.
Send()
Make the request after all properties have been set.

This is an old library kept online for link equity. The original demo is no longer active because it required a Microsoft IIS environment. Project source is on GitHub.