Classic ASP VBScript OAuth
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.
- Library on GitHub: sdesapio/Classic-ASP-VBScript-OAuth
- Example project: OAuthASPExample.zip
- Last update: 2014-01-15
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
- Download the example project.
- Extract the files to a temp directory.
- Copy the
oauthfolder into the root of your project. - Create a folder named
OAuthTestat your project root, and a filedefault.aspinside it. - Use the basic code example below as a starting point. Replace
{TOKENS}with valid values. - Browse to
http://localhost/{YOUR_PROJECT_NAME}/OAuthTest/default.asp.
Basic code flow
- Instantiate an instance of the
cLibOAuthobject. - Add proprietary request parameters.
- Call
Send(). - 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
Hostrequest-header value (required for Twitter). LoggedIn(Get, Boolean)- Convenience property that returns logged-in state — requires you to save session variables (see
twitter/callback.aspin the example). Parameters(Set, Object)- Dictionary of proprietary request key=value pairs (unencoded).
RequestMethod(Let, String)GETorPOST. 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-Agentrequest 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.