forked from sdesapio/Classic-ASP-VBScript-OAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cLibOAuth.Utils.asp
223 lines (191 loc) · 6.82 KB
/
cLibOAuth.Utils.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
<%
'******************************************************************************
' CLASS: cLibOAuthUtils
' PURPOSE:
'
' AUTHOR: sdesapio DATE: 04.04.10 LAST MODIFIED: 04.04.10
'******************************************************************************
Class cLibOAuthUtils
'**************************************************************************
'***'PRIVATE CLASS MEMBERS
'**************************************************************************
Private m_intOffsetMinutes
Private m_intTimeStamp
Private m_strNonce
'**************************************************************************
'***'CLASS_INITIALIZE / CLASS_TERMINATE
'**************************************************************************
Private Sub Class_Initialize()
m_intOffsetMinutes = Null
m_intTimeStamp = Null
m_strNonce = Null
End Sub
Private Sub Class_Terminate()
End Sub
'**************************************************************************
'***'PUBLIC PROPERTIES
'**************************************************************************
Public Property Get OffsetMinutes
If IsNull(m_intOffsetMinutes) Then
Set_OffsetMinutes()
End If
OffsetMinutes = m_intOffsetMinutes
End Property
Public Property Get Nonce
If IsNull(m_strNonce) Then
Set_Nonce()
End If
Nonce = m_strNonce
End Property
Public Property Get TimeStamp
If IsNull(m_intTimeStamp) Then
Set_Timestamp()
End If
TimeStamp = m_intTimeStamp
End Property
'**************************************************************************
'***'PUBLIC FUNCTIONS
'**************************************************************************
'**************************************************************************
' FUNCTION: Get_ResponseValue
' PARAMETERS: strResponseText, strKey
' PURPOSE: Rips out a specific key/value pair from the service
' provider response and returns the value
'
' AUTHOR: sdesapio DATE: 04.04.10 LAST MODIFIED: 04.04.10
'**************************************************************************
Public Function Get_ResponseValue(strResponseText, strKey)
Dim arrPair, arrPairs : arrPairs = Split(strResponseText, "&")
Dim strRetVal : strRetVal = Null
Dim i : i = 0 : Do While i < UBound(arrPairs) + 1
arrPair = arrPairs(i)
arrPair = Split(arrPair, "=")
If arrPair(0) = strKey Then
strRetVal = arrPair(1)
Exit Do
End If
i = i + 1
Loop
Get_ResponseValue = strRetVal
End Function
'**************************************************************************
' SUB: SortDictionary
' PARAMETERS: objDict (collection), intSort (type)
' PURPOSE: Sorts a dictionary on key or item.
' REF: http://support.microsoft.com/kb/246067
'
' AUTHOR: sdesapio DATE: 04.04.10 LAST MODIFIED: 04.04.10
'**************************************************************************
Public Sub SortDictionary(objDict, intSort)
Const dictKey = 1
Const dictItem = 2
' declare our variables
Dim strDict()
Dim objKey
Dim strKey,strItem
Dim X,Y,Z
' get the dictionary count
Z = objDict.Count
' we need more than one item to warrant sorting
If Z > 1 Then
' create an array to store dictionary information
ReDim strDict(Z,2)
X = 0
' populate the string array
For Each objKey In objDict
strDict(X,dictKey) = CStr(objKey)
strDict(X,dictItem) = CStr(objDict(objKey))
X = X + 1
Next
' perform a a shell sort of the string array
For X = 0 to (Z - 2)
For Y = X to (Z - 1)
If StrComp(strDict(X,intSort),strDict(Y,intSort),vbTextCompare) > 0 Then
strKey = strDict(X,dictKey)
strItem = strDict(X,dictItem)
strDict(X,dictKey) = strDict(Y,dictKey)
strDict(X,dictItem) = strDict(Y,dictItem)
strDict(Y,dictKey) = strKey
strDict(Y,dictItem) = strItem
End If
Next
Next
' erase the contents of the dictionary object
objDict.RemoveAll
' repopulate the dictionary with the sorted information
For X = 0 to (Z - 1)
objDict.Add strDict(X,dictKey), strDict(X,dictItem)
Next
End If
End Sub
'**************************************************************************
' FUNCTION: URLEncode
' PARAMETERS: s (string)
' PURPOSE: URL Encodes only those characters required by the oAuth
' standard because native Server.URLEncode encodes too
' much causing call to fail.
'
' AUTHOR: sdesapio DATE: 04.04.10 LAST MODIFIED: 04.04.10
'**************************************************************************
Public Function URLEncode(s)
Dim strTmpVal : strTmpVal = s
Dim strRetVal : strRetVal = ""
Dim intAsc : intAsc = 0
Dim strHex : strHex = ""
Dim i, strChr : For i = 1 To Len(strTmpVal)
strChr = Mid(strTmpVal, i, 1)
If InStr(1, OAUTH_UNRESERVED, strChr) = 0 Then
intAsc = Asc(strChr)
If intAsc < 32 Or intAsc > 126 Then
strHex = encodeURIComponent(strChr)
Else
strHex = "%" & Hex(intAsc)
End If
strRetVal = strRetVal & strHex
Else
strRetVal = strRetVal & strChr
End If
Next
URLEncode = strRetVal
End Function
'**************************************************************************
'***'PRIVATE FUNCTIONS
'**************************************************************************
'**************************************************************************
' SUB: Set_OffsetMinutes()
' PARAMETERS:
' PURPOSE: Pull out GMT Offset Minutes from registry
'
' AUTHOR: sdesapio DATE: 04.04.10 LAST MODIFIED: 04.04.10
'**************************************************************************
Private Sub Set_OffsetMinutes()
Dim objWshShell : Set objWshShell = Server.CreateObject("WScript.Shell")
m_intOffsetMinutes = objWshShell.RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")
Set objWshShell = Nothing
End Sub
'**************************************************************************
' SUB: Set_Nonce()
' PARAMETERS:
' PURPOSE: Returns string based on timestamp to be used as "random"
'
' AUTHOR: sdesapio DATE: 04.04.10 LAST MODIFIED:
'**************************************************************************
Private Sub Set_Nonce()
m_strNonce = Me.TimeStamp + (Timer() * 1000)
End Sub
'**************************************************************************
' SUB: Set_Timestamp()
' PARAMETERS:
' PURPOSE: Returns numnber of seconds from UNIX Epoch Time
' January 1, 1970 00:00:00 GMT
'
' AUTHOR: sdesapio DATE: 04.04.10 LAST MODIFIED:
'**************************************************************************
Private Sub Set_Timestamp()
Dim dteFrom : dteFrom = "01/01/1970 00:00:00 AM"
Dim dteNow : dteNow = Now()
dteNow = DateAdd("n", Me.OffsetMinutes, dteNow)
m_intTimeStamp = DateDiff("s", dteFrom, dteNow)
End Sub
End Class
%>