-
Notifications
You must be signed in to change notification settings - Fork 26
/
cLibOAuth.asp
273 lines (220 loc) · 8.07 KB
/
cLibOAuth.asp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!--#include file="_inc/_base.asp"-->
<!--#include file="cLibOAuth.QS.asp"-->
<!--#include file="cLibOAuth.RequestURL.asp"-->
<!--#include file="cLibOAuth.Utils.asp"-->
<%
'******************************************************************************
' CLASS: cLibOAuth
' PURPOSE:
'
' AUTHOR: sdesapio DATE: 04.04.10 LAST MODIFIED: 04.04.10
'******************************************************************************
Class cLibOAuth
'**************************************************************************
'***'PRIVATE CLASS MEMBERS
'**************************************************************************
' boolean indicating the users current logged in state. This state
' variable is EXCLUSIVE to the session state of the local application
' and NOT the oAuth provider's logged in state.
Private m_blnLoggedIn
' additional parameters exclusive to the current call
Private m_objParameters
' reference to the utilities class (Encoding, response extraction,
' dictionary sorting, etc.)
Private m_objUtils
' reference to the consumer key acquired after registering with the
' oAuth service provider
Private m_strConsumerKey
' reference to the consumer secret acquired after registering with the
' oAuth service provider
Private m_strConsumerSecret
' the request URL
Private m_strEndPoint
' used to globally identify process errors
Private m_strErrorCode
' used to set host header
Private m_strHost
' the request type - e.g. POST, GET
Private m_strRequestMethod
' the response string returned by the service provider
Private m_strResponseText
' where to forward the user if call to oAuth provider times out.
' Absolute URL is recommended
Private m_strTimeoutURL
' used to set user-agent header
Private m_strUserAgent
'**************************************************************************
'***'CLASS_INITIALIZE / CLASS_TERMINATE
'**************************************************************************
Private Sub Class_Initialize()
' set default value to Null so we can check for null before get/set
m_blnLoggedIn = Null
' set default value to Nothing so we can check "If ... Is Nothing"
Set m_objParameters = Nothing
' instantiate the Utils class
Set m_objUtils = New cLibOAuthUtils
' set default to Null to ensure we're returning a verifiable value
m_strErrorCode = Null
' set default to POST
m_strRequestMethod = OAUTH_REQUEST_METHOD_POST
End Sub
Private Sub Class_Terminate()
' kill obj refs
Set m_objUtils = Nothing
Set m_objParameters = Nothing
End Sub
'**************************************************************************
'***'PUBLIC PROPERTIES
'**************************************************************************
Public Property Let ConsumerKey(pData)
m_strConsumerKey = pData
End Property
Public Property Let ConsumerSecret(pData)
m_strConsumerSecret = pData
End Property
Public Property Let EndPoint(pData)
m_strEndPoint = pData
End Property
Public Property Get ErrorCode
ErrorCode = m_strErrorCode
End Property
Public Property Let Host(pData)
m_strHost = pData
End Property
Public Property Get LoggedIn
If IsNull(m_blnLoggedIn) Then
Call Get_LoggedIn()
End If
LoggedIn = m_blnLoggedIn
End Property
Public Property Get Parameters
If m_objParameters Is Nothing Then
Set m_objParameters = Server.CreateObject("Scripting.Dictionary")
End If
Set Parameters = m_objParameters
End Property
Public Property Let RequestMethod(pData)
m_strRequestMethod = pData
End Property
Public Property Get ResponseText
ResponseText = m_strResponseText
End Property
Public Property Let TimeoutURL(pData)
m_strTimeoutURL = pData
End Property
Public Property Let UserAgent(pData)
m_strUserAgent = pData
End Property
'**************************************************************************
'***'PUBLIC FUNCTIONS
'**************************************************************************
'**************************************************************************
' SUB: Send()
' PARAMETERS:
' PURPOSE:
'
' AUTHOR: sdesapio DATE: 04.04.10 LAST MODIFIED: 12.04.12
'**************************************************************************
Public Sub Send()
' build Request URL
Dim strRequestURL : strRequestURL = Get_RequestURL()
' make the call
On Error Resume Next
Dim objXMLHTTP : Set objXMLHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP.6.0")
objXMLHTTP.setTimeouts OAUTH_TIMEOUT_RESOLVE, OAUTH_TIMEOUT_CONNECT, OAUTH_TIMEOUT_SEND, OAUTH_TIMEOUT_RECEIVE
objXMLHTTP.Open m_strRequestMethod, strRequestURL, False
objXMLHTTP.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
objXMLHTTP.SetRequestHeader "User-Agent", m_strUserAgent
objXMLHTTP.SetRequestHeader "Host", m_strHost
objXMLHTTP.Send()
' check for errors
If Err.Number <> 0 Then
Select Case CStr(Err.Number)
Case CStr(OAUTH_ERROR_TIMEOUT)
Response.Redirect m_strTimeoutURL
Response.End
Case Else
m_strErrorCode = Err.Number
End Select
Else
m_strResponseText = objXMLHTTP.ResponseText
End If
Set objXMLHTTP = Nothing
On Error Goto 0
End Sub
'**************************************************************************
' FUNCTION: Get_ResponseValue()
' PARAMETERS: strParamName
' PURPOSE: Returns a value ripped from service provider response
'
' AUTHOR: sdesapio DATE: 04.04.10 LAST MODIFIED: 04.04.10
'**************************************************************************
Public Function Get_ResponseValue(strParamName)
Get_ResponseValue = m_objUtils.Get_ResponseValue(m_strResponseText, strParamName)
End Function
'**************************************************************************
'***'PRIVATE FUNCTIONS
'**************************************************************************
'**************************************************************************
' SUB: Get_LoggedIn
' PARAMETERS:
' PURPOSE:
'
' AUTHOR: sjd DATE: LAST MODIFIED:
'**************************************************************************
Private Sub Get_LoggedIn()
On Error Resume Next
If Session(OAUTH_TOKEN) <> "" And Session(OAUTH_TOKEN_SECRET) <> "" Then
m_blnLoggedIn = True
Else
m_blnLoggedIn = False
End If
If Err.Number <> 0 Then
m_blnLoggedIn = Null
End If
On Error Goto 0
End Sub
'**************************************************************************
' FUNCTION: Get_RequestURL
' PARAMETERS:
' PURPOSE:
'
' AUTHOR: sjd DATE: LAST MODIFIED:
'**************************************************************************
Private Function Get_Parameters()
Dim objQS : Set objQS = New cLibOAuthQS
' add proprieatary param set
If Not m_objParameters Is Nothing Then
Dim Item : For Each Item In m_objParameters
objQS.Add Item, m_objParameters.Item(Item)
Next
End If
' add required standard param set
objQS.Add "oauth_consumer_key", m_strConsumerKey
objQS.Add "oauth_nonce", m_objUtils.Nonce
objQS.Add "oauth_signature_method", OAUTH_SIGNATURE_METHOD
objQS.Add "oauth_timestamp", m_objUtils.TimeStamp
objQS.Add "oauth_version", OAUTH_VERSION
Get_Parameters = objQS.Get_Parameters()
Set objQS = Nothing
End Function
'**************************************************************************
' FUNCTION: Get_RequestURL
' PARAMETERS: strParameters
' PURPOSE: Returns a fully formatted request URL
'
' AUTHOR: sjd DATE: LAST MODIFIED:
'**************************************************************************
Private Function Get_RequestURL()
Dim strParameters : strParameters = Get_Parameters()
Dim objRequestURL : Set objRequestURL = New cLibOAuthRequestURL
objRequestURL.ConsumerSecret = m_strConsumerSecret
objRequestURL.EndPoint = m_strEndPoint
objRequestURL.Method = m_strRequestMethod
objRequestURL.Parameters = strParameters
objRequestURL.TokenSecret = Session(OAUTH_TOKEN_SECRET)
Get_RequestURL = objRequestURL.Get_RequestURL()
Set objRequestURL = Nothing
End Function
End Class
%>