What this is:
This page hosts an example of a Generic Classic ASP VBScript OAuth Library in action. The example uses Twitter's
OAuth Authentication Flow (Sign-in with Twitter)
to illustrate usage. The project in its entirety, with full source code, is available for download here:
PATH: http://scottdesapio.com/VBScriptOAuth/oAuthASPExample.zip
MD5: 335092c3c1d6c2cbd7e141772e0a474f
RELEASE DATE: 10.12.10
LAST UPDATE: 12.04.12
GITHUB (OAuth Library Only): http://github.com/sdesapio/Classic-ASP-VBScript-OAuth
What this is NOT:
Although the Twitter REST API is used, this example project is not so much a "Twitter" example as it is a "VBScript OAuth"
example.
This DEMO is also NOT a CSS or JavaScript tutorial. Pay no attention to the CSS and JavaScript. The CSS and Javascript
used in the example project would require their own tutorials and exist only to help illustrate the implementation.
IGNORE all CSS and JavaScript. NEITHER SHOULD BE CONSIDERED PRODUCTION READY (or remotely production usable for that matter).
What you REALLY want to focus on is the "oauth" folder inside of the example project - specifically the cLibOAuth.asp file.
Quick Start Instructions:
These Quick Start instructions assume you're not interested in the example project and already have a solid grasp on
including external libraries. If you're not yet comfortable with including external libraries, skip this Quick Start
and follow the example project setup instructions below.
NOTE: Use these instructions only after you've acquired a Consumer Key and Secret provided by your OAuth service provider.
Example Project Directory
Although the following example directory structure is used in this example project, the example project itself utilizes
quite a few more files. When utilising the VBScript OAuth Lib, your project should AT MINIMUM follow this structure:
+-root/
+-oauth/
| +-_inc/
| +-_base.asp
| +-constants_oauth.asp
| +-hex_sha1_base64.asp
| +-cLibOAuth.asp
| +-cLibOAuth.QS.asp
| +-cLibOAuth.RequestURL.asp
| +-cLibOAuth.Utils.asp
+-default.asp
Basic Code Flow
The following four steps outline the basic code flow of instantiaing and utilizing the VBScript OAuth Lib:
<!--#include file="../oauth/cLibOAuth.asp"-->) in your project,
your code should end up resembling the following. Values surrounded by brackets ({...}) would of course be replaced by
proprietary values.
NOTE: The above example should not be taken literally. It is meant only to illustrate basic structure. For actual working examples, check out the project files referenced below.
Example Project Setup Instructions
As noted earlier, although the example project can be regarded as a straight up example of Twitter VBScript OAuth, it is meant only to
illustrate core library usage. None of the files existing outside of the "oauth" folder should be considered production ready. Also, please note
that this example project was designed as a client example and expects a browser. Server side implementations may require some modifiction
to deal with Session state as reported by several users (see comments below).
Example Project NOTES:
EXAMPLE PROJECT CODE: This is the actual code, used on this page, illustrating the Sign-in with Twitter workflow accompanied by a status update.
ConsumerKey (Let)
REQUIRED: Yes
TYPE: String
DESCRIPTION: Your "consumer key" as received from the Service Provider. For instance, after successfully
registering your app with twitter, you'll be forward to a page displaying your "consumer key."
USAGE: objOAuth.ConsumerKey = "123456789asdfghjkl"
ConsumerSecret (Let)
REQUIRED: Yes
TYPE: String
DESCRIPTION: Your "consumer secret" as received from the Service Provider.
USAGE: objOAuth.ConsumerSecret = "123456789asdfghjklzxcvbnm"
EndPoint (Let)
REQUIRED: Yes
TYPE: String
DESCRIPTION: The URL of the oauth request. (e.g. http://twitter.com/statuses/update.json)
USAGE: objOAuth.EndPoint = "http://twitter.com/statuses/update.json"
ErrorCode (Get)
REQUIRED: N/A
TYPE: Integer
DESCRIPTION: ASP Error code (Err.number) returned on error.
USAGE: Dim strErr : strErr = objOAuth.ErrorCode
Host (Let)
REQUIRED: Varies (required for twitter implementation)
TYPE: String
DESCRIPTION: The "Host" request header value (required for twitter implementation)
USAGE: objOAuth.Host = "api.twitter.com"
LoggedIn (Get)
REQUIRED: N/A
TYPE: Boolean
DESCRIPTION: Convenience property that returns "logged in" state - requires you to save session variables
as illustrated in "twitter/callback.asp" in the example project.
USAGE: Dim blnLoggedIn : blnLoggedIn = objOAuth.LoggedIn
Parameters (Set)
REQUIRED: No
TYPE: Object
DESCRIPTION: Dictionary object containing proprietary request query string pairs. For instance, twitter's
"statuses/update" method requires a "status" parameter and potentially an "in_reply_to" parameter. You'll add these
pairs as parameters (UNENCODED).
USAGE: objOAuth.Parameters.Add key, value
RequestMethod (Let)
REQUIRED: No (Default is POST)
TYPE: String
DESCRIPTION: Request type (e.g. "GET", "POST")
USAGE: objOAuth.RequestMethod = "POST"
ResponseText (Get)
REQUIRED: N/A
TYPE: String
DESCRIPTION: The proprietary service provider response string. (e.g. twitter will return json string on
"statuses/update.json" call - the json is the ResponseText)
USAGE: Dim strResponseText : strResponseText = objOAuth.ResponseText
TimeoutURL (Let)
REQUIRED: No
TYPE: String
DESCRIPTION: Where to direct the user in the case of a timeout. MUST be an ABSOLUTE path (e.g. "http://mySite/Timeout.html")
USAGE: objOAuth.TimeoutURL = "http://www.myOAuthSite.com/Timeout.html"
UserAgent (Let)
REQUIRED: Varies (required for twitter implementation)
TYPE: String
DESCRIPTION: The "User-Agent" request header value (required for twitter implementation)
USAGE: objOAuth.UserAgent = "Your Twitter App Name"
Get_ResponseValue(strParamName)
PARAMETERS: strParamName (string)
DESCRIPTION: Convenience method used to extract a value from a key=value pair returned by service provider.
RETURNS: strParamValue (string)
USAGE: objOAuth.Get_ResponseValue(strParamName)
Send()
PARAMETERS: None
DESCRIPTION: Makes the call after all properties have been set.
RETURNS: Void
USAGE: objOAuth.Send()
blog comments powered by Disqus