├── English.lproj
├── InfoPlist.strings
└── MainMenu.xib
├── Info.plist
├── LICENSE.txt
├── MPOAuth-Info.plist
├── MPOAuth.xcodeproj
└── project.pbxproj
├── MPOAuthConnection_Prefix.pch
├── MPOAuthMobile+Tests-Info.plist
├── MPOAuthMobile-Info.plist
├── MPOAuthMobile_Prefix.pch
├── MPOAuthTestApp-Info.plist
├── Mobile Unit Tests-Info.plist
├── Resources-iPhone
├── MainWindow.xib
├── RootViewController.xib
└── UserAuthViewController.xib
├── Resources
└── oauthAutoConfig.plist
├── Source
├── Framework
│ ├── Crypto
│ │ ├── Base64Transcoder.c
│ │ └── Base64Transcoder.h
│ ├── MPDebug.h
│ ├── MPOAuth.h
│ ├── MPOAuthAPI.h
│ ├── MPOAuthAPI.m
│ ├── MPOAuthAPIRequestLoader.h
│ ├── MPOAuthAPIRequestLoader.m
│ ├── MPOAuthAuthenticationMethod.h
│ ├── MPOAuthAuthenticationMethod.m
│ ├── MPOAuthAuthenticationMethodAuthExchange.h
│ ├── MPOAuthAuthenticationMethodAuthExchange.m
│ ├── MPOAuthAuthenticationMethodOAuth.h
│ ├── MPOAuthAuthenticationMethodOAuth.m
│ ├── MPOAuthAuthenticationMethodXAuth.h
│ ├── MPOAuthAuthenticationMethodXAuth.m
│ ├── MPOAuthConnection.h
│ ├── MPOAuthConnection.m
│ ├── MPOAuthCredentiaIConcreteStore+KeychainAdditionsMac.m
│ ├── MPOAuthCredentialConcreteStore+KeychainAdditions.h
│ ├── MPOAuthCredentialConcreteStore+KeychainAdditionsiPhone.m
│ ├── MPOAuthCredentialConcreteStore.h
│ ├── MPOAuthCredentialConcreteStore.m
│ ├── MPOAuthCredentialStore.h
│ ├── MPOAuthParameterFactory.h
│ ├── MPOAuthSignatureParameter.h
│ ├── MPOAuthSignatureParameter.m
│ ├── MPOAuthURLRequest.h
│ ├── MPOAuthURLRequest.m
│ ├── MPOAuthURLResponse.h
│ ├── MPOAuthURLResponse.m
│ ├── MPURLRequestParameter.h
│ ├── MPURLRequestParameter.m
│ ├── MPWSLRDDiscoverer.h
│ ├── MPWSLRDDiscoverer.m
│ ├── MPWSXRDDocument.h
│ ├── MPWSXRDDocument.m
│ ├── NSString+URLEscapingAdditions.h
│ ├── NSString+URLEscapingAdditions.m
│ ├── NSURL+MPURLParameterAdditions.h
│ ├── NSURL+MPURLParameterAdditions.m
│ ├── NSURLResponse+Encoding.h
│ └── NSURLResponse+Encoding.m
├── Mobile Test App
│ ├── MPOAuthMobileAppDelegate.h
│ ├── MPOAuthMobileAppDelegate.m
│ ├── RootViewController.h
│ ├── RootViewController.m
│ ├── UserAuthViewController.h
│ ├── UserAuthViewController.m
│ └── main.m
├── Test App
│ ├── OAuthClientController.h
│ ├── OAuthClientController.m
│ └── main.m
└── Unit Tests
│ ├── MPOAuthAPIRequestLoaderTests.h
│ ├── MPOAuthAPIRequestLoaderTests.m
│ ├── MPOAuthCredentialConcreteStoreKeychainTests.h
│ ├── MPOAuthCredentialConcreteStoreKeychainTests.m
│ ├── MPOAuthParameterFactoryTests.h
│ ├── MPOAuthParameterFactoryTests.m
│ ├── MPOAuthSignatureParameterTests.h
│ ├── MPOAuthSignatureParameterTests.m
│ ├── MPOAuthURLRequestTests.h
│ ├── MPOAuthURLRequestTests.m
│ ├── MPURLRequestParameterTests.h
│ ├── MPURLRequestParameterTests.m
│ ├── NSString+URLAdditionsTests.h
│ ├── NSString+URLAdditionsTests.m
│ └── OATestServer.rb
├── Unit Tests Static-Info.plist
└── Unit Tests-Info.plist
/English.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thekarladam/MPOAuth/1609e858e7ca89578ecdf490a6c3e471dd6d368e/English.lproj/InfoPlist.strings
--------------------------------------------------------------------------------
/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | com.yourcompany.${PRODUCT_NAME:identifier}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | APPL
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | NSMainNibFile
24 | MainMenu
25 | NSPrincipalClass
26 | NSApplication
27 |
28 |
29 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2008, Karl Adam, matrixPointer
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 |
6 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9 |
--------------------------------------------------------------------------------
/MPOAuth-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | com.matrixPointer.${PRODUCT_NAME:identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | FMWK
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 |
20 |
21 |
--------------------------------------------------------------------------------
/MPOAuthConnection_Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'MPOAuthConnection' target in the 'MPOAuthConnection' project
3 | //
4 |
5 | #ifdef __OBJC__
6 |
7 | #import
8 | #import "MPDebug.h"
9 |
10 | #if TARGET_OS_IPHONE
11 | #import
12 | #elif TARGET_OS_MAC
13 | #import
14 | #endif
15 |
16 | #endif
17 |
--------------------------------------------------------------------------------
/MPOAuthMobile+Tests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleIconFile
12 |
13 | CFBundleIdentifier
14 | com.smudgeProof.${PRODUCT_NAME:identifier}
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleName
18 | ${PRODUCT_NAME}
19 | CFBundlePackageType
20 | APPL
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1.0
25 | LSRequiresIPhoneOS
26 |
27 | CFBundleURLTypes
28 |
29 |
30 | CFBundleURLName
31 | MPOAuth Mobile User Authentication
32 | CFBundleURLSchemes
33 |
34 | x-com-mpoauth-mobile
35 |
36 |
37 |
38 | NSMainNibFile
39 | MainWindow
40 |
41 |
42 |
--------------------------------------------------------------------------------
/MPOAuthMobile-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleDisplayName
8 | ${PRODUCT_NAME}
9 | CFBundleExecutable
10 | ${EXECUTABLE_NAME}
11 | CFBundleIconFile
12 |
13 | CFBundleIdentifier
14 | com.smudgeProof.${PRODUCT_NAME:identifier}
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleName
18 | ${PRODUCT_NAME}
19 | CFBundlePackageType
20 | APPL
21 | CFBundleSignature
22 | ????
23 | CFBundleURLTypes
24 |
25 |
26 | CFBundleURLName
27 | MPOAuth Mobile User Authentication
28 | CFBundleURLSchemes
29 |
30 | x-com-mpoauth-mobile
31 |
32 |
33 |
34 | CFBundleVersion
35 | 1.0
36 | LSRequiresIPhoneOS
37 |
38 | NSMainNibFile
39 | MainWindow
40 |
41 |
42 |
--------------------------------------------------------------------------------
/MPOAuthMobile_Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'MPOAuthMobile' target in the 'MPOAuthMobile' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #import
8 | #import "MPDebug.h"
9 | #endif
10 |
--------------------------------------------------------------------------------
/MPOAuthTestApp-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | APPL
15 | CFBundleShortVersionString
16 | 1.0
17 | CFBundleSignature
18 | ????
19 | CFBundleVersion
20 | 1
21 | LSMinimumSystemVersion
22 | ${MACOSX_DEPLOYMENT_TARGET}
23 | NSMainNibFile
24 | MainMenu
25 | NSPrincipalClass
26 | NSApplication
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Mobile Unit Tests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Resources-iPhone/MainWindow.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 528
5 | 9E17
6 | 672
7 | 949.33
8 | 352.00
9 |
13 |
17 |
62 |
63 |
64 | YES
65 |
66 |
67 | delegate
68 |
69 |
70 |
71 | 4
72 |
73 |
74 |
75 | window
76 |
77 |
78 |
79 | 5
80 |
81 |
82 |
83 | navigationController
84 |
85 |
86 |
87 | 15
88 |
89 |
90 |
91 |
92 | YES
93 |
94 | 0
95 |
96 | YES
97 |
98 |
99 |
100 |
101 |
102 | 2
103 |
104 |
105 | YES
106 |
107 |
108 |
109 |
110 | -1
111 |
112 |
113 | RmlsZSdzIE93bmVyA
114 |
115 |
116 | 3
117 |
118 |
119 |
120 |
121 | -2
122 |
123 |
124 |
125 |
126 | 9
127 |
128 |
129 | YES
130 |
131 |
132 |
133 |
134 |
135 |
136 | 11
137 |
138 |
139 |
140 |
141 | 13
142 |
143 |
144 | YES
145 |
146 |
147 |
148 |
149 |
150 | 14
151 |
152 |
153 |
154 |
155 |
156 |
157 | YES
158 |
159 | YES
160 | -1.CustomClassName
161 | -2.CustomClassName
162 | 11.IBPluginDependency
163 | 13.CustomClassName
164 | 13.IBPluginDependency
165 | 2.IBAttributePlaceholdersKey
166 | 2.IBEditorWindowLastContentRect
167 | 2.IBPluginDependency
168 | 3.CustomClassName
169 | 3.IBPluginDependency
170 | 9.IBEditorWindowLastContentRect
171 | 9.IBPluginDependency
172 |
173 |
174 | YES
175 | UIApplication
176 | UIResponder
177 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
178 | RootViewController
179 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
180 |
181 | YES
182 |
183 | YES
184 |
185 |
186 | YES
187 |
188 |
189 | {{673, 376}, {320, 480}}
190 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
191 | MPOAuthMobileAppDelegate
192 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
193 | {{500, 343}, {320, 480}}
194 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
195 |
196 |
197 |
198 | YES
199 |
200 | YES
201 |
202 |
203 | YES
204 |
205 |
206 |
207 |
208 | YES
209 |
210 | YES
211 |
212 |
213 | YES
214 |
215 |
216 |
217 | 15
218 |
219 |
220 |
221 | YES
222 |
223 | RootViewController
224 | UITableViewController
225 |
226 | IBProjectSource
227 | Classes/RootViewController.h
228 |
229 |
230 |
231 | MPOAuthMobileAppDelegate
232 | NSObject
233 |
234 | YES
235 |
236 | YES
237 | navigationController
238 | window
239 |
240 |
241 | YES
242 | UINavigationController
243 | UIWindow
244 |
245 |
246 |
247 | IBProjectSource
248 | Classes/MPOAuthMobileAppDelegate.h
249 |
250 |
251 |
252 |
253 | 0
254 | MPOAuthMobile.xcodeproj
255 | 3
256 |
257 |
258 |
--------------------------------------------------------------------------------
/Resources-iPhone/UserAuthViewController.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 528
5 | 9G55
6 | 677
7 | 949.43
8 | 353.00
9 |
10 | YES
11 |
12 |
13 |
14 | YES
15 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
16 |
17 |
18 | YES
19 |
20 | YES
21 |
22 |
23 | YES
24 |
25 |
26 |
27 | YES
28 |
29 | IBFilesOwner
30 |
31 |
32 | IBFirstResponder
33 |
34 |
35 |
36 | 292
37 |
38 | YES
39 |
40 |
41 | 274
42 | {320, 480}
43 |
44 |
45 | 1
46 | MSAxIDEAA
47 |
48 | YES
49 | YES
50 | YES
51 |
52 |
53 | {320, 480}
54 |
55 |
56 | 3
57 | MQA
58 |
59 | 2
60 |
61 |
62 |
63 |
64 |
65 |
66 | YES
67 |
68 |
69 | view
70 |
71 |
72 |
73 | 4
74 |
75 |
76 |
77 | webview
78 |
79 |
80 |
81 | 5
82 |
83 |
84 |
85 | delegate
86 |
87 |
88 |
89 | 6
90 |
91 |
92 |
93 |
94 | YES
95 |
96 | 0
97 |
98 | YES
99 |
100 |
101 |
102 |
103 |
104 | 1
105 |
106 |
107 | YES
108 |
109 |
110 |
111 |
112 |
113 | -1
114 |
115 |
116 | RmlsZSdzIE93bmVyA
117 |
118 |
119 | -2
120 |
121 |
122 |
123 |
124 | 3
125 |
126 |
127 |
128 |
129 |
130 |
131 | YES
132 |
133 | YES
134 | -1.CustomClassName
135 | -2.CustomClassName
136 | 1.IBEditorWindowLastContentRect
137 | 1.IBPluginDependency
138 | 3.IBPluginDependency
139 |
140 |
141 | YES
142 | UserAuthViewController
143 | UIResponder
144 | {{354, 276}, {320, 480}}
145 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
146 | com.apple.InterfaceBuilder.IBCocoaTouchPlugin
147 |
148 |
149 |
150 | YES
151 |
152 | YES
153 |
154 |
155 | YES
156 |
157 |
158 |
159 |
160 | YES
161 |
162 | YES
163 |
164 |
165 | YES
166 |
167 |
168 |
169 | 6
170 |
171 |
172 |
173 | YES
174 |
175 | UserAuthViewController
176 | UIViewController
177 |
178 | webview
179 | UIWebView
180 |
181 |
182 | IBProjectSource
183 | Classes/UserAuthViewController.h
184 |
185 |
186 |
187 |
188 | 0
189 | MPOAuthMobile.xcodeproj
190 | 3
191 |
192 |
193 |
--------------------------------------------------------------------------------
/Resources/oauthAutoConfig.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | .yahoo.com
6 |
7 | MPOAuthRequestTokenURL
8 | https://api.login.yahoo.com/oauth/v2/get_request_token
9 | MPOAuthUserAuthorizationURL
10 | https://api.login.yahoo.com/oauth/v2/request_auth
11 | MPOAuthAccessTokenURL
12 | https://api.login.yahoo.com/oauth/v2/get_token
13 |
14 | .twitter.com
15 |
16 | MPOAuthAuthenticationPreferredMethods
17 |
18 | MPOAuthAuthenticationMethodXAuth
19 |
20 | MPOAuthAuthenticationMethodXAuth
21 |
22 | MPOAuthAccessTokenURL
23 | https://api.twitter.com/oauth/access_token
24 |
25 | MPOAuthRequestTokenURL
26 | http://twitter.com/oauth/request_token
27 | MPOAuthUserAuthorizationURL
28 | http://twitter.com/oauth/authorize
29 | MPOAuthAccessTokenURL
30 | http://twitter.com/oauth/access_token
31 |
32 | .google.com
33 |
34 | MPOAuthRequestTokenURL
35 | https://www.google.com/accounts/OAuthGetRequestToken
36 | MPOAuthUserAuthorizationURL
37 | https://www.google.com/accounts/OAuthAuthorizeToken
38 | MPOAuthAccessTokenURL
39 | https://www.google.com/accounts/OAuthGetAccessToken
40 |
41 | .fireeagle.yahooapis.com
42 |
43 | MPOAuthRequestTokenURL
44 | https://fireeagle.yahooapis.com/oauth/request_token
45 | MPOAuthUserAuthorizationURL
46 | https://fireeagle.yahoo.net/auth/
47 | MPOAuthUserAuthorizationMobileURL
48 | https://fireeagle.yahoo.net/mobile_auth/
49 | MPOAuthAccessTokenURL
50 | https://fireeagle.yahooapis.com/oauth/access_token
51 |
52 | .freebaseapps.com
53 |
54 | MPOAuthRequestTokenURL
55 | https://www.freebase.com/api/oauth/request_token
56 | MPOAuthUserAuthorizationURL
57 | https://www.freebase.com/signin/authorize_token
58 | MPOAuthAccessTokenURL
59 | https://www.freebase.com/api/oauth/access_token
60 |
61 | .foursquare.com
62 |
63 | MPOAuthAuthenticationPreferredMethods
64 |
65 | MPOAuthAuthenticationMethodAuthExchange
66 |
67 | MPOAuthAuthenticationMethodAuthExchange
68 |
69 | MPOAuthAccessTokenURL
70 | https://api.foursquare.com/v1/authexchange
71 |
72 | MPOAuthRequestTokenURL
73 | http://www.foursquare.com/oauth/request_token
74 | MPOAuthUserAuthorizationURL
75 | http://www.foursquare.com/oauth/authorize
76 | MPOAuthAccessTokenURL
77 | http://www.foursquare.com/oauth/access_token
78 |
79 | .getsatisfaction.com
80 |
81 | MPOAuthRequestTokenURL
82 | http://getsatisfaction.com/api/request_token
83 | MPOAuthUserAuthorizationURL
84 | http://getsatisfaction.com/api/authorize
85 | MPOAuthAccessTokenURL
86 | http://getsatisfaction.com/api/access_token
87 |
88 | .ironmoney.com
89 |
90 | MPOAuthRequestTokenURL
91 | https://ironmoney.com/oauth/request
92 | MPOAuthUserAuthorizationURL
93 | https://ironmoney.com/oauth/authorize
94 | MPOAuthAccessTokenURL
95 | https://ironmoney.com/oauth/access
96 |
97 | .meetup.com
98 |
99 | MPOAuthRequestTokenURL
100 | http://www.meetup.com/oauth/request/
101 | MPOAuthUserAuthorizationURL
102 | http://www.meetup.com/authorize/
103 | MPOAuthAccessTokenURL
104 | http://www.meetup.com/oauth/access/
105 |
106 | .netflix.com
107 |
108 | MPOAuthRequestTokenURL
109 | http://api.netflix.com/oauth/request_token
110 | MPOAuthUserAuthorizationURL
111 | https://api-user.netflix.com/oauth/login
112 | MPOAuthAccessTokenURL
113 | http://api.netflix.com/oauth/access_token
114 |
115 | .proofile.com
116 |
117 | MPOAuthRequestTokenURL
118 | http://api.proofile.org/oauth/request_token
119 | MPOAuthUserAuthorizationURL
120 | http://api.proofile.org/oauth/authorize
121 | MPOAuthAccessTokenURL
122 | http://api.proofile.org/oauth/access_token
123 |
124 | .smugmug.com
125 |
126 | MPOAuthRequestTokenURL
127 | http://api.smugmug.com/services/oauth/getRequestToken.mg
128 | MPOAuthUserAuthorizationURL
129 | http://api.smugmug.com/services/oauth/authorize.mg
130 | MPOAuthAccessTokenURL
131 | http://api.smugmug.com/services/oauth/getAccessToken.mg
132 |
133 | .soundcloud.com
134 |
135 | MPOAuthRequestTokenURL
136 | http://api.soundcloud.com/oauth/request_token
137 | MPOAuthUserAuthorizationURL
138 | http://soundcloud.com/oauth/authorize_token
139 | MPOAuthAccessTokenURL
140 | http://api.soundcloud.com/oauth/request_token
141 |
142 | .tripit.com
143 |
144 | MPOAuthRequestTokenURL
145 | https://api.tripit.com/oauth/request_token
146 | MPOAuthUserAuthorizationURL
147 | https://www.tripit.com/oauth/authorize
148 | MPOAuthUserAuthorizationMobileURL
149 | https://m.tripit.com/oauth/authorize
150 | MPOAuthAccessTokenURL
151 | https://api.tripit.com/oauth/access_token
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/Source/Framework/Crypto/Base64Transcoder.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Base64Transcoder.c
3 | * Base64Test
4 | *
5 | * Created by Jonathan Wight on Tue Mar 18 2003.
6 | * Copyright (c) 2003 Toxic Software. All rights reserved.
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy
9 | * of this software and associated documentation files (the "Software"), to deal
10 | * in the Software without restriction, including without limitation the rights
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | * copies of the Software, and to permit persons to whom the Software is
13 | * furnished to do so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | * THE SOFTWARE.
25 | *
26 | */
27 |
28 | #include "Base64Transcoder.h"
29 |
30 | #include
31 | #include
32 |
33 | const u_int8_t kBase64EncodeTable[64] = {
34 | /* 0 */ 'A', /* 1 */ 'B', /* 2 */ 'C', /* 3 */ 'D',
35 | /* 4 */ 'E', /* 5 */ 'F', /* 6 */ 'G', /* 7 */ 'H',
36 | /* 8 */ 'I', /* 9 */ 'J', /* 10 */ 'K', /* 11 */ 'L',
37 | /* 12 */ 'M', /* 13 */ 'N', /* 14 */ 'O', /* 15 */ 'P',
38 | /* 16 */ 'Q', /* 17 */ 'R', /* 18 */ 'S', /* 19 */ 'T',
39 | /* 20 */ 'U', /* 21 */ 'V', /* 22 */ 'W', /* 23 */ 'X',
40 | /* 24 */ 'Y', /* 25 */ 'Z', /* 26 */ 'a', /* 27 */ 'b',
41 | /* 28 */ 'c', /* 29 */ 'd', /* 30 */ 'e', /* 31 */ 'f',
42 | /* 32 */ 'g', /* 33 */ 'h', /* 34 */ 'i', /* 35 */ 'j',
43 | /* 36 */ 'k', /* 37 */ 'l', /* 38 */ 'm', /* 39 */ 'n',
44 | /* 40 */ 'o', /* 41 */ 'p', /* 42 */ 'q', /* 43 */ 'r',
45 | /* 44 */ 's', /* 45 */ 't', /* 46 */ 'u', /* 47 */ 'v',
46 | /* 48 */ 'w', /* 49 */ 'x', /* 50 */ 'y', /* 51 */ 'z',
47 | /* 52 */ '0', /* 53 */ '1', /* 54 */ '2', /* 55 */ '3',
48 | /* 56 */ '4', /* 57 */ '5', /* 58 */ '6', /* 59 */ '7',
49 | /* 60 */ '8', /* 61 */ '9', /* 62 */ '+', /* 63 */ '/'
50 | };
51 |
52 | /*
53 | -1 = Base64 end of data marker.
54 | -2 = White space (tabs, cr, lf, space)
55 | -3 = Noise (all non whitespace, non-base64 characters)
56 | -4 = Dangerous noise
57 | -5 = Illegal noise (null byte)
58 | */
59 |
60 | const int8_t kBase64DecodeTable[128] = {
61 | /* 0x00 */ -5, /* 0x01 */ -3, /* 0x02 */ -3, /* 0x03 */ -3,
62 | /* 0x04 */ -3, /* 0x05 */ -3, /* 0x06 */ -3, /* 0x07 */ -3,
63 | /* 0x08 */ -3, /* 0x09 */ -2, /* 0x0a */ -2, /* 0x0b */ -2,
64 | /* 0x0c */ -2, /* 0x0d */ -2, /* 0x0e */ -3, /* 0x0f */ -3,
65 | /* 0x10 */ -3, /* 0x11 */ -3, /* 0x12 */ -3, /* 0x13 */ -3,
66 | /* 0x14 */ -3, /* 0x15 */ -3, /* 0x16 */ -3, /* 0x17 */ -3,
67 | /* 0x18 */ -3, /* 0x19 */ -3, /* 0x1a */ -3, /* 0x1b */ -3,
68 | /* 0x1c */ -3, /* 0x1d */ -3, /* 0x1e */ -3, /* 0x1f */ -3,
69 | /* ' ' */ -2, /* '!' */ -3, /* '"' */ -3, /* '#' */ -3,
70 | /* '$' */ -3, /* '%' */ -3, /* '&' */ -3, /* ''' */ -3,
71 | /* '(' */ -3, /* ')' */ -3, /* '*' */ -3, /* '+' */ 62,
72 | /* ',' */ -3, /* '-' */ -3, /* '.' */ -3, /* '/' */ 63,
73 | /* '0' */ 52, /* '1' */ 53, /* '2' */ 54, /* '3' */ 55,
74 | /* '4' */ 56, /* '5' */ 57, /* '6' */ 58, /* '7' */ 59,
75 | /* '8' */ 60, /* '9' */ 61, /* ':' */ -3, /* ';' */ -3,
76 | /* '<' */ -3, /* '=' */ -1, /* '>' */ -3, /* '?' */ -3,
77 | /* '@' */ -3, /* 'A' */ 0, /* 'B' */ 1, /* 'C' */ 2,
78 | /* 'D' */ 3, /* 'E' */ 4, /* 'F' */ 5, /* 'G' */ 6,
79 | /* 'H' */ 7, /* 'I' */ 8, /* 'J' */ 9, /* 'K' */ 10,
80 | /* 'L' */ 11, /* 'M' */ 12, /* 'N' */ 13, /* 'O' */ 14,
81 | /* 'P' */ 15, /* 'Q' */ 16, /* 'R' */ 17, /* 'S' */ 18,
82 | /* 'T' */ 19, /* 'U' */ 20, /* 'V' */ 21, /* 'W' */ 22,
83 | /* 'X' */ 23, /* 'Y' */ 24, /* 'Z' */ 25, /* '[' */ -3,
84 | /* '\' */ -3, /* ']' */ -3, /* '^' */ -3, /* '_' */ -3,
85 | /* '`' */ -3, /* 'a' */ 26, /* 'b' */ 27, /* 'c' */ 28,
86 | /* 'd' */ 29, /* 'e' */ 30, /* 'f' */ 31, /* 'g' */ 32,
87 | /* 'h' */ 33, /* 'i' */ 34, /* 'j' */ 35, /* 'k' */ 36,
88 | /* 'l' */ 37, /* 'm' */ 38, /* 'n' */ 39, /* 'o' */ 40,
89 | /* 'p' */ 41, /* 'q' */ 42, /* 'r' */ 43, /* 's' */ 44,
90 | /* 't' */ 45, /* 'u' */ 46, /* 'v' */ 47, /* 'w' */ 48,
91 | /* 'x' */ 49, /* 'y' */ 50, /* 'z' */ 51, /* '{' */ -3,
92 | /* '|' */ -3, /* '}' */ -3, /* '~' */ -3, /* 0x7f */ -3
93 | };
94 |
95 | const u_int8_t kBits_00000011 = 0x03;
96 | const u_int8_t kBits_00001111 = 0x0F;
97 | const u_int8_t kBits_00110000 = 0x30;
98 | const u_int8_t kBits_00111100 = 0x3C;
99 | const u_int8_t kBits_00111111 = 0x3F;
100 | const u_int8_t kBits_11000000 = 0xC0;
101 | const u_int8_t kBits_11110000 = 0xF0;
102 | const u_int8_t kBits_11111100 = 0xFC;
103 |
104 | size_t EstimateBas64EncodedDataSize(size_t inDataSize)
105 | {
106 | size_t theEncodedDataSize = (int)ceil(inDataSize / 3.0) * 4;
107 | theEncodedDataSize = theEncodedDataSize / 72 * 74 + theEncodedDataSize % 72;
108 | return(theEncodedDataSize);
109 | }
110 |
111 | size_t EstimateBas64DecodedDataSize(size_t inDataSize)
112 | {
113 | size_t theDecodedDataSize = (int)ceil(inDataSize / 4.0) * 3;
114 | //theDecodedDataSize = theDecodedDataSize / 72 * 74 + theDecodedDataSize % 72;
115 | return(theDecodedDataSize);
116 | }
117 |
118 | bool Base64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize)
119 | {
120 | size_t theEncodedDataSize = EstimateBas64EncodedDataSize(inInputDataSize);
121 | if (*ioOutputDataSize < theEncodedDataSize)
122 | return(false);
123 | *ioOutputDataSize = theEncodedDataSize;
124 | const u_int8_t *theInPtr = (const u_int8_t *)inInputData;
125 | u_int32_t theInIndex = 0, theOutIndex = 0;
126 | for (; theInIndex < (inInputDataSize / 3) * 3; theInIndex += 3)
127 | {
128 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
129 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4];
130 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (theInPtr[theInIndex + 2] & kBits_11000000) >> 6];
131 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 2] & kBits_00111111) >> 0];
132 | if (theOutIndex % 74 == 72)
133 | {
134 | outOutputData[theOutIndex++] = '\r';
135 | outOutputData[theOutIndex++] = '\n';
136 | }
137 | }
138 | const size_t theRemainingBytes = inInputDataSize - theInIndex;
139 | if (theRemainingBytes == 1)
140 | {
141 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
142 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (0 & kBits_11110000) >> 4];
143 | outOutputData[theOutIndex++] = '=';
144 | outOutputData[theOutIndex++] = '=';
145 | if (theOutIndex % 74 == 72)
146 | {
147 | outOutputData[theOutIndex++] = '\r';
148 | outOutputData[theOutIndex++] = '\n';
149 | }
150 | }
151 | else if (theRemainingBytes == 2)
152 | {
153 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_11111100) >> 2];
154 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex] & kBits_00000011) << 4 | (theInPtr[theInIndex + 1] & kBits_11110000) >> 4];
155 | outOutputData[theOutIndex++] = kBase64EncodeTable[(theInPtr[theInIndex + 1] & kBits_00001111) << 2 | (0 & kBits_11000000) >> 6];
156 | outOutputData[theOutIndex++] = '=';
157 | if (theOutIndex % 74 == 72)
158 | {
159 | outOutputData[theOutIndex++] = '\r';
160 | outOutputData[theOutIndex++] = '\n';
161 | }
162 | }
163 | return(true);
164 | }
165 |
166 | bool Base64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize)
167 | {
168 | memset(ioOutputData, '.', *ioOutputDataSize);
169 |
170 | size_t theDecodedDataSize = EstimateBas64DecodedDataSize(inInputDataSize);
171 | if (*ioOutputDataSize < theDecodedDataSize)
172 | return(false);
173 | *ioOutputDataSize = 0;
174 | const u_int8_t *theInPtr = (const u_int8_t *)inInputData;
175 | u_int8_t *theOutPtr = (u_int8_t *)ioOutputData;
176 | size_t theInIndex = 0, theOutIndex = 0;
177 | u_int8_t theOutputOctet;
178 | size_t theSequence = 0;
179 | for (; theInIndex < inInputDataSize; )
180 | {
181 | int8_t theSextet = 0;
182 |
183 | int8_t theCurrentInputOctet = theInPtr[theInIndex];
184 | theSextet = kBase64DecodeTable[theCurrentInputOctet];
185 | if (theSextet == -1)
186 | break;
187 | while (theSextet == -2)
188 | {
189 | theCurrentInputOctet = theInPtr[++theInIndex];
190 | theSextet = kBase64DecodeTable[theCurrentInputOctet];
191 | }
192 | while (theSextet == -3)
193 | {
194 | theCurrentInputOctet = theInPtr[++theInIndex];
195 | theSextet = kBase64DecodeTable[theCurrentInputOctet];
196 | }
197 | if (theSequence == 0)
198 | {
199 | theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 2 & kBits_11111100;
200 | }
201 | else if (theSequence == 1)
202 | {
203 | theOutputOctet |= (theSextet >- 0 ? theSextet : 0) >> 4 & kBits_00000011;
204 | theOutPtr[theOutIndex++] = theOutputOctet;
205 | }
206 | else if (theSequence == 2)
207 | {
208 | theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 4 & kBits_11110000;
209 | }
210 | else if (theSequence == 3)
211 | {
212 | theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 2 & kBits_00001111;
213 | theOutPtr[theOutIndex++] = theOutputOctet;
214 | }
215 | else if (theSequence == 4)
216 | {
217 | theOutputOctet = (theSextet >= 0 ? theSextet : 0) << 6 & kBits_11000000;
218 | }
219 | else if (theSequence == 5)
220 | {
221 | theOutputOctet |= (theSextet >= 0 ? theSextet : 0) >> 0 & kBits_00111111;
222 | theOutPtr[theOutIndex++] = theOutputOctet;
223 | }
224 | theSequence = (theSequence + 1) % 6;
225 | if (theSequence != 2 && theSequence != 4)
226 | theInIndex++;
227 | }
228 | *ioOutputDataSize = theOutIndex;
229 | return(true);
230 | }
231 |
--------------------------------------------------------------------------------
/Source/Framework/Crypto/Base64Transcoder.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Base64Transcoder.h
3 | * Base64Test
4 | *
5 | * Created by Jonathan Wight on Tue Mar 18 2003.
6 | * Copyright (c) 2003 Toxic Software. All rights reserved.
7 | *
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy
9 | * of this software and associated documentation files (the "Software"), to deal
10 | * in the Software without restriction, including without limitation the rights
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | * copies of the Software, and to permit persons to whom the Software is
13 | * furnished to do so, subject to the following conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be included in
16 | * all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | * THE SOFTWARE.
25 | *
26 | */
27 |
28 | #include
29 | #include
30 |
31 | extern size_t EstimateBas64EncodedDataSize(size_t inDataSize);
32 | extern size_t EstimateBas64DecodedDataSize(size_t inDataSize);
33 |
34 | extern bool Base64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize);
35 | extern bool Base64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize);
36 |
37 |
--------------------------------------------------------------------------------
/Source/Framework/MPDebug.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPDebug.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 09.02.06.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #ifdef DEBUG
10 | #define MPLog(...) NSLog(__VA_ARGS__)
11 | #else
12 | #define MPLog(...) do { } while (0)
13 | #endif
14 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuth.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuth.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.13.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | #import
13 | #import
14 | #import
15 | #import
16 | #import
17 | #import
18 | #import
19 | #import
20 | #import
21 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAPI.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAPI.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MPOAuthCredentialStore.h"
11 | #import "MPOAuthParameterFactory.h"
12 |
13 | extern NSString * const MPOAuthNotificationAccessTokenReceived;
14 | extern NSString * const MPOAuthNotificationAccessTokenRejected;
15 | extern NSString * const MPOAuthNotificationAccessTokenRefreshed;
16 | extern NSString * const MPOAuthNotificationOAuthCredentialsReady;
17 | extern NSString * const MPOAuthNotificationErrorHasOccurred;
18 |
19 | extern NSString * const MPOAuthCredentialRequestTokenKey;
20 | extern NSString * const MPOAuthCredentialRequestTokenSecretKey;
21 | extern NSString * const MPOAuthCredentialAccessTokenKey;
22 | extern NSString * const MPOAuthCredentialAccessTokenSecretKey;
23 | extern NSString * const MPOAuthCredentialSessionHandleKey;
24 |
25 | extern NSString * const MPOAuthTokenRefreshDateDefaultsKey;
26 |
27 | extern NSString * const MPOAuthBaseURLKey;
28 | extern NSString * const MPOAuthAuthenticationURLKey;
29 |
30 | typedef enum {
31 | MPOAuthSignatureSchemePlainText,
32 | MPOAuthSignatureSchemeHMACSHA1,
33 | MPOAuthSignatureSchemeRSASHA1
34 | } MPOAuthSignatureScheme;
35 |
36 | typedef enum {
37 | MPOAuthAuthenticationStateUnauthenticated = 0,
38 | MPOAuthAuthenticationStateAuthenticating = 1,
39 | MPOAuthAuthenticationStateAuthenticated = 2
40 | } MPOAuthAuthenticationState;
41 |
42 | @protocol MPOAuthAPIInternalClient
43 | @end
44 |
45 | @class MPOAuthAuthenticationMethod;
46 |
47 | @interface MPOAuthAPI : NSObject {
48 | @private
49 | id credentials_;
50 | NSURL *baseURL_;
51 | NSURL *authenticationURL_;
52 | MPOAuthAuthenticationMethod *authenticationMethod_;
53 | MPOAuthSignatureScheme signatureScheme_;
54 | NSMutableArray *activeLoaders_;
55 | MPOAuthAuthenticationState oauthAuthenticationState_;
56 | }
57 |
58 | @property (nonatomic, readonly, retain) id credentials;
59 | @property (nonatomic, readonly, retain) NSURL *baseURL;
60 | @property (nonatomic, readonly, retain) NSURL *authenticationURL;
61 | @property (nonatomic, readwrite, retain) MPOAuthAuthenticationMethod *authenticationMethod;
62 | @property (nonatomic, readwrite, assign) MPOAuthSignatureScheme signatureScheme;
63 |
64 | @property (nonatomic, readonly, assign) MPOAuthAuthenticationState authenticationState;
65 |
66 |
67 | - (id)initWithCredentials:(NSDictionary *)inCredentials andBaseURL:(NSURL *)inURL;
68 | - (id)initWithCredentials:(NSDictionary *)inCredentials authenticationURL:(NSURL *)inAuthURL andBaseURL:(NSURL *)inBaseURL;
69 | - (id)initWithCredentials:(NSDictionary *)inCredentials authenticationURL:(NSURL *)inAuthURL andBaseURL:(NSURL *)inBaseURL autoStart:(BOOL)aFlag;
70 | - (id)initWithCredentials:(NSDictionary *)inCredentials withConfiguration:(NSDictionary *)inConfiguration autoStart:(BOOL)aFlag;
71 |
72 | - (void)authenticate;
73 | - (BOOL)isAuthenticated;
74 |
75 | - (void)performMethod:(NSString *)inMethod withTarget:(id)inTarget andAction:(SEL)inAction;
76 | - (void)performMethod:(NSString *)inMethod withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction;
77 | - (void)performMethod:(NSString *)inMethod atURL:(NSURL *)inURL withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction;
78 | - (void)performPOSTMethod:(NSString *)inMethod withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction;
79 | - (void)performPOSTMethod:(NSString *)inMethod atURL:(NSURL *)inURL withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction;
80 | - (void)performURLRequest:(NSURLRequest *)inRequest withTarget:(id)inTarget andAction:(SEL)inAction;
81 |
82 | - (NSData *)dataForMethod:(NSString *)inMethod;
83 | - (NSData *)dataForMethod:(NSString *)inMethod withParameters:(NSArray *)inParameters;
84 | - (NSData *)dataForURL:(NSURL *)inURL andMethod:(NSString *)inMethod withParameters:(NSArray *)inParameters;
85 |
86 | - (id)credentialNamed:(NSString *)inCredentialName;
87 | - (void)setCredential:(id)inCredential withName:(NSString *)inName;
88 | - (void)removeCredentialNamed:(NSString *)inName;
89 |
90 | - (void)discardCredentials;
91 |
92 | @end
93 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAPI.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAPI.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthAPIRequestLoader.h"
10 | #import "MPOAuthAPI.h"
11 | #import "MPOAuthCredentialConcreteStore.h"
12 | #import "MPOAuthURLRequest.h"
13 | #import "MPOAuthURLResponse.h"
14 | #import "MPURLRequestParameter.h"
15 | #import "MPOAuthAuthenticationMethod.h"
16 |
17 | #import "NSURL+MPURLParameterAdditions.h"
18 |
19 | NSString *kMPOAuthCredentialConsumerKey = @"kMPOAuthCredentialConsumerKey";
20 | NSString *kMPOAuthCredentialConsumerSecret = @"kMPOAuthCredentialConsumerSecret";
21 | NSString *kMPOAuthCredentialUsername = @"kMPOAuthCredentialUsername";
22 | NSString *kMPOAuthCredentialPassword = @"kMPOAuthCredentialPassword";
23 | NSString *kMPOAuthCredentialRequestToken = @"kMPOAuthCredentialRequestToken";
24 | NSString *kMPOAuthCredentialRequestTokenSecret = @"kMPOAuthCredentialRequestTokenSecret";
25 | NSString *kMPOAuthCredentialAccessToken = @"kMPOAuthCredentialAccessToken";
26 | NSString *kMPOAuthCredentialAccessTokenSecret = @"kMPOAuthCredentialAccessTokenSecret";
27 | NSString *kMPOAuthCredentialSessionHandle = @"kMPOAuthCredentialSessionHandle";
28 |
29 | NSString *kMPOAuthSignatureMethod = @"kMPOAuthSignatureMethod";
30 | NSString * const MPOAuthTokenRefreshDateDefaultsKey = @"MPOAuthAutomaticTokenRefreshLastExpiryDate";
31 |
32 | NSString * const MPOAuthBaseURLKey = @"MPOAuthBaseURL";
33 | NSString * const MPOAuthAuthenticationURLKey = @"MPOAuthAuthenticationURL";
34 |
35 | @interface MPOAuthAPI ()
36 | @property (nonatomic, readwrite, retain) id credentials;
37 | @property (nonatomic, readwrite, retain) NSURL *authenticationURL;
38 | @property (nonatomic, readwrite, retain) NSURL *baseURL;
39 | @property (nonatomic, readwrite, retain) NSMutableArray *activeLoaders;
40 | @property (nonatomic, readwrite, assign) MPOAuthAuthenticationState authenticationState;
41 |
42 | - (void)performMethod:(NSString *)inMethod atURL:(NSURL *)inURL withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction usingHTTPMethod:(NSString *)inHTTPMethod;
43 | @end
44 |
45 | @implementation MPOAuthAPI
46 |
47 | - (id)initWithCredentials:(NSDictionary *)inCredentials andBaseURL:(NSURL *)inBaseURL {
48 | return [self initWithCredentials:inCredentials authenticationURL:inBaseURL andBaseURL:inBaseURL];
49 | }
50 |
51 | - (id)initWithCredentials:(NSDictionary *)inCredentials authenticationURL:(NSURL *)inAuthURL andBaseURL:(NSURL *)inBaseURL {
52 | return [self initWithCredentials:inCredentials authenticationURL:inBaseURL andBaseURL:inBaseURL autoStart:YES];
53 | }
54 |
55 | - (id)initWithCredentials:(NSDictionary *)inCredentials authenticationURL:(NSURL *)inAuthURL andBaseURL:(NSURL *)inBaseURL autoStart:(BOOL)aFlag {
56 | if ((self = [super init])) {
57 | self.authenticationURL = inAuthURL;
58 | self.baseURL = inBaseURL;
59 | self.authenticationState = MPOAuthAuthenticationStateUnauthenticated;
60 | credentials_ = [[MPOAuthCredentialConcreteStore alloc] initWithCredentials:inCredentials forBaseURL:inBaseURL withAuthenticationURL:inAuthURL];
61 | self.authenticationMethod = [[[MPOAuthAuthenticationMethod alloc] initWithAPI:self forURL:inAuthURL] autorelease];
62 | self.signatureScheme = MPOAuthSignatureSchemeHMACSHA1;
63 |
64 | activeLoaders_ = [[NSMutableArray alloc] initWithCapacity:10];
65 |
66 | if (aFlag) {
67 | [self authenticate];
68 | }
69 | }
70 | return self;
71 | }
72 |
73 | - (id)initWithCredentials:(NSDictionary *)inCredentials withConfiguration:(NSDictionary *)inConfiguration autoStart:(BOOL)aFlag {
74 | if ((self = [super init])) {
75 | self.authenticationURL = [inConfiguration valueForKey:MPOAuthAuthenticationURLKey];
76 | self.baseURL = [inConfiguration valueForKey:MPOAuthBaseURLKey];
77 | self.authenticationState = MPOAuthAuthenticationStateUnauthenticated;
78 | credentials_ = [[MPOAuthCredentialConcreteStore alloc] initWithCredentials:inCredentials forBaseURL:self.baseURL withAuthenticationURL:self.authenticationURL];
79 | self.authenticationMethod = [[MPOAuthAuthenticationMethod alloc] initWithAPI:self forURL:self.authenticationURL withConfiguration:inConfiguration];
80 | self.signatureScheme = MPOAuthSignatureSchemeHMACSHA1;
81 |
82 | activeLoaders_ = [[NSMutableArray alloc] initWithCapacity:10];
83 |
84 | if (aFlag) {
85 | [self authenticate];
86 | }
87 | }
88 | return self;
89 | }
90 |
91 | - (oneway void)dealloc {
92 | self.credentials = nil;
93 | self.baseURL = nil;
94 | self.authenticationURL = nil;
95 | self.authenticationMethod = nil;
96 | self.activeLoaders = nil;
97 |
98 | [super dealloc];
99 | }
100 |
101 | @synthesize credentials = credentials_;
102 | @synthesize baseURL = baseURL_;
103 | @synthesize authenticationURL = authenticationURL_;
104 | @synthesize authenticationMethod = authenticationMethod_;
105 | @synthesize signatureScheme = signatureScheme_;
106 | @synthesize activeLoaders = activeLoaders_;
107 | @synthesize authenticationState = oauthAuthenticationState_;
108 |
109 | #pragma mark -
110 |
111 | - (void)setSignatureScheme:(MPOAuthSignatureScheme)inScheme {
112 | signatureScheme_ = inScheme;
113 |
114 | NSString *methodString = @"HMAC-SHA1";
115 |
116 | switch (signatureScheme_) {
117 | case MPOAuthSignatureSchemePlainText:
118 | methodString = @"PLAINTEXT";
119 | break;
120 | case MPOAuthSignatureSchemeRSASHA1:
121 | methodString = @"RSA-SHA1";
122 | case MPOAuthSignatureSchemeHMACSHA1:
123 | default:
124 | // already initted to the default
125 | break;
126 | }
127 |
128 | [(MPOAuthCredentialConcreteStore *)credentials_ setSignatureMethod:methodString];
129 | }
130 |
131 | #pragma mark -
132 |
133 | - (void)authenticate {
134 | NSAssert(credentials_.consumerKey, @"A Consumer Key is required for use of OAuth.");
135 | [self.authenticationMethod authenticate];
136 | }
137 |
138 | - (BOOL)isAuthenticated {
139 | return (self.authenticationState == MPOAuthAuthenticationStateAuthenticated);
140 | }
141 |
142 | #pragma mark -
143 |
144 | - (void)performMethod:(NSString *)inMethod withTarget:(id)inTarget andAction:(SEL)inAction {
145 | [self performMethod:inMethod atURL:self.baseURL withParameters:nil withTarget:inTarget andAction:inAction usingHTTPMethod:@"GET"];
146 | }
147 |
148 | - (void)performMethod:(NSString *)inMethod withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction {
149 | [self performMethod:inMethod atURL:self.baseURL withParameters:inParameters withTarget:inTarget andAction:inAction usingHTTPMethod:@"GET"];
150 | }
151 |
152 | - (void)performMethod:(NSString *)inMethod atURL:(NSURL *)inURL withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction {
153 | [self performMethod:inMethod atURL:inURL withParameters:inParameters withTarget:inTarget andAction:inAction usingHTTPMethod:@"GET"];
154 | }
155 |
156 | - (void)performPOSTMethod:(NSString *)inMethod withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction {
157 | [self performPOSTMethod:inMethod atURL:self.baseURL withParameters:inParameters withTarget:inTarget andAction:inAction];
158 | }
159 |
160 | - (void)performPOSTMethod:(NSString *)inMethod atURL:(NSURL *)inURL withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction {
161 | [self performMethod:inMethod atURL:inURL withParameters:inParameters withTarget:inTarget andAction:inAction usingHTTPMethod:@"POST"];
162 | }
163 |
164 | - (void)performMethod:(NSString *)inMethod atURL:(NSURL *)inURL withParameters:(NSArray *)inParameters withTarget:(id)inTarget andAction:(SEL)inAction usingHTTPMethod:(NSString *)inHTTPMethod {
165 | if (!inMethod && ![inURL path] && ![inURL query]) {
166 | [NSException raise:@"MPOAuthNilMethodRequestException" format:@"Nil was passed as the method to be performed on %@", inURL];
167 | }
168 |
169 | NSURL *requestURL = inMethod ? [NSURL URLWithString:inMethod relativeToURL:inURL] : inURL;
170 | MPOAuthURLRequest *aRequest = [[MPOAuthURLRequest alloc] initWithURL:requestURL andParameters:inParameters];
171 | MPOAuthAPIRequestLoader *loader = [[MPOAuthAPIRequestLoader alloc] initWithRequest:aRequest];
172 |
173 | aRequest.HTTPMethod = inHTTPMethod;
174 | loader.credentials = self.credentials;
175 | loader.target = inTarget;
176 | loader.action = inAction ? inAction : @selector(_performedLoad:receivingData:);
177 |
178 | [loader loadSynchronously:NO];
179 | // [self.activeLoaders addObject:loader];
180 |
181 | [loader release];
182 | [aRequest release];
183 | }
184 |
185 | - (void)performURLRequest:(NSURLRequest *)inRequest withTarget:(id)inTarget andAction:(SEL)inAction {
186 | if (!inRequest && ![[inRequest URL] path] && ![[inRequest URL] query]) {
187 | [NSException raise:@"MPOAuthNilMethodRequestException" format:@"Nil was passed as the method to be performed on %@", inRequest];
188 | }
189 |
190 | MPOAuthURLRequest *aRequest = [[MPOAuthURLRequest alloc] initWithURLRequest:inRequest];
191 | MPOAuthAPIRequestLoader *loader = [[MPOAuthAPIRequestLoader alloc] initWithRequest:aRequest];
192 |
193 | loader.credentials = self.credentials;
194 | loader.target = inTarget;
195 | loader.action = inAction ? inAction : @selector(_performedLoad:receivingData:);
196 |
197 | [loader loadSynchronously:NO];
198 | // [self.activeLoaders addObject:loader];
199 |
200 | [loader release];
201 | [aRequest release];
202 | }
203 |
204 | - (NSData *)dataForMethod:(NSString *)inMethod {
205 | return [self dataForURL:self.baseURL andMethod:inMethod withParameters:nil];
206 | }
207 |
208 | - (NSData *)dataForMethod:(NSString *)inMethod withParameters:(NSArray *)inParameters {
209 | return [self dataForURL:self.baseURL andMethod:inMethod withParameters:inParameters];
210 | }
211 |
212 | - (NSData *)dataForURL:(NSURL *)inURL andMethod:(NSString *)inMethod withParameters:(NSArray *)inParameters {
213 | NSURL *requestURL = [NSURL URLWithString:inMethod relativeToURL:inURL];
214 | MPOAuthURLRequest *aRequest = [[MPOAuthURLRequest alloc] initWithURL:requestURL andParameters:inParameters];
215 | MPOAuthAPIRequestLoader *loader = [[MPOAuthAPIRequestLoader alloc] initWithRequest:aRequest];
216 |
217 | loader.credentials = self.credentials;
218 | [loader loadSynchronously:YES];
219 |
220 | [loader autorelease];
221 | [aRequest release];
222 |
223 | return loader.data;
224 | }
225 |
226 | #pragma mark -
227 |
228 | - (id)credentialNamed:(NSString *)inCredentialName {
229 | return [self.credentials credentialNamed:inCredentialName];
230 | }
231 |
232 | - (void)setCredential:(id)inCredential withName:(NSString *)inName {
233 | [(MPOAuthCredentialConcreteStore *)self.credentials setCredential:inCredential withName:inName];
234 | }
235 |
236 | - (void)removeCredentialNamed:(NSString *)inName {
237 | [(MPOAuthCredentialConcreteStore *)self.credentials removeCredentialNamed:inName];
238 | }
239 |
240 | - (void)discardCredentials {
241 | [self.credentials discardOAuthCredentials];
242 |
243 | self.authenticationState = MPOAuthAuthenticationStateUnauthenticated;
244 | }
245 |
246 | #pragma mark -
247 | #pragma mark - Private APIs -
248 |
249 | - (void)_performedLoad:(MPOAuthAPIRequestLoader *)inLoader receivingData:(NSData *)inData {
250 | // NSLog(@"loaded %@, and got %@", inLoader, inData);
251 | }
252 |
253 | @end
254 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAPIRequestLoader.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAPIRequestLoader.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | extern NSString * const MPOAuthNotificationRequestTokenReceived;
12 | extern NSString * const MPOAuthNotificationRequestTokenRejected;
13 | extern NSString * const MPOAuthNotificationAccessTokenReceived;
14 | extern NSString * const MPOAuthNotificationAccessTokenRejected;
15 | extern NSString * const MPOAuthNotificationAccessTokenRefreshed;
16 | extern NSString * const MPOAuthNotificationErrorHasOccurred;
17 |
18 | @protocol MPOAuthCredentialStore;
19 | @protocol MPOAuthParameterFactory;
20 |
21 | @class MPOAuthURLRequest;
22 | @class MPOAuthURLResponse;
23 | @class MPOAuthCredentialConcreteStore;
24 |
25 | @interface MPOAuthAPIRequestLoader : NSObject {
26 | MPOAuthCredentialConcreteStore *_credentials;
27 | MPOAuthURLRequest *_oauthRequest;
28 | MPOAuthURLResponse *_oauthResponse;
29 | NSMutableData *_dataBuffer;
30 | NSString *_dataAsString;
31 | NSError *_error;
32 | id _target;
33 | SEL _action;
34 | }
35 |
36 | @property (nonatomic, readwrite, retain) id credentials;
37 | @property (nonatomic, readwrite, retain) MPOAuthURLRequest *oauthRequest;
38 | @property (nonatomic, readwrite, retain) MPOAuthURLResponse *oauthResponse;
39 | @property (nonatomic, readonly, retain) NSData *data;
40 | @property (nonatomic, readonly, retain) NSString *responseString;
41 | @property (nonatomic, readwrite, assign) id target;
42 | @property (nonatomic, readwrite, assign) SEL action;
43 |
44 | - (id)initWithURL:(NSURL *)inURL;
45 | - (id)initWithRequest:(MPOAuthURLRequest *)inRequest;
46 |
47 | - (void)loadSynchronously:(BOOL)inSynchronous;
48 |
49 | @end
50 |
51 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAPIRequestLoader.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAPIRequestLoader.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthAPIRequestLoader.h"
10 | #import "MPOAuthURLRequest.h"
11 | #import "MPOAuthURLResponse.h"
12 | #import "MPOAuthConnection.h"
13 | #import "MPOAuthCredentialStore.h"
14 | #import "MPOAuthCredentialConcreteStore.h"
15 | #import "MPURLRequestParameter.h"
16 | #import "NSURLResponse+Encoding.h"
17 | #import "MPDebug.h"
18 |
19 | NSString * const MPOAuthNotificationRequestTokenReceived = @"MPOAuthNotificationRequestTokenReceived";
20 | NSString * const MPOAuthNotificationRequestTokenRejected = @"MPOAuthNotificationRequestTokenRejected";
21 | NSString * const MPOAuthNotificationAccessTokenReceived = @"MPOAuthNotificationAccessTokenReceived";
22 | NSString * const MPOAuthNotificationAccessTokenRejected = @"MPOAuthNotificationAccessTokenRejected";
23 | NSString * const MPOAuthNotificationAccessTokenRefreshed = @"MPOAuthNotificationAccessTokenRefreshed";
24 | NSString * const MPOAuthNotificationOAuthCredentialsReady = @"MPOAuthNotificationOAuthCredentialsReady";
25 | NSString * const MPOAuthNotificationErrorHasOccurred = @"MPOAuthNotificationErrorHasOccurred";
26 |
27 | @interface MPOAuthURLResponse ()
28 | @property (nonatomic, readwrite, retain) NSURLResponse *urlResponse;
29 | @property (nonatomic, readwrite, retain) NSDictionary *oauthParameters;
30 | @end
31 |
32 |
33 | @interface MPOAuthAPIRequestLoader ()
34 | @property (nonatomic, readwrite, retain) NSData *data;
35 | @property (nonatomic, readwrite, retain) NSString *responseString;
36 |
37 | - (void)_interrogateResponseForOAuthData;
38 | @end
39 |
40 | @protocol MPOAuthAPIInternalClient;
41 |
42 | @implementation MPOAuthAPIRequestLoader
43 |
44 | - (id)initWithURL:(NSURL *)inURL {
45 | return [self initWithRequest:[[[MPOAuthURLRequest alloc] initWithURL:inURL andParameters:nil] autorelease]];
46 | }
47 |
48 | - (id)initWithRequest:(MPOAuthURLRequest *)inRequest {
49 | if ((self = [super init])) {
50 | self.oauthRequest = inRequest;
51 | _dataBuffer = [[NSMutableData alloc] init];
52 | }
53 | return self;
54 | }
55 |
56 | - (oneway void)dealloc {
57 | self.credentials = nil;
58 | self.oauthRequest = nil;
59 | self.oauthResponse = nil;
60 | self.data = nil;
61 | self.responseString = nil;
62 |
63 | [super dealloc];
64 | }
65 |
66 | @synthesize credentials = _credentials;
67 | @synthesize oauthRequest = _oauthRequest;
68 | @synthesize oauthResponse = _oauthResponse;
69 | @synthesize data = _dataBuffer;
70 | @synthesize responseString = _dataAsString;
71 | @synthesize target = _target;
72 | @synthesize action = _action;
73 |
74 | #pragma mark -
75 |
76 | - (MPOAuthURLResponse *)oauthResponse {
77 | if (!_oauthResponse) {
78 | _oauthResponse = [[MPOAuthURLResponse alloc] init];
79 | }
80 |
81 | return _oauthResponse;
82 | }
83 |
84 | - (NSString *)responseString {
85 | if (!_dataAsString) {
86 | _dataAsString = [[NSString alloc] initWithData:self.data encoding:[self.oauthResponse.urlResponse encoding]];
87 | }
88 |
89 | return _dataAsString;
90 | }
91 |
92 | - (void)loadSynchronously:(BOOL)inSynchronous {
93 | NSAssert(_credentials, @"Unable to load without valid credentials");
94 | NSAssert(_credentials.consumerKey, @"Unable to load, credentials contain no consumer key");
95 |
96 | if (!inSynchronous) {
97 | [MPOAuthConnection connectionWithRequest:self.oauthRequest delegate:self credentials:self.credentials];
98 | } else {
99 | MPOAuthURLResponse *theOAuthResponse = nil;
100 | self.data = [MPOAuthConnection sendSynchronousRequest:self.oauthRequest usingCredentials:self.credentials returningResponse:&theOAuthResponse error:nil];
101 | self.oauthResponse = theOAuthResponse;
102 | [self _interrogateResponseForOAuthData];
103 | }
104 | }
105 |
106 | #pragma mark -
107 |
108 | - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
109 | MPLog(@"%p: [%@ %@] %@, %@", self, NSStringFromClass([self class]), NSStringFromSelector(_cmd), connection, error);
110 | if ([_target respondsToSelector:@selector(loader:didFailWithError:)]) {
111 | [_target performSelector: @selector(loader:didFailWithError:) withObject: self withObject: error];
112 | }
113 | }
114 |
115 | - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
116 | self.oauthResponse.urlResponse = response;
117 | }
118 |
119 | - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
120 | MPLog(@"%@", NSStringFromSelector(_cmd));
121 | }
122 |
123 | - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
124 | [_dataBuffer appendData:data];
125 | }
126 |
127 | - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse {
128 | MPLog( @"[%@ %@]: %@, %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd), request, redirectResponse);
129 | return request;
130 | }
131 |
132 | - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
133 | [self _interrogateResponseForOAuthData];
134 |
135 | if (_action) {
136 | if ([_target conformsToProtocol:@protocol(MPOAuthAPIInternalClient)]) {
137 | [_target performSelector:_action withObject:self withObject:self.data];
138 | } else {
139 | [_target performSelector:_action withObject:self.oauthRequest.url withObject:self.responseString];
140 | }
141 | }
142 | }
143 |
144 | #pragma mark -
145 |
146 | - (void)_interrogateResponseForOAuthData {
147 | NSString *response = self.responseString;
148 | NSDictionary *foundParameters = nil;
149 | NSInteger status = [(NSHTTPURLResponse *)[self.oauthResponse urlResponse] statusCode];
150 |
151 | if ([response length] > 5 && [[response substringToIndex:5] isEqualToString:@"oauth"]) {
152 | foundParameters = [MPURLRequestParameter parameterDictionaryFromString:response];
153 | self.oauthResponse.oauthParameters = foundParameters;
154 |
155 | if (status == 401 || [foundParameters objectForKey:@"oauth_problem"]) {
156 | NSString *aParameterValue = nil;
157 | MPLog(@"oauthProblem = %@", foundParameters);
158 |
159 | if ([foundParameters count] && (aParameterValue = [foundParameters objectForKey:@"oauth_problem"])) {
160 | if ([aParameterValue isEqualToString:@"token_rejected"]) {
161 | if (self.credentials.requestToken && !self.credentials.accessToken) {
162 | [_credentials setRequestToken:nil];
163 | [_credentials setRequestTokenSecret:nil];
164 |
165 | [[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationRequestTokenRejected
166 | object:nil
167 | userInfo:foundParameters];
168 | } else if (self.credentials.accessToken && !self.credentials.requestToken) {
169 | // your access token may be invalid due to a number of reasons so it's up to the
170 | // user to decide whether or not to remove them
171 | [[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationAccessTokenRejected
172 | object:nil
173 | userInfo:foundParameters];
174 |
175 | }
176 | }
177 |
178 | // something's messed up, so throw an error
179 | [[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationErrorHasOccurred
180 | object:nil
181 | userInfo:foundParameters];
182 | }
183 | } else if ([foundParameters objectForKey:@"oauth_token"]) {
184 | NSString *aParameterValue = nil;
185 | MPLog(@"foundParameters = %@", foundParameters);
186 |
187 | if ([foundParameters count] && (aParameterValue = [foundParameters objectForKey:@"oauth_token"])) {
188 | if (!self.credentials.requestToken && !self.credentials.accessToken) {
189 | [_credentials setRequestToken:aParameterValue];
190 | [_credentials setRequestTokenSecret:[foundParameters objectForKey:@"oauth_token_secret"]];
191 |
192 | [[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationRequestTokenReceived
193 | object:nil
194 | userInfo:foundParameters];
195 |
196 | } else if (!self.credentials.accessToken && self.credentials.requestToken) {
197 | [_credentials setRequestToken:nil];
198 | [_credentials setRequestTokenSecret:nil];
199 | [_credentials setAccessToken:aParameterValue];
200 | [_credentials setAccessTokenSecret:[foundParameters objectForKey:@"oauth_token_secret"]];
201 |
202 | [[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationAccessTokenReceived
203 | object:nil
204 | userInfo:foundParameters];
205 |
206 | } else if (self.credentials.accessToken && !self.credentials.requestToken) {
207 | // replace the current token
208 | [_credentials setAccessToken:aParameterValue];
209 | [_credentials setAccessTokenSecret:[foundParameters objectForKey:@"oauth_token_secret"]];
210 |
211 | [[NSNotificationCenter defaultCenter] postNotificationName:MPOAuthNotificationAccessTokenRefreshed
212 | object:nil
213 | userInfo:foundParameters];
214 | }
215 | }
216 | }
217 | }
218 | }
219 |
220 | @end
221 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAuthenticationMethod.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAuthenticationMethod.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 09.12.19.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | extern NSString * const MPOAuthAccessTokenURLKey;
12 |
13 | @class MPOAuthAPI;
14 |
15 | @interface MPOAuthAuthenticationMethod : NSObject {
16 | MPOAuthAPI *oauthAPI_;
17 | NSURL *oauthGetAccessTokenURL_;
18 | NSTimer *refreshTimer_;
19 | }
20 |
21 | @property (nonatomic, readwrite, assign) MPOAuthAPI *oauthAPI;
22 | @property (nonatomic, readwrite, retain) NSURL *oauthGetAccessTokenURL;
23 |
24 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL;
25 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL withConfiguration:(NSDictionary *)inConfig;
26 | - (void)authenticate;
27 |
28 | - (void)setTokenRefreshInterval:(NSTimeInterval)inTimeInterval;
29 | - (void)refreshAccessToken;
30 | @end
31 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAuthenticationMethod.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAuthenticationMethod.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 09.12.19.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthAuthenticationMethod.h"
10 | #import "MPOAuthAuthenticationMethodOAuth.h"
11 | #import "MPOAuthCredentialConcreteStore.h"
12 | #import "MPURLRequestParameter.h"
13 |
14 | #import "NSURL+MPURLParameterAdditions.h"
15 |
16 | NSString * const MPOAuthAccessTokenURLKey = @"MPOAuthAccessTokenURL";
17 |
18 | @interface MPOAuthAuthenticationMethod ()
19 | @property (nonatomic, readwrite, retain) NSTimer *refreshTimer;
20 |
21 | + (Class)_authorizationMethodClassForURL:(NSURL *)inBaseURL withConfiguration:(NSDictionary **)outConfig;
22 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL withConfiguration:(NSDictionary *)inConfig;
23 | - (void)_automaticallyRefreshAccessToken:(NSTimer *)inTimer;
24 | @end
25 |
26 | @implementation MPOAuthAuthenticationMethod
27 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL {
28 | return [self initWithAPI:inAPI forURL:inURL withConfiguration:nil];
29 | }
30 |
31 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL withConfiguration:(NSDictionary *)inConfig {
32 | if ([[self class] isEqual:[MPOAuthAuthenticationMethod class]]) {
33 | NSDictionary *configuration = inConfig;
34 | Class methodClass = [[self class] _authorizationMethodClassForURL:inURL withConfiguration:&configuration];
35 | [self release];
36 |
37 | self = [[methodClass alloc] initWithAPI:inAPI forURL:inURL withConfiguration:configuration];
38 | } else if ((self = [super init])) {
39 | self.oauthAPI = inAPI;
40 | }
41 |
42 | return self;
43 | }
44 |
45 | - (oneway void)dealloc {
46 | self.oauthAPI = nil;
47 | self.oauthGetAccessTokenURL = nil;
48 |
49 | [self.refreshTimer invalidate];
50 | self.refreshTimer = nil;
51 |
52 | [super dealloc];
53 | }
54 |
55 | @synthesize oauthAPI = oauthAPI_;
56 | @synthesize oauthGetAccessTokenURL = oauthGetAccessTokenURL_;
57 | @synthesize refreshTimer = refreshTimer_;
58 |
59 | #pragma mark -
60 |
61 | + (Class)_authorizationMethodClassForURL:(NSURL *)inBaseURL withConfiguration:(NSDictionary **)outConfig {
62 | Class methodClass = [MPOAuthAuthenticationMethodOAuth class];
63 | NSString *oauthConfigPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"oauthAutoConfig" ofType:@"plist"];
64 | NSDictionary *oauthConfigDictionary = [NSDictionary dictionaryWithContentsOfFile:oauthConfigPath];
65 |
66 | for ( NSString *domainString in [oauthConfigDictionary keyEnumerator]) {
67 | if ([inBaseURL domainMatches:domainString]) {
68 | NSDictionary *oauthConfig = [oauthConfigDictionary objectForKey:domainString];
69 |
70 | NSArray *requestedMethods = [oauthConfig objectForKey:@"MPOAuthAuthenticationPreferredMethods"];
71 | NSString *requestedMethod = nil;
72 | for (requestedMethod in requestedMethods) {
73 | Class requestedMethodClass = NSClassFromString(requestedMethod);
74 |
75 | if (requestedMethodClass) {
76 | methodClass = requestedMethodClass;
77 | }
78 | break;
79 | }
80 |
81 | if (requestedMethod) {
82 | *outConfig = [oauthConfig objectForKey:requestedMethod];
83 | } else {
84 | *outConfig = oauthConfig;
85 | }
86 |
87 | break;
88 | }
89 | }
90 |
91 | return methodClass;
92 | }
93 |
94 | #pragma mark -
95 |
96 | - (void)authenticate {
97 | [NSException raise:@"Not Implemented" format:@"All subclasses of MPOAuthAuthenticationMethod are required to implement -authenticate"];
98 | }
99 |
100 | - (void)setTokenRefreshInterval:(NSTimeInterval)inTimeInterval {
101 | if (!self.refreshTimer && inTimeInterval > 0.0) {
102 | self.refreshTimer = [NSTimer scheduledTimerWithTimeInterval:inTimeInterval target:self selector:@selector(_automaticallyRefreshAccessToken:) userInfo:nil repeats:YES];
103 | }
104 | }
105 |
106 | - (void)refreshAccessToken {
107 | MPURLRequestParameter *sessionHandleParameter = nil;
108 | MPOAuthCredentialConcreteStore *credentials = (MPOAuthCredentialConcreteStore *)[self.oauthAPI credentials];
109 |
110 | if (credentials.sessionHandle) {
111 | sessionHandleParameter = [[MPURLRequestParameter alloc] init];
112 | sessionHandleParameter.name = @"oauth_session_handle";
113 | sessionHandleParameter.value = credentials.sessionHandle;
114 | }
115 |
116 | [self.oauthAPI performMethod:nil
117 | atURL:self.oauthGetAccessTokenURL
118 | withParameters:sessionHandleParameter ? [NSArray arrayWithObject:sessionHandleParameter] : nil
119 | withTarget:nil
120 | andAction:nil];
121 |
122 | [sessionHandleParameter release];
123 | }
124 |
125 | #pragma mark -
126 |
127 | - (void)_automaticallyRefreshAccessToken:(NSTimer *)inTimer {
128 | [self refreshAccessToken];
129 | }
130 |
131 | @end
132 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAuthenticationMethodAuthExchange.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAuthenticationMethodAuthExchange.h
3 | // MPOAuthMobile
4 | //
5 | // Created by Karl Adam on 09.12.20.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MPOAuthAPI.h"
11 | #import "MPOAuthAuthenticationMethod.h"
12 |
13 | @interface MPOAuthAuthenticationMethodAuthExchange : MPOAuthAuthenticationMethod {
14 |
15 | }
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAuthenticationMethodAuthExchange.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAuthenticationMethodAuthExchange.m
3 | // MPOAuthMobile
4 | //
5 | // Created by Karl Adam on 09.12.20.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthAuthenticationMethodAuthExchange.h"
10 | #import "MPOAuthAPI.h"
11 | #import "MPOAuthAPIRequestLoader.h"
12 | #import "MPOAuthCredentialStore.h"
13 | #import "MPURLRequestParameter.h"
14 |
15 | #import
16 | #import
17 | #import
18 |
19 | @interface MPOAuthAPI ()
20 | @property (nonatomic, readwrite, assign) MPOAuthAuthenticationState authenticationState;
21 | @end
22 |
23 | @implementation MPOAuthAuthenticationMethodAuthExchange
24 |
25 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL withConfiguration:(NSDictionary *)inConfig {
26 | if ((self = [super initWithAPI:inAPI forURL:inURL withConfiguration:inConfig])) {
27 | self.oauthGetAccessTokenURL = [NSURL URLWithString:[inConfig objectForKey:MPOAuthAccessTokenURLKey]];
28 | }
29 | return self;
30 | }
31 |
32 | - (void)authenticate {
33 | id credentials = [self.oauthAPI credentials];
34 |
35 | if (!credentials.accessToken && !credentials.accessTokenSecret) {
36 | MPLog(@"--> Performing Access Token Request: %@", self.oauthGetAccessTokenURL);
37 | NSString *username = [[self.oauthAPI credentials] username];
38 | NSString *password = [[self.oauthAPI credentials] password];
39 | NSAssert(username, @"AuthExchange requires a Username credential");
40 | NSAssert(password, @"AuthExchange requires a Password credential");
41 |
42 | MPURLRequestParameter *usernameParameter = [[MPURLRequestParameter alloc] initWithName:@"fs_username" andValue:username];
43 | MPURLRequestParameter *passwordParameter = [[MPURLRequestParameter alloc] initWithName:@"fs_password" andValue:password];
44 |
45 | [self.oauthAPI performPOSTMethod:nil
46 | atURL:self.oauthGetAccessTokenURL
47 | withParameters:[NSArray arrayWithObjects:usernameParameter, passwordParameter, nil]
48 | withTarget:self
49 | andAction:nil];
50 | } else if (credentials.accessToken && credentials.accessTokenSecret) {
51 | NSTimeInterval expiryDateInterval = [[NSUserDefaults standardUserDefaults] doubleForKey:MPOAuthTokenRefreshDateDefaultsKey];
52 | NSDate *tokenExpiryDate = [NSDate dateWithTimeIntervalSinceReferenceDate:expiryDateInterval];
53 |
54 | if ([tokenExpiryDate compare:[NSDate date]] == NSOrderedAscending) {
55 | [self refreshAccessToken];
56 | }
57 | }
58 |
59 | }
60 |
61 | - (void)_performedLoad:(MPOAuthAPIRequestLoader *)inLoader receivingData:(NSData *)inData {
62 | MPLog(@"loaded %@, and got:\n %@", inLoader, inData);
63 | NSString *accessToken = nil;
64 | NSString *accessTokenSecret = nil;
65 | const char *xmlCString = (const char *)[inData bytes];
66 | xmlParserCtxtPtr parserContext = xmlNewParserCtxt();
67 | xmlDocPtr accessTokenXML = xmlCtxtReadMemory(parserContext, xmlCString, strlen(xmlCString), NULL, NULL, XML_PARSE_NOBLANKS);
68 | xmlNodePtr rootNode = xmlDocGetRootElement(accessTokenXML);
69 | xmlNodePtr currentNode = rootNode->children;
70 | const char *currentNodeName = NULL;
71 |
72 | for ( ; currentNode; currentNode = currentNode->next) {
73 | currentNodeName = (const char *)currentNode->name;
74 |
75 | if (strcmp("oauth_token", currentNodeName) == 0) {
76 | xmlChar *oauthToken = xmlNodeGetContent(currentNode);
77 | accessToken = [NSString stringWithUTF8String:(const char *)oauthToken];
78 | } else if (strcmp("oauth_token_secret", currentNodeName) == 0) {
79 | xmlChar *oauthTokenSecret = xmlNodeGetContent(currentNode);
80 | accessTokenSecret = [NSString stringWithUTF8String:(const char *)oauthTokenSecret];
81 | }
82 | }
83 |
84 | if (accessToken && accessTokenSecret) {
85 | [self.oauthAPI removeCredentialNamed:kMPOAuthCredentialPassword];
86 | [self.oauthAPI setCredential:accessToken withName:kMPOAuthCredentialAccessToken];
87 | [self.oauthAPI setCredential:accessTokenSecret withName:kMPOAuthCredentialAccessTokenSecret];
88 | }
89 |
90 | [self.oauthAPI setAuthenticationState:MPOAuthAuthenticationStateAuthenticated];
91 |
92 | xmlFreeDoc(accessTokenXML);
93 | xmlFreeParserCtxt(parserContext);
94 | }
95 |
96 | @end
97 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAuthenticationMethodOAuth.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAuthenticationMethodOAuth.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 09.12.19.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MPOAuthAuthenticationMethod.h"
11 | #import "MPOAuthAPI.h"
12 | #import "MPOAuthAPIRequestLoader.h"
13 |
14 | extern NSString * const MPOAuthRequestTokenURLKey;
15 | extern NSString * const MPOAuthUserAuthorizationURLKey;
16 | extern NSString * const MPOAuthUserAuthorizationMobileURLKey;
17 |
18 | extern NSString * const MPOAuthNotificationRequestTokenReceived;
19 | extern NSString * const MPOAuthNotificationRequestTokenRejected;
20 |
21 | @protocol MPOAuthAuthenticationMethodOAuthDelegate;
22 |
23 | @interface MPOAuthAuthenticationMethodOAuth : MPOAuthAuthenticationMethod {
24 | NSURL *oauthRequestTokenURL_;
25 | NSURL *oauthAuthorizeTokenURL_;
26 | BOOL oauth10aModeActive_;
27 |
28 | id delegate_;
29 | }
30 |
31 | @property (nonatomic, readwrite, assign) id delegate;
32 |
33 | @property (nonatomic, readwrite, retain) NSURL *oauthRequestTokenURL;
34 | @property (nonatomic, readwrite, retain) NSURL *oauthAuthorizeTokenURL;
35 |
36 | - (void)authenticate;
37 |
38 | @end
39 |
40 | @protocol MPOAuthAuthenticationMethodOAuthDelegate
41 | - (NSURL *)callbackURLForCompletedUserAuthorization;
42 | - (BOOL)automaticallyRequestAuthenticationFromURL:(NSURL *)inAuthURL withCallbackURL:(NSURL *)inCallbackURL;
43 |
44 | @optional
45 | - (NSString *)oauthVerifierForCompletedUserAuthorization;
46 | - (void)authenticationDidFailWithError:(NSError *)error;
47 | @end
48 |
49 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAuthenticationMethodOAuth.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAuthenticationMethodOAuth.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 09.12.19.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthAuthenticationMethodOAuth.h"
10 | #import "MPOAuthAPI.h"
11 | #import "MPOAuthAPIRequestLoader.h"
12 | #import "MPOAuthURLResponse.h"
13 | #import "MPOAuthCredentialStore.h"
14 | #import "MPOAuthCredentialConcreteStore.h"
15 | #import "MPURLRequestParameter.h"
16 |
17 | #import "NSURL+MPURLParameterAdditions.h"
18 |
19 | NSString * const MPOAuthRequestTokenURLKey = @"MPOAuthRequestTokenURL";
20 | NSString * const MPOAuthUserAuthorizationURLKey = @"MPOAuthUserAuthorizationURL";
21 | NSString * const MPOAuthUserAuthorizationMobileURLKey = @"MPOAuthUserAuthorizationMobileURL";
22 |
23 | NSString * const MPOAuthCredentialRequestTokenKey = @"oauth_token_request";
24 | NSString * const MPOAuthCredentialRequestTokenSecretKey = @"oauth_token_request_secret";
25 | NSString * const MPOAuthCredentialAccessTokenKey = @"oauth_token_access";
26 | NSString * const MPOAuthCredentialAccessTokenSecretKey = @"oauth_token_access_secret";
27 | NSString * const MPOAuthCredentialSessionHandleKey = @"oauth_session_handle";
28 | NSString * const MPOAuthCredentialVerifierKey = @"oauth_verifier";
29 |
30 | @interface MPOAuthAPI ()
31 | @property (nonatomic, readwrite, assign) MPOAuthAuthenticationState authenticationState;
32 | @end
33 |
34 |
35 | @interface MPOAuthAuthenticationMethodOAuth ()
36 | @property (nonatomic, readwrite, assign) BOOL oauth10aModeActive;
37 |
38 | - (void)_authenticationRequestForRequestToken;
39 | - (void)_authenticationRequestForUserPermissionsConfirmationAtURL:(NSURL *)inURL;
40 | - (void)_authenticationRequestForAccessToken;
41 |
42 | @end
43 |
44 | @implementation MPOAuthAuthenticationMethodOAuth
45 |
46 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL withConfiguration:(NSDictionary *)inConfig {
47 | if ((self = [super initWithAPI:inAPI forURL:inURL withConfiguration:inConfig])) {
48 |
49 | NSAssert( [inConfig count] >= 3, @"Incorrect number of oauth authorization methods");
50 | self.oauthRequestTokenURL = [NSURL URLWithString:[inConfig objectForKey:MPOAuthRequestTokenURLKey]];
51 | self.oauthAuthorizeTokenURL = [NSURL URLWithString:[inConfig objectForKey:MPOAuthUserAuthorizationURLKey]];
52 | self.oauthGetAccessTokenURL = [NSURL URLWithString:[inConfig objectForKey:MPOAuthAccessTokenURLKey]];
53 |
54 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_requestTokenReceived:) name:MPOAuthNotificationRequestTokenReceived object:nil];
55 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_requestTokenRejected:) name:MPOAuthNotificationRequestTokenRejected object:nil];
56 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_accessTokenReceived:) name:MPOAuthNotificationAccessTokenReceived object:nil];
57 | }
58 | return self;
59 | }
60 |
61 | - (oneway void)dealloc {
62 | [[NSNotificationCenter defaultCenter] removeObserver:self];
63 |
64 | self.oauthRequestTokenURL = nil;
65 | self.oauthAuthorizeTokenURL = nil;
66 |
67 | [super dealloc];
68 | }
69 |
70 | @synthesize delegate = delegate_;
71 | @synthesize oauthRequestTokenURL = oauthRequestTokenURL_;
72 | @synthesize oauthAuthorizeTokenURL = oauthAuthorizeTokenURL_;
73 | @synthesize oauth10aModeActive = oauth10aModeActive_;
74 |
75 | #pragma mark -
76 |
77 | - (void)authenticate {
78 | id credentials = [self.oauthAPI credentials];
79 |
80 | if (!credentials.accessToken && !credentials.requestToken) {
81 | [self _authenticationRequestForRequestToken];
82 | } else if (!credentials.accessToken) {
83 | [self _authenticationRequestForAccessToken];
84 | } else if (credentials.accessToken && [[NSUserDefaults standardUserDefaults] objectForKey:MPOAuthTokenRefreshDateDefaultsKey]) {
85 | NSTimeInterval expiryDateInterval = [[NSUserDefaults standardUserDefaults] doubleForKey:MPOAuthTokenRefreshDateDefaultsKey];
86 | NSDate *tokenExpiryDate = [NSDate dateWithTimeIntervalSinceReferenceDate:expiryDateInterval];
87 |
88 | if ([tokenExpiryDate compare:[NSDate date]] == NSOrderedAscending) {
89 | [self refreshAccessToken];
90 | }
91 | }
92 | }
93 |
94 | - (void)_authenticationRequestForRequestToken {
95 | if (self.oauthRequestTokenURL) {
96 | MPLog(@"--> Performing Request Token Request: %@", self.oauthRequestTokenURL);
97 |
98 | // Append the oauth_callbackUrl parameter for requesting the request token
99 | MPURLRequestParameter *callbackParameter = nil;
100 | if (self.delegate && [self.delegate respondsToSelector: @selector(callbackURLForCompletedUserAuthorization)]) {
101 | NSURL *callbackURL = [self.delegate callbackURLForCompletedUserAuthorization];
102 | callbackParameter = [[[MPURLRequestParameter alloc] initWithName:@"oauth_callback" andValue:[callbackURL absoluteString]] autorelease];
103 | } else {
104 | // oob = "Out of bounds"
105 | callbackParameter = [[[MPURLRequestParameter alloc] initWithName:@"oauth_callback" andValue:@"oob"] autorelease];
106 | }
107 |
108 | NSArray *params = [NSArray arrayWithObject:callbackParameter];
109 | [self.oauthAPI performMethod:nil atURL:self.oauthRequestTokenURL withParameters:params withTarget:self andAction:@selector(_authenticationRequestForRequestTokenSuccessfulLoad:withData:)];
110 | }
111 | }
112 |
113 | - (void)_authenticationRequestForRequestTokenSuccessfulLoad:(MPOAuthAPIRequestLoader *)inLoader withData:(NSData *)inData {
114 | NSDictionary *oauthResponseParameters = inLoader.oauthResponse.oauthParameters;
115 | NSString *xoauthRequestAuthURL = [oauthResponseParameters objectForKey:@"xoauth_request_auth_url"]; // a common custom extension, used by Yahoo!
116 | NSURL *userAuthURL = xoauthRequestAuthURL ? [NSURL URLWithString:xoauthRequestAuthURL] : self.oauthAuthorizeTokenURL;
117 | NSURL *callbackURL = nil;
118 |
119 | if (!self.oauth10aModeActive) {
120 | callbackURL = [self.delegate respondsToSelector:@selector(callbackURLForCompletedUserAuthorization)] ? [self.delegate callbackURLForCompletedUserAuthorization] : nil;
121 | }
122 |
123 | NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys: [oauthResponseParameters objectForKey: @"oauth_token"], @"oauth_token",
124 | callbackURL, @"oauth_callback",
125 | nil];
126 |
127 | userAuthURL = [userAuthURL urlByAddingParameterDictionary:parameters];
128 | BOOL delegateWantsToBeInvolved = [self.delegate respondsToSelector:@selector(automaticallyRequestAuthenticationFromURL:withCallbackURL:)];
129 |
130 | if (!delegateWantsToBeInvolved || (delegateWantsToBeInvolved && [self.delegate automaticallyRequestAuthenticationFromURL:userAuthURL withCallbackURL:callbackURL])) {
131 | MPLog(@"--> Automatically Performing User Auth Request: %@", userAuthURL);
132 | [self _authenticationRequestForUserPermissionsConfirmationAtURL:userAuthURL];
133 | }
134 | }
135 |
136 | - (void)loader:(MPOAuthAPIRequestLoader *)inLoader didFailWithError:(NSError *)error {
137 | if ([self.delegate respondsToSelector:@selector(authenticationDidFailWithError:)]) {
138 | [self.delegate authenticationDidFailWithError: error];
139 | }
140 | }
141 |
142 | - (void)_authenticationRequestForUserPermissionsConfirmationAtURL:(NSURL *)userAuthURL {
143 | #if TARGET_OS_IPHONE
144 | [[UIApplication sharedApplication] openURL:userAuthURL];
145 | #else
146 | [[NSWorkspace sharedWorkspace] openURL:userAuthURL];
147 | #endif
148 | }
149 |
150 | - (void)_authenticationRequestForAccessToken {
151 | NSArray *params = nil;
152 |
153 | if (self.delegate && [self.delegate respondsToSelector: @selector(oauthVerifierForCompletedUserAuthorization)]) {
154 | MPURLRequestParameter *verifierParameter = nil;
155 |
156 | NSString *verifier = [self.delegate oauthVerifierForCompletedUserAuthorization];
157 | if (verifier) {
158 | verifierParameter = [[[MPURLRequestParameter alloc] initWithName:@"oauth_verifier" andValue:verifier] autorelease];
159 | params = [NSArray arrayWithObject:verifierParameter];
160 | }
161 | }
162 |
163 | if (self.oauthGetAccessTokenURL) {
164 | MPLog(@"--> Performing Access Token Request: %@", self.oauthGetAccessTokenURL);
165 | [self.oauthAPI performMethod:nil atURL:self.oauthGetAccessTokenURL withParameters:params withTarget:self andAction:nil];
166 | }
167 | }
168 |
169 | #pragma mark -
170 |
171 | - (void)_requestTokenReceived:(NSNotification *)inNotification {
172 | if ([[inNotification userInfo] objectForKey:@"oauth_callback_confirmed"]) {
173 | self.oauth10aModeActive = YES;
174 | }
175 |
176 | [self.oauthAPI setCredential:[[inNotification userInfo] objectForKey:@"oauth_token"] withName:kMPOAuthCredentialRequestToken];
177 | [self.oauthAPI setCredential:[[inNotification userInfo] objectForKey:@"oauth_token_secret"] withName:kMPOAuthCredentialRequestTokenSecret];
178 | }
179 |
180 | - (void)_requestTokenRejected:(NSNotification *)inNotification {
181 | [self.oauthAPI removeCredentialNamed:MPOAuthCredentialRequestTokenKey];
182 | [self.oauthAPI removeCredentialNamed:MPOAuthCredentialRequestTokenSecretKey];
183 | }
184 |
185 | - (void)_accessTokenReceived:(NSNotification *)inNotification {
186 | [self.oauthAPI removeCredentialNamed:MPOAuthCredentialRequestTokenKey];
187 | [self.oauthAPI removeCredentialNamed:MPOAuthCredentialRequestTokenSecretKey];
188 |
189 | [self.oauthAPI setCredential:[[inNotification userInfo] objectForKey:@"oauth_token"] withName:kMPOAuthCredentialAccessToken];
190 | [self.oauthAPI setCredential:[[inNotification userInfo] objectForKey:@"oauth_token_secret"] withName:kMPOAuthCredentialAccessTokenSecret];
191 |
192 | if ([[inNotification userInfo] objectForKey:MPOAuthCredentialSessionHandleKey]) {
193 | [self.oauthAPI setCredential:[[inNotification userInfo] objectForKey:MPOAuthCredentialSessionHandleKey] withName:kMPOAuthCredentialSessionHandle];
194 | }
195 |
196 | [self.oauthAPI setAuthenticationState:MPOAuthAuthenticationStateAuthenticated];
197 |
198 | if ([[inNotification userInfo] objectForKey:@"oauth_expires_in"]) {
199 | NSTimeInterval tokenRefreshInterval = (NSTimeInterval)[[[inNotification userInfo] objectForKey:@"oauth_expires_in"] intValue];
200 | NSDate *tokenExpiryDate = [NSDate dateWithTimeIntervalSinceNow:tokenRefreshInterval];
201 | [[NSUserDefaults standardUserDefaults] setDouble:[tokenExpiryDate timeIntervalSinceReferenceDate] forKey:MPOAuthTokenRefreshDateDefaultsKey];
202 |
203 | if (tokenRefreshInterval > 0.0) {
204 | [self setTokenRefreshInterval:tokenRefreshInterval];
205 | }
206 | } else {
207 | [[NSUserDefaults standardUserDefaults] removeObjectForKey:MPOAuthTokenRefreshDateDefaultsKey];
208 | }
209 | }
210 |
211 | #pragma mark -
212 | #pragma mark - Private APIs -
213 |
214 | - (void)_performedLoad:(MPOAuthAPIRequestLoader *)inLoader receivingData:(NSData *)inData {
215 | // NSLog(@"loaded %@, and got %@", inLoader, inData);
216 | }
217 |
218 | @end
219 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAuthenticationMethodXAuth.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAuthenticationMethodXAuth.h
3 | // MPOAuth
4 | //
5 | // Created by Karl Adam on 10.03.07.
6 | // Copyright 2010 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MPOAuthAPI.h"
11 | #import "MPOAuthAuthenticationMethod.h"
12 |
13 | @interface MPOAuthAuthenticationMethodXAuth : MPOAuthAuthenticationMethod {
14 |
15 | }
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthAuthenticationMethodXAuth.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAuthenticationMethodXAuth.m
3 | // MPOAuth
4 | //
5 | // Created by Karl Adam on 10.03.07.
6 | // Copyright 2010 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthAuthenticationMethodXAuth.h"
10 | #import "MPURLRequestParameter.h"
11 | #import "MPOAuthAPIRequestLoader.h"
12 |
13 | @interface MPOAuthAPI ()
14 | @property (nonatomic, readwrite, assign) MPOAuthAuthenticationState authenticationState;
15 | @end
16 |
17 | @implementation MPOAuthAuthenticationMethodXAuth
18 |
19 | - (id)initWithAPI:(MPOAuthAPI *)inAPI forURL:(NSURL *)inURL withConfiguration:(NSDictionary *)inConfig {
20 | if ((self = [super initWithAPI:inAPI forURL:inURL withConfiguration:inConfig])) {
21 | self.oauthGetAccessTokenURL = [NSURL URLWithString:[inConfig objectForKey:MPOAuthAccessTokenURLKey]];
22 | }
23 | return self;
24 | }
25 |
26 | - (void)authenticate {
27 | id credentials = [self.oauthAPI credentials];
28 |
29 | if (!credentials.accessToken && !credentials.accessTokenSecret) {
30 | MPLog(@"--> Performing Access Token Request: %@", self.oauthGetAccessTokenURL);
31 | NSString *username = [[self.oauthAPI credentials] username];
32 | NSString *password = [[self.oauthAPI credentials] password];
33 | NSAssert(username, @"XAuth requires a Username credential");
34 | NSAssert(password, @"XAuth requires a Password credential");
35 |
36 | MPURLRequestParameter *usernameParameter = [[MPURLRequestParameter alloc] initWithName:@"x_auth_username" andValue:username];
37 | MPURLRequestParameter *passwordParameter = [[MPURLRequestParameter alloc] initWithName:@"x_auth_password" andValue:password];
38 | MPURLRequestParameter *clientModeParameter = [[MPURLRequestParameter alloc] initWithName:@"x_auth_mode" andValue:@"client_auth"];
39 |
40 | [self.oauthAPI performPOSTMethod:nil
41 | atURL:self.oauthGetAccessTokenURL
42 | withParameters:[NSArray arrayWithObjects:usernameParameter, passwordParameter, clientModeParameter, nil]
43 | withTarget:self
44 | andAction:nil];
45 | } else if (credentials.accessToken && credentials.accessTokenSecret) {
46 | NSTimeInterval expiryDateInterval = [[NSUserDefaults standardUserDefaults] doubleForKey:MPOAuthTokenRefreshDateDefaultsKey];
47 | NSDate *tokenExpiryDate = [NSDate dateWithTimeIntervalSinceReferenceDate:expiryDateInterval];
48 |
49 | if ([tokenExpiryDate compare:[NSDate date]] == NSOrderedAscending) {
50 | [self refreshAccessToken];
51 | }
52 | }
53 |
54 | }
55 |
56 | - (void)_performedLoad:(MPOAuthAPIRequestLoader *)inLoader receivingData:(NSData *)inData {
57 | MPLog(@"loaded %@, and got:\n %@", inLoader, inData);
58 | NSString *responseString = [inLoader responseString];
59 | NSDictionary *responseParameters = [MPURLRequestParameter parameterDictionaryFromString:responseString];
60 | MPLog(@"responseParameters = %@", responseParameters);
61 | NSString *accessToken = [responseParameters objectForKey:@"oauth_token"];
62 | NSString *accessTokenSecret = [responseParameters objectForKey:@"oauth_token_secret"];
63 |
64 |
65 | if (accessToken && accessTokenSecret) {
66 | [self.oauthAPI removeCredentialNamed:kMPOAuthCredentialPassword];
67 | [self.oauthAPI setCredential:accessToken withName:kMPOAuthCredentialAccessToken];
68 | [self.oauthAPI setCredential:accessTokenSecret withName:kMPOAuthCredentialAccessTokenSecret];
69 | }
70 |
71 | [self.oauthAPI setAuthenticationState:MPOAuthAuthenticationStateAuthenticated];
72 |
73 | }
74 |
75 | @end
76 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthConnection.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthConnection.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @protocol MPOAuthCredentialStore;
12 | @protocol MPOAuthParameterFactory;
13 |
14 | @class MPOAuthURLRequest;
15 | @class MPOAuthURLResponse;
16 | @class MPOAuthCredentialConcreteStore;
17 |
18 | @interface MPOAuthConnection : NSURLConnection {
19 | @private
20 | MPOAuthCredentialConcreteStore *_credentials;
21 | }
22 |
23 | @property (nonatomic, readonly) id credentials;
24 |
25 | + (MPOAuthConnection *)connectionWithRequest:(MPOAuthURLRequest *)inRequest delegate:(id)inDelegate credentials:(NSObject *)inCredentials;
26 | + (NSData *)sendSynchronousRequest:(MPOAuthURLRequest *)inRequest usingCredentials:(NSObject *)inCredentials returningResponse:(MPOAuthURLResponse **)outResponse error:(NSError **)inError;
27 | - (id)initWithRequest:(MPOAuthURLRequest *)inRequest delegate:(id)inDelegate credentials:(NSObject *)inCredentials;
28 |
29 | @end
30 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthConnection.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthConnection.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthConnection.h"
10 | #import "MPOAuthURLRequest.h"
11 | #import "MPOAuthURLResponse.h"
12 | #import "MPOAuthParameterFactory.h"
13 | #import "MPOAuthCredentialConcreteStore.h"
14 |
15 | @interface MPOAuthURLResponse ()
16 | @property (nonatomic, readwrite, retain) NSURLResponse *urlResponse;
17 | @property (nonatomic, readwrite, retain) NSDictionary *oauthParameters;
18 | @end
19 |
20 | @implementation MPOAuthConnection
21 |
22 | + (MPOAuthConnection *)connectionWithRequest:(MPOAuthURLRequest *)inRequest delegate:(id)inDelegate credentials:(NSObject *)inCredentials {
23 | MPOAuthConnection *aConnection = [[MPOAuthConnection alloc] initWithRequest:inRequest delegate:inDelegate credentials:inCredentials];
24 | return [aConnection autorelease];
25 | }
26 |
27 | + (NSData *)sendSynchronousRequest:(MPOAuthURLRequest *)inRequest usingCredentials:(NSObject *)inCredentials returningResponse:(MPOAuthURLResponse **)outResponse error:(NSError **)inError {
28 | [inRequest addParameters:[inCredentials oauthParameters]];
29 | NSURLRequest *urlRequest = [inRequest urlRequestSignedWithSecret:[inCredentials signingKey] usingMethod:[inCredentials signatureMethod]];
30 | NSURLResponse *urlResponse = nil;
31 | NSData *responseData = [self sendSynchronousRequest:urlRequest returningResponse:&urlResponse error:inError];
32 | MPOAuthURLResponse *oauthResponse = [[[MPOAuthURLResponse alloc] init] autorelease];
33 | oauthResponse.urlResponse = urlResponse;
34 | *outResponse = oauthResponse;
35 |
36 | return responseData;
37 | }
38 |
39 | - (id)initWithRequest:(MPOAuthURLRequest *)inRequest delegate:(id)inDelegate credentials:(NSObject *)inCredentials {
40 | [inRequest addParameters:[inCredentials oauthParameters]];
41 | NSURLRequest *urlRequest = [inRequest urlRequestSignedWithSecret:[inCredentials signingKey] usingMethod:[inCredentials signatureMethod]];
42 | if ((self = [super initWithRequest:urlRequest delegate:inDelegate])) {
43 | _credentials = [inCredentials retain];
44 | }
45 | return self;
46 | }
47 |
48 | - (oneway void)dealloc {
49 | [_credentials release];
50 |
51 | [super dealloc];
52 | }
53 |
54 | @synthesize credentials = _credentials;
55 |
56 | #pragma mark -
57 |
58 | @end
59 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthCredentiaIConcreteStore+KeychainAdditionsMac.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthCredentialConcreteStore+TokenAdditionsMac.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.13.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthCredentialConcreteStore+KeychainAdditions.h"
10 |
11 | #if !TARGET_OS_IPHONE || (TARGET_IPHONE_SIMULATOR && !__IPHONE_3_0)
12 |
13 | @interface MPOAuthCredentialConcreteStore (KeychainAdditionsMac)
14 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName returningItem:(SecKeychainItemRef *)outKeychainItemRef;
15 | @end
16 |
17 | @implementation MPOAuthCredentialConcreteStore (KeychainAdditions)
18 |
19 | - (void)addToKeychainUsingName:(NSString *)inName andValue:(NSString *)inValue {
20 | NSString *serverName = [self.baseURL host];
21 | NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
22 | NSString *securityDomain = [self.authenticationURL host];
23 | NSString *uniqueName = [NSString stringWithFormat:@"%@.%@", bundleID, inName];
24 | SecKeychainItemRef existingKeychainItem = NULL;
25 |
26 | if ([self findValueFromKeychainUsingName:inName returningItem:&existingKeychainItem]) {
27 | // This is MUCH easier than updating the item attributes/data
28 | SecKeychainItemDelete(existingKeychainItem);
29 | }
30 |
31 | SecKeychainAddInternetPassword(NULL /* default keychain */,
32 | [serverName length], [serverName UTF8String],
33 | [securityDomain length], [securityDomain UTF8String],
34 | [uniqueName length], [uniqueName UTF8String], /* account name */
35 | 0, NULL, /* path */
36 | 0,
37 | 'oaut' /* OAuth, not an official OSType code */,
38 | kSecAuthenticationTypeDefault,
39 | [inValue length], [inValue UTF8String],
40 | NULL);
41 | }
42 |
43 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName {
44 | return [self findValueFromKeychainUsingName:inName returningItem:NULL];
45 | }
46 |
47 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName returningItem:(SecKeychainItemRef *)outKeychainItemRef {
48 | NSString *foundPassword = nil;
49 | NSString *serverName = [self.baseURL host];
50 | NSString *securityDomain = [self.authenticationURL host];
51 | NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
52 | NSString *uniqueName = [NSString stringWithFormat:@"%@.%@", bundleID, inName];
53 |
54 | UInt32 passwordLength = 0;
55 | const char *passwordString = NULL;
56 |
57 | OSStatus status = SecKeychainFindInternetPassword(NULL /* default keychain */,
58 | [serverName length], [serverName UTF8String],
59 | [securityDomain length], [securityDomain UTF8String],
60 | [uniqueName length], [uniqueName UTF8String],
61 | 0, NULL, /* path */
62 | 0,
63 | kSecProtocolTypeAny,
64 | kSecAuthenticationTypeAny,
65 | (UInt32 *)&passwordLength,
66 | (void **)&passwordString,
67 | outKeychainItemRef);
68 |
69 | if (status == noErr && passwordLength) {
70 | NSData *passwordStringData = [NSData dataWithBytes:passwordString length:passwordLength];
71 | foundPassword = [[NSString alloc] initWithData:passwordStringData encoding:NSUTF8StringEncoding];
72 | }
73 |
74 | return [foundPassword autorelease];
75 | }
76 |
77 | - (void)removeValueFromKeychainUsingName:(NSString *)inName {
78 | SecKeychainItemRef aKeychainItem = NULL;
79 |
80 | [self findValueFromKeychainUsingName:inName returningItem:&aKeychainItem];
81 |
82 | if (aKeychainItem) {
83 | SecKeychainItemDelete(aKeychainItem);
84 | }
85 | }
86 |
87 | @end
88 |
89 | #endif
90 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthCredentialConcreteStore+KeychainAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthCredentialConcreteStore+TokenAdditionsMac.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.13.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MPOAuthCredentialConcreteStore.h"
11 |
12 | @interface MPOAuthCredentialConcreteStore (KeychainAdditions)
13 |
14 | - (void)addToKeychainUsingName:(NSString *)inName andValue:(NSString *)inValue;
15 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName;
16 | - (void)removeValueFromKeychainUsingName:(NSString *)inName;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthCredentialConcreteStore+KeychainAdditionsiPhone.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthCredentialConcreteStore+TokenAdditionsiPhone.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.13.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthCredentialConcreteStore+KeychainAdditions.h"
10 | #import
11 |
12 | #if TARGET_OS_IPHONE && (!TARGET_IPHONE_SIMULATOR || __IPHONE_3_0)
13 |
14 | @interface MPOAuthCredentialConcreteStore (TokenAdditionsiPhone)
15 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName returningItem:(NSDictionary **)outKeychainItemRef;
16 | @end
17 |
18 | @implementation MPOAuthCredentialConcreteStore (KeychainAdditions)
19 |
20 | - (void)addToKeychainUsingName:(NSString *)inName andValue:(NSString *)inValue {
21 | NSString *serverName = [self.baseURL host];
22 | NSString *securityDomain = [self.authenticationURL host];
23 | // NSString *itemID = [NSString stringWithFormat:@"%@.oauth.%@", [[NSBundle mainBundle] bundleIdentifier], inName];
24 | NSDictionary *searchDictionary = nil;
25 | NSDictionary *keychainItemAttributeDictionary = [NSDictionary dictionaryWithObjectsAndKeys: (id)kSecClassInternetPassword, kSecClass,
26 | securityDomain, kSecAttrSecurityDomain,
27 | serverName, kSecAttrServer,
28 | inName, kSecAttrAccount,
29 | kSecAttrAuthenticationTypeDefault, kSecAttrAuthenticationType,
30 | [NSNumber numberWithUnsignedLongLong:'oaut'], kSecAttrType,
31 | [inValue dataUsingEncoding:NSUTF8StringEncoding], kSecValueData,
32 | nil];
33 |
34 |
35 | if ([self findValueFromKeychainUsingName:inName returningItem:&searchDictionary]) {
36 | NSMutableDictionary *updateDictionary = [keychainItemAttributeDictionary mutableCopy];
37 | [updateDictionary removeObjectForKey:(id)kSecClass];
38 |
39 | SecItemUpdate((CFDictionaryRef)keychainItemAttributeDictionary, (CFDictionaryRef)updateDictionary);
40 | [updateDictionary release];
41 | } else {
42 | OSStatus success = SecItemAdd( (CFDictionaryRef)keychainItemAttributeDictionary, NULL);
43 |
44 | if (success == errSecNotAvailable) {
45 | [NSException raise:@"Keychain Not Available" format:@"Keychain Access Not Currently Available"];
46 | } else if (success == errSecDuplicateItem) {
47 | [NSException raise:@"Keychain duplicate item exception" format:@"Item already exists for %@", keychainItemAttributeDictionary];
48 | }
49 | }
50 | }
51 |
52 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName {
53 | return [self findValueFromKeychainUsingName:inName returningItem:NULL];
54 | }
55 |
56 | - (NSString *)findValueFromKeychainUsingName:(NSString *)inName returningItem:(NSDictionary **)outKeychainItemRef {
57 | NSString *foundPassword = nil;
58 | NSString *serverName = [self.baseURL host];
59 | NSString *securityDomain = [self.authenticationURL host];
60 | NSDictionary *attributesDictionary = nil;
61 | NSData *foundValue = nil;
62 | OSStatus status = noErr;
63 | // NSString *itemID = [NSString stringWithFormat:@"%@.oauth.%@", [[NSBundle mainBundle] bundleIdentifier], inName];
64 |
65 | NSMutableDictionary *searchDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:(id)kSecClassInternetPassword, (id)kSecClass,
66 | securityDomain, (id)kSecAttrSecurityDomain,
67 | serverName, (id)kSecAttrServer,
68 | inName, (id)kSecAttrAccount,
69 | (id)kSecMatchLimitOne, (id)kSecMatchLimit,
70 | (id)kCFBooleanTrue, (id)kSecReturnData,
71 | (id)kCFBooleanTrue, (id)kSecReturnAttributes,
72 | (id)kCFBooleanTrue, (id)kSecReturnPersistentRef,
73 | nil];
74 |
75 | status = SecItemCopyMatching((CFDictionaryRef)searchDictionary, (CFTypeRef *)&attributesDictionary);
76 | foundValue = [attributesDictionary objectForKey:(id)kSecValueData];
77 | if (outKeychainItemRef) {
78 | *outKeychainItemRef = attributesDictionary;
79 | }
80 |
81 | if (status == noErr && foundValue) {
82 | foundPassword = [[NSString alloc] initWithData:foundValue encoding:NSUTF8StringEncoding];
83 | }
84 |
85 | return [foundPassword autorelease];
86 | }
87 |
88 | - (void)removeValueFromKeychainUsingName:(NSString *)inName {
89 | NSString *serverName = [self.baseURL host];
90 | NSString *securityDomain = [self.authenticationURL host];
91 |
92 | NSMutableDictionary *searchDictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys: (id)kSecClassInternetPassword, (id)kSecClass,
93 | securityDomain, (id)kSecAttrSecurityDomain,
94 | serverName, (id)kSecAttrServer,
95 | inName, (id)kSecAttrAccount,
96 | nil];
97 |
98 | OSStatus success = SecItemDelete((CFDictionaryRef)searchDictionary);
99 |
100 | if (success == errSecNotAvailable) {
101 | [NSException raise:@"Keychain Not Available" format:@"Keychain Access Not Currently Available"];
102 | } else if (success == errSecParam) {
103 | [NSException raise:@"Keychain parameter error" format:@"One or more parameters passed to the function were not valid from %@", searchDictionary];
104 | } else if (success == errSecAllocate) {
105 | [NSException raise:@"Keychain memory error" format:@"Failed to allocate memory"];
106 | }
107 |
108 | }
109 |
110 | @end
111 |
112 | #endif TARGET_OS_IPHONE
113 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthCredentialConcreteStore.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthCredentialConcreteStore.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.11.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MPOAuthCredentialStore.h"
11 | #import "MPOAuthParameterFactory.h"
12 |
13 | @interface MPOAuthCredentialConcreteStore : NSObject {
14 | NSMutableDictionary *store_;
15 | NSURL *baseURL_;
16 | NSURL *authenticationURL_;
17 | }
18 |
19 | @property (nonatomic, readonly, retain) NSURL *baseURL;
20 | @property (nonatomic, readonly, retain) NSURL *authenticationURL;
21 |
22 | @property (nonatomic, readonly) NSString *tokenSecret;
23 | @property (nonatomic, readonly) NSString *signingKey;
24 |
25 | @property (nonatomic, readwrite, retain) NSString *requestToken;
26 | @property (nonatomic, readwrite, retain) NSString *requestTokenSecret;
27 | @property (nonatomic, readwrite, retain) NSString *accessToken;
28 | @property (nonatomic, readwrite, retain) NSString *accessTokenSecret;
29 |
30 | @property (nonatomic, readwrite, retain) NSString *sessionHandle;
31 |
32 | - (id)initWithCredentials:(NSDictionary *)inCredentials forBaseURL:(NSURL *)inBaseURL;
33 | - (id)initWithCredentials:(NSDictionary *)inCredentials forBaseURL:(NSURL *)inBaseURL withAuthenticationURL:(NSURL *)inAuthenticationURL;
34 |
35 | - (void)setCredential:(id)inCredential withName:(NSString *)inName;
36 | - (void)removeCredentialNamed:(NSString *)inName;
37 |
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthCredentialConcreteStore.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthCredentialConcreteStore.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.11.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthCredentialConcreteStore.h"
10 | #import "MPURLRequestParameter.h"
11 |
12 | #import "MPOAuthCredentialConcreteStore+KeychainAdditions.h"
13 | #import "NSString+URLEscapingAdditions.h"
14 |
15 | extern NSString * const MPOAuthCredentialRequestTokenKey;
16 | extern NSString * const MPOAuthCredentialRequestTokenSecretKey;
17 | extern NSString * const MPOAuthCredentialAccessTokenKey;
18 | extern NSString * const MPOAuthCredentialAccessTokenSecretKey;
19 | extern NSString * const MPOAuthCredentialSessionHandleKey;
20 |
21 | @interface MPOAuthCredentialConcreteStore ()
22 | @property (nonatomic, readwrite, retain) NSMutableDictionary *store;
23 | @property (nonatomic, readwrite, retain) NSURL *baseURL;
24 | @property (nonatomic, readwrite, retain) NSURL *authenticationURL;
25 | @end
26 |
27 | @implementation MPOAuthCredentialConcreteStore
28 |
29 | - (id)initWithCredentials:(NSDictionary *)inCredentials forBaseURL:(NSURL *)inBaseURL {
30 | return [self initWithCredentials:inCredentials forBaseURL:inBaseURL withAuthenticationURL:inBaseURL];
31 | }
32 |
33 | - (id)initWithCredentials:(NSDictionary *)inCredentials forBaseURL:(NSURL *)inBaseURL withAuthenticationURL:(NSURL *)inAuthenticationURL {
34 | if ((self = [super init])) {
35 | store_ = [[NSMutableDictionary alloc] initWithDictionary:inCredentials];
36 | self.baseURL = inBaseURL;
37 | self.authenticationURL = inAuthenticationURL;
38 |
39 | NSString *requestToken = [self findValueFromKeychainUsingName:kMPOAuthCredentialRequestToken];
40 | NSString *requestTokenSecret = [self findValueFromKeychainUsingName:kMPOAuthCredentialRequestTokenSecret];
41 | NSString *accessToken = [self findValueFromKeychainUsingName:kMPOAuthCredentialAccessToken];
42 | NSString *accessTokenSecret = [self findValueFromKeychainUsingName:kMPOAuthCredentialAccessTokenSecret];
43 | NSString *sessionHandle = [self findValueFromKeychainUsingName:kMPOAuthCredentialSessionHandle];
44 |
45 | self.requestToken = requestToken;
46 | self.requestTokenSecret = requestTokenSecret;
47 | self.accessToken = accessToken;
48 | self.accessTokenSecret = accessTokenSecret;
49 | self.sessionHandle = sessionHandle;
50 | }
51 | return self;
52 | }
53 |
54 | - (oneway void)dealloc {
55 | self.store = nil;
56 | self.baseURL = nil;
57 | self.authenticationURL = nil;
58 |
59 | [super dealloc];
60 | }
61 |
62 | @synthesize store = store_;
63 | @synthesize baseURL = baseURL_;
64 | @synthesize authenticationURL = authenticationURL_;
65 |
66 | #pragma mark -
67 |
68 | - (NSString *)consumerKey {
69 | return [self.store objectForKey:kMPOAuthCredentialConsumerKey];
70 | }
71 |
72 | - (NSString *)consumerSecret {
73 | return [self.store objectForKey:kMPOAuthCredentialConsumerSecret];
74 | }
75 |
76 | - (NSString *)username {
77 | return [self.store objectForKey:kMPOAuthCredentialUsername];
78 | }
79 |
80 | - (NSString *)password {
81 | return [self.store objectForKey:kMPOAuthCredentialPassword];
82 | }
83 |
84 | - (NSString *)requestToken {
85 | return [self.store objectForKey:kMPOAuthCredentialRequestToken];
86 | }
87 |
88 | - (void)setRequestToken:(NSString *)inToken {
89 | if (inToken) {
90 | [self.store setObject:inToken forKey:kMPOAuthCredentialRequestToken];
91 | } else {
92 | [self.store removeObjectForKey:kMPOAuthCredentialRequestToken];
93 | [self removeValueFromKeychainUsingName:kMPOAuthCredentialRequestToken];
94 | }
95 | }
96 |
97 | - (NSString *)requestTokenSecret {
98 | return [self.store objectForKey:kMPOAuthCredentialRequestTokenSecret];
99 | }
100 |
101 | - (void)setRequestTokenSecret:(NSString *)inTokenSecret {
102 | if (inTokenSecret) {
103 | [self.store setObject:inTokenSecret forKey:kMPOAuthCredentialRequestTokenSecret];
104 | } else {
105 | [self.store removeObjectForKey:kMPOAuthCredentialRequestTokenSecret];
106 | [self removeValueFromKeychainUsingName:kMPOAuthCredentialRequestTokenSecret];
107 | }
108 | }
109 |
110 | - (NSString *)accessToken {
111 | return [self.store objectForKey:kMPOAuthCredentialAccessToken];
112 | }
113 |
114 | - (void)setAccessToken:(NSString *)inToken {
115 | if (inToken) {
116 | [self.store setObject:inToken forKey:kMPOAuthCredentialAccessToken];
117 | } else {
118 | [self.store removeObjectForKey:kMPOAuthCredentialAccessToken];
119 | [self removeValueFromKeychainUsingName:kMPOAuthCredentialAccessToken];
120 | }
121 | }
122 |
123 | - (NSString *)accessTokenSecret {
124 | return [self.store objectForKey:kMPOAuthCredentialAccessTokenSecret];
125 | }
126 |
127 | - (void)setAccessTokenSecret:(NSString *)inTokenSecret {
128 | if (inTokenSecret) {
129 | [self.store setObject:inTokenSecret forKey:kMPOAuthCredentialAccessTokenSecret];
130 | } else {
131 | [self.store removeObjectForKey:kMPOAuthCredentialAccessTokenSecret];
132 | [self removeValueFromKeychainUsingName:kMPOAuthCredentialAccessTokenSecret];
133 | }
134 | }
135 |
136 | - (NSString *)sessionHandle {
137 | return [self.store objectForKey:kMPOAuthCredentialSessionHandle];
138 | }
139 |
140 | - (void)setSessionHandle:(NSString *)inSessionHandle {
141 | if (inSessionHandle) {
142 | [self.store setObject:inSessionHandle forKey:kMPOAuthCredentialSessionHandle];
143 | } else {
144 | [self.store removeObjectForKey:kMPOAuthCredentialSessionHandle];
145 | [self removeValueFromKeychainUsingName:kMPOAuthCredentialSessionHandle];
146 | }
147 | }
148 |
149 | #pragma mark -
150 |
151 | - (NSString *)credentialNamed:(NSString *)inCredentialName {
152 | return [store_ objectForKey:inCredentialName];
153 | }
154 |
155 | - (void)setCredential:(id)inCredential withName:(NSString *)inName {
156 | [self.store setObject:inCredential forKey:inName];
157 | [self addToKeychainUsingName:inName andValue:inCredential];
158 | }
159 |
160 | - (void)removeCredentialNamed:(NSString *)inName {
161 | [self.store removeObjectForKey:inName];
162 | [self removeValueFromKeychainUsingName:inName];
163 | }
164 |
165 | - (void)discardOAuthCredentials {
166 | self.requestToken = nil;
167 | self.requestTokenSecret = nil;
168 | self.accessToken = nil;
169 | self.accessTokenSecret = nil;
170 | self.sessionHandle = nil;
171 | }
172 |
173 | #pragma mark -
174 |
175 | - (NSString *)tokenSecret {
176 | NSString *tokenSecret = @"";
177 |
178 | if (self.accessToken) {
179 | tokenSecret = [self accessTokenSecret];
180 | } else if (self.requestToken) {
181 | tokenSecret = [self requestTokenSecret];
182 | }
183 |
184 | return tokenSecret;
185 | }
186 |
187 | - (NSString *)signingKey {
188 | NSString *consumerSecret = [[self consumerSecret] stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding];
189 | NSString *tokenSecret = [[self tokenSecret] stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding];
190 |
191 | return [NSString stringWithFormat:@"%@%&%@", consumerSecret, tokenSecret];
192 | }
193 |
194 | #pragma mark -
195 |
196 | - (NSString *)timestamp {
197 | return [NSString stringWithFormat:@"%d", (int)[[NSDate date] timeIntervalSince1970]];
198 | }
199 |
200 | - (NSString *)signatureMethod {
201 | return [self.store objectForKey:kMPOAuthSignatureMethod];
202 | }
203 |
204 | - (NSArray *)oauthParameters {
205 | NSMutableArray *oauthParameters = [[NSMutableArray alloc] initWithCapacity:5];
206 | MPURLRequestParameter *tokenParameter = [self oauthTokenParameter];
207 |
208 | [oauthParameters addObject:[self oauthConsumerKeyParameter]];
209 | if (tokenParameter) [oauthParameters addObject:tokenParameter];
210 | [oauthParameters addObject:[self oauthSignatureMethodParameter]];
211 | [oauthParameters addObject:[self oauthTimestampParameter]];
212 | [oauthParameters addObject:[self oauthNonceParameter]];
213 | [oauthParameters addObject:[self oauthVersionParameter]];
214 |
215 | return [oauthParameters autorelease];
216 | }
217 |
218 | - (void)setSignatureMethod:(NSString *)inSignatureMethod {
219 | [self.store setObject:inSignatureMethod forKey:kMPOAuthSignatureMethod];
220 | }
221 |
222 | - (MPURLRequestParameter *)oauthConsumerKeyParameter {
223 | MPURLRequestParameter *aRequestParameter = [[MPURLRequestParameter alloc] init];
224 | aRequestParameter.name = @"oauth_consumer_key";
225 | aRequestParameter.value = self.consumerKey;
226 |
227 | return [aRequestParameter autorelease];
228 | }
229 |
230 | - (MPURLRequestParameter *)oauthTokenParameter {
231 | MPURLRequestParameter *aRequestParameter = nil;
232 |
233 | if (self.accessToken || self.requestToken) {
234 | aRequestParameter = [[MPURLRequestParameter alloc] init];
235 | aRequestParameter.name = @"oauth_token";
236 |
237 | if (self.accessToken) {
238 | aRequestParameter.value = self.accessToken;
239 | } else if (self.requestToken) {
240 | aRequestParameter.value = self.requestToken;
241 | }
242 | }
243 |
244 | return [aRequestParameter autorelease];
245 | }
246 |
247 | - (MPURLRequestParameter *)oauthSignatureMethodParameter {
248 | MPURLRequestParameter *aRequestParameter = [[MPURLRequestParameter alloc] init];
249 | aRequestParameter.name = @"oauth_signature_method";
250 | aRequestParameter.value = self.signatureMethod;
251 |
252 | return [aRequestParameter autorelease];
253 | }
254 |
255 | - (MPURLRequestParameter *)oauthTimestampParameter {
256 | MPURLRequestParameter *aRequestParameter = [[MPURLRequestParameter alloc] init];
257 | aRequestParameter.name = @"oauth_timestamp";
258 | aRequestParameter.value = self.timestamp;
259 |
260 | return [aRequestParameter autorelease];
261 | }
262 |
263 | - (MPURLRequestParameter *)oauthNonceParameter {
264 | MPURLRequestParameter *aRequestParameter = [[MPURLRequestParameter alloc] init];
265 | aRequestParameter.name = @"oauth_nonce";
266 |
267 | NSString *generatedNonce = nil;
268 | CFUUIDRef generatedUUID = CFUUIDCreate(kCFAllocatorDefault);
269 |
270 | generatedNonce = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, generatedUUID);
271 | CFRelease(generatedUUID);
272 |
273 | aRequestParameter.value = generatedNonce;
274 | [generatedNonce release];
275 |
276 | return [aRequestParameter autorelease];
277 | }
278 |
279 | - (MPURLRequestParameter *)oauthVersionParameter {
280 | MPURLRequestParameter *versionParameter = [self.store objectForKey:@"versionParameter"];
281 |
282 | if (!versionParameter) {
283 | versionParameter = [[MPURLRequestParameter alloc] init];
284 | versionParameter.name = @"oauth_version";
285 | versionParameter.value = @"1.0";
286 | [versionParameter autorelease];
287 | }
288 |
289 | return versionParameter;
290 | }
291 |
292 | @end
293 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthCredentialStore.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthCredentialStore.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.06.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | extern NSString *kMPOAuthCredentialConsumerKey;
10 | extern NSString *kMPOAuthCredentialConsumerSecret;
11 | extern NSString *kMPOAuthCredentialUsername;
12 | extern NSString *kMPOAuthCredentialPassword;
13 | extern NSString *kMPOAuthCredentialRequestToken;
14 | extern NSString *kMPOAuthCredentialRequestTokenSecret;
15 | extern NSString *kMPOAuthCredentialAccessToken;
16 | extern NSString *kMPOAuthCredentialAccessTokenSecret;
17 | extern NSString *kMPOAuthCredentialSessionHandle;
18 | extern NSString *kMPOAuthCredentialRealm;
19 |
20 | @protocol MPOAuthCredentialStore
21 |
22 | @property (nonatomic, readonly) NSString *consumerKey;
23 | @property (nonatomic, readonly) NSString *consumerSecret;
24 | @property (nonatomic, readonly) NSString *username;
25 | @property (nonatomic, readonly) NSString *password;
26 | @property (nonatomic, readonly, retain) NSString *requestToken;
27 | @property (nonatomic, readonly, retain) NSString *requestTokenSecret;
28 | @property (nonatomic, readonly, retain) NSString *accessToken;
29 | @property (nonatomic, readonly, retain) NSString *accessTokenSecret;
30 |
31 | - (NSString *)credentialNamed:(NSString *)inCredentialName;
32 | - (void)discardOAuthCredentials;
33 | @end
34 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthParameterFactory.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthParameterFactory.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.06.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | extern NSString *kMPOAuthSignatureMethod;
10 |
11 | @class MPURLRequestParameter;
12 |
13 | @protocol MPOAuthParameterFactory
14 |
15 | @property (nonatomic, readwrite, retain) NSString *signatureMethod;
16 | @property (nonatomic, readonly) NSString *signingKey;
17 | @property (nonatomic, readonly) NSString *timestamp;
18 |
19 | - (NSArray *)oauthParameters;
20 |
21 | - (MPURLRequestParameter *)oauthConsumerKeyParameter;
22 | - (MPURLRequestParameter *)oauthTokenParameter;
23 | - (MPURLRequestParameter *)oauthSignatureMethodParameter;
24 | - (MPURLRequestParameter *)oauthTimestampParameter;
25 | - (MPURLRequestParameter *)oauthNonceParameter;
26 | - (MPURLRequestParameter *)oauthVersionParameter;
27 |
28 | @end
29 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthSignatureParameter.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthSignatureParameter.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.07.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MPURLRequestParameter.h"
11 |
12 | #define kMPOAuthSignatureMethodPlaintext @"PLAINTEXT"
13 | #define kMPOAuthSignatureMethodHMACSHA1 @"HMAC-SHA1"
14 | #define kMPOAuthSignatureMethodRSASHA1 @"RSA-SHA1"
15 |
16 | @class MPOAuthURLRequest;
17 |
18 | @interface MPOAuthSignatureParameter : MPURLRequestParameter {
19 |
20 | }
21 |
22 | + (NSString *)signatureBaseStringUsingParameterString:(NSString *)inParameterString forRequest:(MPOAuthURLRequest *)inRequest;
23 | + (NSString *)HMAC_SHA1SignatureForText:(NSString *)inText usingSecret:(NSString *)inSecret;
24 |
25 | - (id)initWithText:(NSString *)inText andSecret:(NSString *)inSecret forRequest:(MPOAuthURLRequest *)inRequest usingMethod:(NSString *)inMethod;
26 |
27 |
28 | @end
29 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthSignatureParameter.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthSignatureParameter.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.07.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthSignatureParameter.h"
10 | #import "MPOAuthURLRequest.h"
11 | #import "NSString+URLEscapingAdditions.h"
12 | #import "NSURL+MPURLParameterAdditions.h"
13 |
14 | #import
15 | #include "Base64Transcoder.h"
16 |
17 | @interface MPOAuthSignatureParameter ()
18 | - (id)initUsingHMAC_SHA1WithText:(NSString *)inText andSecret:(NSString *)inSecret forRequest:(MPOAuthURLRequest *)inRequest;
19 | @end
20 |
21 | @implementation MPOAuthSignatureParameter
22 |
23 | + (NSString *)signatureBaseStringUsingParameterString:(NSString *)inParameterString forRequest:(MPOAuthURLRequest *)inRequest {
24 | return [NSString stringWithFormat:@"%@&%@&%@", [inRequest HTTPMethod],
25 | [[inRequest.url absoluteNormalizedString] stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding],
26 | [inParameterString stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
27 | }
28 |
29 | + (NSString *)HMAC_SHA1SignatureForText:(NSString *)inText usingSecret:(NSString *)inSecret {
30 | NSData *secretData = [inSecret dataUsingEncoding:NSUTF8StringEncoding];
31 | NSData *textData = [inText dataUsingEncoding:NSUTF8StringEncoding];
32 | unsigned char result[CC_SHA1_DIGEST_LENGTH];
33 |
34 | CCHmacContext hmacContext;
35 | bzero(&hmacContext, sizeof(CCHmacContext));
36 | CCHmacInit(&hmacContext, kCCHmacAlgSHA1, secretData.bytes, secretData.length);
37 | CCHmacUpdate(&hmacContext, textData.bytes, textData.length);
38 | CCHmacFinal(&hmacContext, result);
39 |
40 | //Base64 Encoding
41 | char base64Result[32];
42 | size_t theResultLength = 32;
43 | Base64EncodeData(result, 20, base64Result, &theResultLength);
44 | NSData *theData = [NSData dataWithBytes:base64Result length:theResultLength];
45 | NSString *base64EncodedResult = [[[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding] autorelease];
46 |
47 | return base64EncodedResult;
48 | }
49 |
50 | - (id)initWithText:(NSString *)inText andSecret:(NSString *)inSecret forRequest:(MPOAuthURLRequest *)inRequest usingMethod:(NSString *)inMethod {
51 | if ([inMethod isEqual:kMPOAuthSignatureMethodHMACSHA1]) {
52 | self = [self initUsingHMAC_SHA1WithText:inText andSecret:inSecret forRequest:inRequest];
53 | } else if ([inMethod isEqualToString:kMPOAuthSignatureMethodPlaintext]) {
54 | if ((self = [super init])) {
55 | self.name = @"oauth_signature";
56 | self.value = inSecret;
57 | }
58 | } else {
59 | [self release];
60 | self = nil;
61 | [NSException raise:@"Unsupported Signature Method" format:@"The signature method \"%@\" is not currently support by MPOAuthConnection", inMethod];
62 | }
63 |
64 | return self;
65 | }
66 |
67 | - (id)initUsingHMAC_SHA1WithText:(NSString *)inText andSecret:(NSString *)inSecret forRequest:(MPOAuthURLRequest *)inRequest {
68 | if ((self = [super init])) {
69 | NSString *signatureBaseString = [MPOAuthSignatureParameter signatureBaseStringUsingParameterString:inText forRequest:inRequest];
70 |
71 | self.name = @"oauth_signature";
72 | self.value = [MPOAuthSignatureParameter HMAC_SHA1SignatureForText:signatureBaseString usingSecret:inSecret];
73 | }
74 | return self;
75 | }
76 |
77 | - (oneway void)dealloc {
78 | [super dealloc];
79 | }
80 |
81 | @end
82 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthURLRequest.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthURLRequest.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface MPOAuthURLRequest : NSObject {
13 | @private
14 | NSURL *_url;
15 | NSString *_httpMethod;
16 | NSURLRequest *_urlRequest;
17 | NSMutableArray *_parameters;
18 | }
19 |
20 | @property (nonatomic, readwrite, retain) NSURL *url;
21 | @property (nonatomic, readwrite, retain) NSString *HTTPMethod;
22 | @property (nonatomic, readonly, retain) NSURLRequest *urlRequest;
23 | @property (nonatomic, readwrite, retain) NSMutableArray *parameters;
24 |
25 | - (id)initWithURL:(NSURL *)inURL andParameters:(NSArray *)parameters;
26 | - (id)initWithURLRequest:(NSURLRequest *)inRequest;
27 |
28 | - (void)addParameters:(NSArray *)inParameters;
29 |
30 | - (NSURLRequest *)urlRequestSignedWithSecret:(NSString *)inSecret usingMethod:(NSString *)inScheme;
31 |
32 | @end
33 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthURLRequest.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthURLRequest.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthURLRequest.h"
10 | #import "MPURLRequestParameter.h"
11 | #import "MPOAuthSignatureParameter.h"
12 |
13 | #import "NSURL+MPURLParameterAdditions.h"
14 | #import "NSString+URLEscapingAdditions.h"
15 |
16 | @interface MPOAuthURLRequest ()
17 | @property (nonatomic, readwrite, retain) NSURLRequest *urlRequest;
18 | @end
19 |
20 | @implementation MPOAuthURLRequest
21 |
22 | - (id)initWithURL:(NSURL *)inURL andParameters:(NSArray *)inParameters {
23 | if ((self = [super init])) {
24 | self.url = inURL;
25 | _parameters = inParameters ? [inParameters mutableCopy] : [[NSMutableArray alloc] initWithCapacity:10];
26 | self.HTTPMethod = @"GET";
27 | }
28 | return self;
29 | }
30 |
31 | - (id)initWithURLRequest:(NSURLRequest *)inRequest {
32 | if ((self = [super init])) {
33 | self.url = [[inRequest URL] urlByRemovingQuery];
34 | self.parameters = [[[MPURLRequestParameter parametersFromString:[[inRequest URL] query]] mutableCopy] autorelease];
35 | self.HTTPMethod = [inRequest HTTPMethod];
36 | self.urlRequest = [[inRequest mutableCopy] autorelease];
37 | }
38 | return self;
39 | }
40 |
41 | - (oneway void)dealloc {
42 | self.url = nil;
43 | self.HTTPMethod = nil;
44 | self.urlRequest = nil;
45 | self.parameters = nil;
46 |
47 | [super dealloc];
48 | }
49 |
50 | @synthesize url = _url;
51 | @synthesize HTTPMethod = _httpMethod;
52 | @synthesize urlRequest = _urlRequest;
53 | @synthesize parameters = _parameters;
54 |
55 | #pragma mark -
56 |
57 | - (NSArray *)nonOAuthParameters {
58 | NSArray *oauthParameters = [NSArray arrayWithObjects:@"oauth_signature", @"oauth_nonce", @"oauth_token", @"oauth_consumer_key", @"oauth_timestamp", @"oauth_version", @"oauth_signature_method", nil];
59 | NSPredicate *filterPredicate = [NSPredicate predicateWithFormat:@"!(name IN %@)", oauthParameters];
60 | return [self.parameters filteredArrayUsingPredicate:filterPredicate];
61 | }
62 |
63 | - (NSString *)authorizationHeaderValueFromParameterString:(NSString *)parameterString {
64 | NSDictionary *paramsDict = [MPURLRequestParameter parameterDictionaryFromString:parameterString];
65 | NSString *signature = [[paramsDict objectForKey:@"oauth_signature"] stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding];
66 | NSString *nonce = [[paramsDict objectForKey:@"oauth_nonce"] stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding];
67 | NSString *token = [[paramsDict objectForKey:@"oauth_token"] stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding];
68 | NSString *consumerKey = [[paramsDict objectForKey:@"oauth_consumer_key"] stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding];
69 | NSString *timeStamp = [[paramsDict objectForKey:@"oauth_timestamp"] stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding];
70 | NSString *version = [[paramsDict objectForKey:@"oauth_version"] stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding];
71 | NSString *method = [[paramsDict objectForKey:@"oauth_signature_method"] stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding];
72 | NSString *fullAuthString = nil;
73 |
74 | if (token) {
75 | fullAuthString = [NSString stringWithFormat:@"OAuth oauth_token=\"%@\",oauth_consumer_key=\"%@\",oauth_version=\"%@\",oauth_signature_method=\"%@\", oauth_timestamp=\"%@\",oauth_nonce=\"%@\",oauth_signature=\"%@\"", token, consumerKey, version, method, timeStamp, nonce, signature];
76 | } else {
77 | fullAuthString = [NSString stringWithFormat:@"OAuth oauth_consumer_key=\"%@\",oauth_version=\"%@\",oauth_signature_method=\"%@\", oauth_timestamp=\"%@\",oauth_nonce=\"%@\",oauth_signature=\"%@\"", consumerKey, version, method, timeStamp, nonce, signature];
78 | }
79 |
80 | return fullAuthString;
81 | }
82 |
83 | - (NSURLRequest *)urlRequestSignedWithSecret:(NSString *)inSecret usingMethod:(NSString *)inScheme {
84 | NSMutableURLRequest *aRequest = [self.urlRequest mutableCopy];
85 | [self.parameters sortUsingSelector:@selector(compare:)];
86 |
87 | if (!aRequest ) {
88 | aRequest = [[NSMutableURLRequest alloc] init];
89 | }
90 |
91 | NSString *urlString = nil;
92 | NSMutableString *parameterString = [[NSMutableString alloc] initWithString:[MPURLRequestParameter parameterStringForParameters:self.parameters]];
93 | MPOAuthSignatureParameter *signatureParameter = [[MPOAuthSignatureParameter alloc] initWithText:parameterString andSecret:inSecret forRequest:self usingMethod:inScheme];
94 |
95 | [parameterString appendFormat:@"&%@", [signatureParameter URLEncodedParameterString]];
96 | [aRequest setHTTPMethod:self.HTTPMethod];
97 |
98 | if ([[self HTTPMethod] isEqualToString:@"GET"] && [self.parameters count]) {
99 | urlString = [NSString stringWithFormat:@"%@?%@", [self.url absoluteString], parameterString];
100 | } else if ([[self HTTPMethod] isEqualToString:@"POST"]) {
101 | NSArray *nonOauthParameters = [self nonOAuthParameters];
102 | urlString = [self.url absoluteString];
103 | [aRequest setValue: [self authorizationHeaderValueFromParameterString:parameterString] forHTTPHeaderField:@"Authorization"];
104 |
105 | if ([nonOauthParameters count] && [aRequest HTTPBody]) {
106 | [NSException raise:@"MalformedHTTPPOSTMethodException" format:@"The request has both an HTTP Body and additional parameters. This is not supported."];
107 | } else if ([nonOauthParameters count]) {
108 | NSString *postDataString = [MPURLRequestParameter parameterStringForParameters:nonOauthParameters];
109 | NSData *postData = [postDataString dataUsingEncoding:NSUTF8StringEncoding];
110 | MPLog(@"postDataString - %@", postDataString);
111 |
112 | [aRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
113 | [aRequest setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"];
114 | [aRequest setHTTPBody:postData];
115 | }
116 | } else {
117 | [NSException raise:@"UnhandledHTTPMethodException" format:@"The requested HTTP method, %@, is not supported", self.HTTPMethod];
118 | }
119 |
120 | MPLog( @"urlString - %@", urlString);
121 | [aRequest setURL:[NSURL URLWithString:urlString]];
122 | self.urlRequest = aRequest;
123 |
124 | [parameterString release];
125 | [signatureParameter release];
126 | [aRequest release];
127 |
128 | return aRequest;
129 | }
130 |
131 | #pragma mark -
132 |
133 | - (void)addParameters:(NSArray *)inParameters {
134 | [self.parameters addObjectsFromArray:inParameters];
135 | }
136 |
137 | @end
138 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthURLResponse.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthURLResponse.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface MPOAuthURLResponse : NSObject {
13 | NSURLResponse *_urlResponse;
14 | NSDictionary *_oauthParameters;
15 | }
16 |
17 | @property (nonatomic, readonly, retain) NSURLResponse *urlResponse;
18 | @property (nonatomic, readonly, retain) NSDictionary *oauthParameters;
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/Source/Framework/MPOAuthURLResponse.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthURLResponse.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthURLResponse.h"
10 |
11 | @interface MPOAuthURLResponse ()
12 | @property (nonatomic, readwrite, retain) NSURLResponse *urlResponse;
13 | @property (nonatomic, readwrite, retain) NSDictionary *oauthParameters;
14 | @end
15 |
16 | @implementation MPOAuthURLResponse
17 |
18 | - (id)init {
19 | if ((self = [super init])) {
20 |
21 | }
22 | return self;
23 | }
24 |
25 | - (oneway void)dealloc {
26 | self.urlResponse = nil;
27 | self.oauthParameters = nil;
28 |
29 | [super dealloc];
30 | }
31 |
32 | @synthesize urlResponse = _urlResponse;
33 | @synthesize oauthParameters = _oauthParameters;
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/Source/Framework/MPURLRequestParameter.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPURLParameter.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface MPURLRequestParameter : NSObject {
13 | NSString *_name;
14 | NSString *_value;
15 | }
16 |
17 | @property (nonatomic, readwrite, copy) NSString *name;
18 | @property (nonatomic, readwrite, copy) NSString *value;
19 |
20 | + (NSArray *)parametersFromString:(NSString *)inString;
21 | + (NSArray *)parametersFromDictionary:(NSDictionary *)inDictionary;
22 | + (NSDictionary *)parameterDictionaryFromString:(NSString *)inString;
23 | + (NSString *)parameterStringForParameters:(NSArray *)inParameters;
24 | + (NSString *)parameterStringForDictionary:(NSDictionary *)inParameterDictionary;
25 |
26 | - (id)initWithName:(NSString *)inName andValue:(NSString *)inValue;
27 |
28 | - (NSString *)URLEncodedParameterString;
29 |
30 | @end
31 |
--------------------------------------------------------------------------------
/Source/Framework/MPURLRequestParameter.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPURLParameter.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPURLRequestParameter.h"
10 | #import "NSString+URLEscapingAdditions.h"
11 |
12 | @implementation MPURLRequestParameter
13 |
14 | + (NSArray *)parametersFromString:(NSString *)inString {
15 | NSMutableArray *foundParameters = [NSMutableArray arrayWithCapacity:10];
16 | NSScanner *parameterScanner = [[NSScanner alloc] initWithString:inString];
17 | NSString *name = nil;
18 | NSString *value = nil;
19 | MPURLRequestParameter *currentParameter = nil;
20 |
21 | while (![parameterScanner isAtEnd]) {
22 | name = nil;
23 | value = nil;
24 |
25 | [parameterScanner scanUpToString:@"=" intoString:&name];
26 | [parameterScanner scanString:@"=" intoString:NULL];
27 | [parameterScanner scanUpToString:@"&" intoString:&value];
28 | [parameterScanner scanString:@"&" intoString:NULL];
29 |
30 | currentParameter = [[MPURLRequestParameter alloc] init];
31 | currentParameter.name = name;
32 | currentParameter.value = [value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
33 |
34 | [foundParameters addObject:currentParameter];
35 |
36 | [currentParameter release];
37 | }
38 |
39 | [parameterScanner release];
40 |
41 | return foundParameters;
42 | }
43 |
44 | + (NSArray *)parametersFromDictionary:(NSDictionary *)inDictionary {
45 | NSMutableArray *parameterArray = [[NSMutableArray alloc] init];
46 | MPURLRequestParameter *aURLParameter = nil;
47 |
48 | for (NSString *aKey in [inDictionary allKeys]) {
49 | aURLParameter = [[MPURLRequestParameter alloc] init];
50 | aURLParameter.name = aKey;
51 | aURLParameter.value = [inDictionary objectForKey:aKey];
52 |
53 | [parameterArray addObject:aURLParameter];
54 | [aURLParameter release];
55 | }
56 |
57 | return [parameterArray autorelease];
58 | }
59 |
60 | + (NSDictionary *)parameterDictionaryFromString:(NSString *)inString {
61 | NSMutableDictionary *foundParameters = [NSMutableDictionary dictionaryWithCapacity:10];
62 | if (inString) {
63 | NSScanner *parameterScanner = [[NSScanner alloc] initWithString:inString];
64 | NSString *name = nil;
65 | NSString *value = nil;
66 |
67 | while (![parameterScanner isAtEnd]) {
68 | name = nil;
69 | value = nil;
70 |
71 | [parameterScanner scanUpToString:@"=" intoString:&name];
72 | [parameterScanner scanString:@"=" intoString:NULL];
73 | [parameterScanner scanUpToString:@"&" intoString:&value];
74 | [parameterScanner scanString:@"&" intoString:NULL];
75 |
76 | if (name && value) {
77 | [foundParameters setObject:[value stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] forKey:name];
78 | }
79 | }
80 |
81 | [parameterScanner release];
82 | }
83 | return foundParameters;
84 | }
85 |
86 | + (NSString *)parameterStringForParameters:(NSArray *)inParameters {
87 | NSMutableString *queryString = [[NSMutableString alloc] init];
88 | int i = 0;
89 | int parameterCount = [inParameters count];
90 | MPURLRequestParameter *aParameter = nil;
91 |
92 | for (; i < parameterCount; i++) {
93 | aParameter = [inParameters objectAtIndex:i];
94 | [queryString appendString:[aParameter URLEncodedParameterString]];
95 |
96 | if (i < parameterCount - 1) {
97 | [queryString appendString:@"&"];
98 | }
99 | }
100 |
101 | return [queryString autorelease];
102 | }
103 |
104 | + (NSString *)parameterStringForDictionary:(NSDictionary *)inParameterDictionary {
105 | NSArray *parameters = [self parametersFromDictionary:inParameterDictionary];
106 | NSString *queryString = [self parameterStringForParameters:parameters];
107 |
108 | return queryString;
109 | }
110 |
111 | #pragma mark -
112 |
113 | - (id)init {
114 | if ((self = [super init])) {
115 |
116 | }
117 | return self;
118 | }
119 |
120 | - (id)initWithName:(NSString *)inName andValue:(NSString *)inValue {
121 | if ((self = [super init])) {
122 | self.name = inName;
123 | self.value = inValue;
124 | }
125 | return self;
126 | }
127 |
128 | - (oneway void)dealloc {
129 | self.name = nil;
130 | self.value = nil;
131 |
132 | [super dealloc];
133 | }
134 |
135 | @synthesize name = _name;
136 | @synthesize value = _value;
137 |
138 | #pragma mark -
139 |
140 | - (NSString *)URLEncodedParameterString {
141 | return [NSString stringWithFormat:@"%@=%@", [self.name stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding], self.value ? [self.value stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding] : @""];
142 | }
143 |
144 | #pragma mark -
145 |
146 | - (NSComparisonResult)compare:(id)inObject {
147 | NSComparisonResult result = [self.name compare:[(MPURLRequestParameter *)inObject name]];
148 |
149 | if (result == NSOrderedSame) {
150 | result = [self.value compare:[(MPURLRequestParameter *)inObject value]];
151 | }
152 |
153 | return result;
154 | }
155 |
156 | - (NSString *)description {
157 | return [NSString stringWithFormat:@"<%@: %p %@>", NSStringFromClass([self class]), self, [self URLEncodedParameterString]];
158 | }
159 |
160 | @end
161 |
--------------------------------------------------------------------------------
/Source/Framework/MPWSLRDDiscoverer.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOWSLRDDiscoverer.h
3 | // MPWebServices
4 | //
5 | // Created by Karl Adam on 09.03.30.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @protocol MPWSLRDDiscovererDelegate;
12 |
13 | typedef enum {
14 | MPWSLRDDiscovererStateRequestingURI = 0,
15 | MPWSLRDDiscovererStateSearchingForLinkElements = 1,
16 | MPWSLRDDiscovererStateSearchingForLinkHeaders = 2,
17 | MPWSLRDDiscovererStateRequestingHostMeta = 3,
18 | MPWSLRDDiscovererStateSearchingHostMeta = 4,
19 | MPWSLRDDiscovererStateResourceLocated = 5,
20 | MPWSLRDDiscovererStateLookupFailured = 6
21 | } MPWSLRDDiscovererState;
22 |
23 | @interface MPWSLRDDiscoverer : NSObject {
24 | id _delegate;
25 | NSURL *_endpointURL;
26 | NSString *_soughtMIMEType;
27 | NSURLConnection *_urlConnection;
28 | NSURLResponse *_urlResponse;
29 | NSMutableData *_responseData;
30 | MPWSLRDDiscovererState _discoveryState;
31 | }
32 |
33 | @property (nonatomic, readonly, assign) id delegate;
34 | @property (nonatomic, readonly, assign) MPWSLRDDiscovererState discoveryState;
35 |
36 | - (void)locateResourceOfType:(NSString *)inMimeType fromURL:(NSURL *)inURL;
37 |
38 | @end
39 |
40 |
41 | @protocol MPWSLRDDiscovererDelegate
42 | - (void)locatedResourceOfType:(NSString *)inMimeType fromURL:(NSURL *)inEndpointURL atLocation:(NSURL *)inResourceURL;
43 | @end
44 |
--------------------------------------------------------------------------------
/Source/Framework/MPWSLRDDiscoverer.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPWSLRDDiscoverer.m
3 | // MPWSConnection
4 | //
5 | // Created by Karl Adam on 09.03.30.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPWSLRDDiscoverer.h"
10 |
11 | #define kMPWSLRDDiscovererExpectedHTTPHeader @"Link"
12 | #define kMPWSLRDDiscovererExpectedRelType @"describedby"
13 |
14 | @interface MPWSLRDDiscoverer ()
15 | @property (nonatomic, readwrite, retain) NSURL *endpointURL;
16 | @property (nonatomic, readwrite, retain) NSString *soughtType;
17 | @property (nonatomic, readwrite, retain) NSURLConnection *connection;
18 | @property (nonatomic, readwrite, retain) NSURLResponse *response;
19 | @property (nonatomic, readwrite, retain) NSMutableData *responseData;
20 |
21 | - (BOOL)_processResponseSearchingForLinkMarkup;
22 | - (BOOL)_processResponseSearchingForLinkHeaders;
23 | - (BOOL)_ignoreResponseAndLookupHostMeta;
24 | - (void)_foundResourceURL:(NSURL *)inURL forType:(NSString *)urlTypeSought;
25 |
26 | @end
27 |
28 | @implementation MPWSLRDDiscoverer
29 |
30 | - (id)init {
31 | if ((self = [super init])) {
32 |
33 | }
34 | return self;
35 | }
36 |
37 | - (oneway void)dealloc {
38 | self.endpointURL = nil;
39 | self.soughtType = nil;
40 | self.connection = nil;
41 | self.response = nil;
42 | self.responseData = nil;
43 |
44 | [super dealloc];
45 | }
46 |
47 | @synthesize delegate = _delegate;
48 | @synthesize endpointURL = _endpointURL;
49 | @synthesize soughtType = _soughtMIMEType;
50 | @synthesize connection = _urlConnection;
51 | @synthesize response = _urlResponse;
52 | @synthesize responseData = _responseData;
53 | @synthesize discoveryState = _discoveryState;
54 |
55 | #pragma mark -
56 |
57 | - (void)locateResourceOfType:(NSString *)inMimeType fromURL:(NSURL *)inURL {
58 | self.endpointURL = inURL;
59 | NSURLRequest *initialPageRequest = [NSURLRequest requestWithURL:inURL];
60 | NSURLConnection *urlConnection = [NSURLConnection connectionWithRequest:initialPageRequest delegate:self];
61 | self.connection = urlConnection;
62 | }
63 |
64 | - (BOOL)_processResponseSearchingForLinkMarkup {
65 | BOOL foundMatchingLink = NO;
66 | //TODO: Determe if type is html derivative and use libxml to derive the link elements from it
67 |
68 | return foundMatchingLink;
69 | }
70 |
71 | - (BOOL)_processResponseSearchingForLinkHeaders {
72 | BOOL foundMatchingLink = NO;
73 | NSDictionary *httpResponseHeaders = [(NSHTTPURLResponse *)self.response allHeaderFields];
74 | NSString *headerForTitle = [httpResponseHeaders objectForKey:kMPWSLRDDiscovererExpectedHTTPHeader];
75 | NSScanner *linkScanner = [NSScanner scannerWithString:headerForTitle];
76 | NSString *foundLink = nil;
77 | NSString *foundLinkRel = nil;
78 | NSString *foundLinkType = nil;
79 |
80 | while (![linkScanner isAtEnd]) {
81 | [linkScanner scanUpToString:@"<" intoString:NULL];
82 | [linkScanner scanUpToString:@">" intoString:&foundLink];
83 | [linkScanner scanString:@">" intoString:NULL];
84 |
85 | [linkScanner scanString:@"; " intoString:NULL];
86 | [linkScanner scanString:@"rel=\"" intoString:NULL];
87 | [linkScanner scanUpToString:@"\"" intoString:&foundLinkRel];
88 | [linkScanner scanString:@"\"" intoString:NULL];
89 | [linkScanner scanString:@"; " intoString:NULL];
90 |
91 | [linkScanner scanString:@"type=\"" intoString:NULL];
92 | [linkScanner scanUpToString:@"\"" intoString:&foundLinkType];
93 | [linkScanner scanString:@"\"" intoString:NULL];
94 |
95 | if ([foundLinkRel rangeOfString:kMPWSLRDDiscovererExpectedRelType].location != NSNotFound &&
96 | [foundLinkType isEqualToString:self.soughtType]) {
97 | NSURL *foundURL = [NSURL URLWithString:foundLink];
98 | [self _foundResourceURL:foundURL forType:self.soughtType];
99 | foundMatchingLink = YES;
100 | }
101 |
102 | if (![linkScanner isAtEnd]) {
103 | [linkScanner scanString:@";" intoString:NULL];
104 | }
105 | }
106 |
107 | return foundMatchingLink;
108 | }
109 |
110 | - (BOOL)_ignoreResponseAndLookupHostMeta {
111 | BOOL foundMatchingLink = NO;
112 | //TODO: Parse host-meta link templates
113 |
114 | return foundMatchingLink;
115 | }
116 |
117 | - (void)_foundResourceURL:(NSURL *)inURL forType:(NSString *)urlTypeSought {
118 | [self.delegate locatedResourceOfType:urlTypeSought fromURL:self.endpointURL atLocation:inURL];
119 | }
120 | #pragma mark - NSConnection Delegate Methods -
121 |
122 | - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse {
123 | return request;
124 | }
125 |
126 | - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
127 | self.responseData = [NSMutableData data];
128 | }
129 |
130 | - (void)connection:(NSURLConnection *)inConnection didReceiveData:(NSData *)inData {
131 | [self.responseData appendData:inData];
132 | }
133 |
134 | - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
135 | [self _processResponseSearchingForLinkMarkup];
136 | }
137 |
138 | @end
139 |
--------------------------------------------------------------------------------
/Source/Framework/MPWSXRDDocument.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPWSXRDDocument.h
3 | // MPWebServices
4 | //
5 | // Created by Karl Adam on 09.03.31.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface MPWSXRDDocument : NSObject {
13 | NSString *_subject;
14 | NSDate *_expirationDate;
15 | NSDictionary *_urlRelationships;
16 | }
17 |
18 | @property (nonatomic, readonly, retain) NSString *subject;
19 | @property (nonatomic, readonly, retain) NSDate *expirationDate;
20 | @property (nonatomic, readonly, retain) NSDictionary *urlRelationships;
21 |
22 | - (id)initFromURL:(NSURL *)inURL;
23 | - (id)iniWithString:(NSString *)inString;
24 | - (NSURL *)urlForRelationship:(NSString *)inRelationshipType;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/Source/Framework/MPWSXRDDocument.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPWSXRDDocument.m
3 | // MPWwbServices
4 | //
5 | // Created by Karl Adam on 09.03.31.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPWSXRDDocument.h"
10 | #import
11 | #import
12 | #import
13 | #import
14 |
15 | @interface MPWSXRDDocument ()
16 | @property (nonatomic, readwrite, retain) NSString *subject;
17 | @property (nonatomic, readwrite, retain) NSDate *expirationDate;
18 | @property (nonatomic, readwrite, retain) NSDictionary *urlRelationships;
19 |
20 | - (BOOL)_parseStringForContent:(NSString *)inString;
21 | @end
22 |
23 | @implementation MPWSXRDDocument
24 |
25 | - (id)initFromURL:(NSURL *)inURL {
26 | if ((self = [super init])) {
27 | }
28 | return self;
29 | }
30 |
31 | - (id)iniWithString:(NSString *)inString {
32 | if ((self = [super init])) {
33 | [self _parseStringForContent:inString];
34 | }
35 | return self;
36 | }
37 |
38 | - (oneway void)dealloc {
39 | self.subject = nil;
40 | self.expirationDate = nil;
41 | self.urlRelationships = nil;
42 |
43 | [super dealloc];
44 | }
45 |
46 | @synthesize subject = _subject;
47 | @synthesize expirationDate = _expirationDate;
48 | @synthesize urlRelationships = _urlRelationships;
49 |
50 | #pragma mark -
51 |
52 | - (BOOL)_parseStringForContent:(NSString *)inString {
53 | BOOL successfullyParsed = NO;
54 |
55 | xmlInitParser();
56 | const char *cStringForDoc = [inString UTF8String];
57 | xmlDocPtr xrdDocument = xmlParseMemory(cStringForDoc, strlen(cStringForDoc));
58 | if (xrdDocument) {
59 | // xmlNodePtr rootNode = xmlDocGetRootElement(xrdDocument);
60 | xmlXPathContextPtr xpathContext = xmlXPathNewContext(xrdDocument);
61 | xmlXPathObjectPtr xpathObject = NULL;
62 |
63 | xpathObject = xmlXPathEvalExpression((const xmlChar *)"/xrd[0]/subject", xpathContext);
64 | if (xpathObject) {
65 | xmlNodeSetPtr subjectNodes = xpathObject->nodesetval;
66 | int resultsCount = subjectNodes ? subjectNodes->nodeNr : 0;
67 | int i = 0;
68 |
69 | for ( ; i < resultsCount; i++) {
70 |
71 | }
72 | }
73 | xmlXPathFreeObject(xpathObject);
74 |
75 | xmlXPathFreeContext(xpathContext);
76 | xmlFreeDoc(xrdDocument);
77 | }
78 | xmlCleanupParser();
79 |
80 | return successfullyParsed;
81 | }
82 |
83 | - (NSURL *)urlForRelationship:(NSString *)inRelationshipType {
84 | NSURL *foundURL = [self.urlRelationships objectForKey:inRelationshipType];
85 |
86 | return foundURL;
87 | }
88 |
89 | @end
90 |
--------------------------------------------------------------------------------
/Source/Framework/NSString+URLEscapingAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+URLEscapingAdditions.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.07.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface NSString (MPURLEscapingAdditions)
13 |
14 | - (BOOL)isIPAddress;
15 | - (NSString *)stringByAddingURIPercentEscapesUsingEncoding:(NSStringEncoding)inEncoding;
16 |
17 | @end
18 |
19 | @interface NSURL (MPURLEscapingAdditions)
20 | - (NSString *)stringByAddingURIPercentEscapesUsingEncoding:(NSStringEncoding)inEncoding;
21 | @end
--------------------------------------------------------------------------------
/Source/Framework/NSString+URLEscapingAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+URLEscapingAdditions.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.07.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "NSString+URLEscapingAdditions.h"
10 |
11 |
12 | @implementation NSString (MPURLEscapingAdditions)
13 |
14 | - (BOOL)isIPAddress {
15 | BOOL isIPAddress = NO;
16 | NSArray *components = [self componentsSeparatedByString:@"."];
17 | NSCharacterSet *invalidCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"1234567890"] invertedSet];
18 |
19 | if ([components count] == 4) {
20 | NSString *part1 = [components objectAtIndex:0];
21 | NSString *part2 = [components objectAtIndex:1];
22 | NSString *part3 = [components objectAtIndex:2];
23 | NSString *part4 = [components objectAtIndex:3];
24 |
25 | if ([part1 rangeOfCharacterFromSet:invalidCharacters].location == NSNotFound &&
26 | [part2 rangeOfCharacterFromSet:invalidCharacters].location == NSNotFound &&
27 | [part3 rangeOfCharacterFromSet:invalidCharacters].location == NSNotFound &&
28 | [part4 rangeOfCharacterFromSet:invalidCharacters].location == NSNotFound ) {
29 |
30 | if ([part1 intValue] < 255 &&
31 | [part2 intValue] < 255 &&
32 | [part3 intValue] < 255 &&
33 | [part4 intValue] < 255) {
34 | isIPAddress = YES;
35 | }
36 | }
37 | }
38 |
39 | return isIPAddress;
40 | }
41 |
42 | - (NSString *)stringByAddingURIPercentEscapesUsingEncoding:(NSStringEncoding)inEncoding {
43 | NSString *escapedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
44 | (CFStringRef)self,
45 | NULL,
46 | (CFStringRef)@":/?=,!$&'()*+;[]@#",
47 | CFStringConvertNSStringEncodingToEncoding(inEncoding));
48 |
49 | return [escapedString autorelease];
50 | }
51 |
52 | @end
53 |
54 | @implementation NSURL (MPURLEscapingAdditions)
55 |
56 | - (NSString *)stringByAddingURIPercentEscapesUsingEncoding:(NSStringEncoding)inEncoding {
57 | return [[self absoluteString] stringByAddingURIPercentEscapesUsingEncoding:inEncoding];
58 | }
59 |
60 | @end
61 |
--------------------------------------------------------------------------------
/Source/Framework/NSURL+MPURLParameterAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSURL+MPURLParameterAdditions.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.08.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface NSURL (MPURLParameterAdditions)
13 |
14 | - (NSURL *)urlByAddingParameters:(NSArray *)inParameters;
15 | - (NSURL *)urlByAddingParameterDictionary:(NSDictionary *)inParameters;
16 | - (NSURL *)urlByRemovingQuery;
17 | - (NSString *)absoluteNormalizedString;
18 |
19 | - (BOOL)domainMatches:(NSString *)inString;
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/Source/Framework/NSURL+MPURLParameterAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSURL+MPURLParameterAdditions.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.08.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "NSURL+MPURLParameterAdditions.h"
10 | #import "MPURLRequestParameter.h"
11 | #import "NSString+URLEscapingAdditions.h"
12 |
13 | @implementation NSURL (MPURLParameterAdditions)
14 |
15 | - (NSURL *)urlByAddingParameters:(NSArray *)inParameters {
16 | NSMutableArray *parameters = [[NSMutableArray alloc] init];
17 | NSString *queryString = [self query];
18 | NSString *absoluteString = [self absoluteString];
19 | NSRange parameterRange = [absoluteString rangeOfString:@"?"];
20 |
21 | if (parameterRange.location != NSNotFound) {
22 | parameterRange.length = [absoluteString length] - parameterRange.location;
23 | [parameters addObjectsFromArray:[MPURLRequestParameter parametersFromString:queryString]];
24 | absoluteString = [absoluteString substringToIndex:parameterRange.location];
25 | }
26 |
27 | [parameters addObjectsFromArray:inParameters];
28 |
29 | return [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", absoluteString, [MPURLRequestParameter parameterStringForParameters:[parameters autorelease]]]];
30 | }
31 |
32 | - (NSURL *)urlByAddingParameterDictionary:(NSDictionary *)inParameterDictionary {
33 | NSMutableDictionary *parameterDictionary = [inParameterDictionary mutableCopy];
34 | NSString *queryString = [self query];
35 | NSString *absoluteString = [self absoluteString];
36 | NSRange parameterRange = [absoluteString rangeOfString:@"?"];
37 | NSURL *composedURL = self;
38 |
39 | if (parameterRange.location != NSNotFound) {
40 | parameterRange.length = [absoluteString length] - parameterRange.location;
41 |
42 | //[parameterDictionary addEntriesFromDictionary:inParameterDictionary];
43 | [parameterDictionary addEntriesFromDictionary:[MPURLRequestParameter parameterDictionaryFromString:queryString]];
44 |
45 | composedURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", [absoluteString substringToIndex:parameterRange.location], [MPURLRequestParameter parameterStringForDictionary:parameterDictionary]]];
46 | } else if ([parameterDictionary count]) {
47 | composedURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@", absoluteString, [MPURLRequestParameter parameterStringForDictionary:parameterDictionary]]];
48 | }
49 |
50 | [parameterDictionary release];
51 |
52 | return composedURL;
53 | }
54 |
55 | - (NSURL *)urlByRemovingQuery {
56 | NSURL *composedURL = self;
57 | NSString *absoluteString = [self absoluteString];
58 | NSRange queryRange = [absoluteString rangeOfString:@"?"];
59 |
60 | if (queryRange.location != NSNotFound) {
61 | NSString *urlSansQuery = [absoluteString substringToIndex:queryRange.location];
62 | composedURL = [NSURL URLWithString:urlSansQuery];
63 | }
64 |
65 | return composedURL;
66 | }
67 |
68 | - (NSString *)absoluteNormalizedString {
69 | NSString *normalizedString = [self absoluteString];
70 |
71 | if ([[self path] length] == 0 && [[self query] length] == 0) {
72 | normalizedString = [NSString stringWithFormat:@"%@/", [self absoluteString]];
73 | }
74 |
75 | return normalizedString;
76 | }
77 |
78 | - (BOOL)domainMatches:(NSString *)inString {
79 | BOOL matches = NO;
80 |
81 | NSString *domain = [self host];
82 | matches = [domain isIPAddress] && [domain isEqualToString:inString];
83 |
84 | int domainLength = [domain length];
85 | int requestedDomainLength = [inString length];
86 |
87 | if (!matches) {
88 | if (domainLength > requestedDomainLength) {
89 | matches = [domain rangeOfString:inString].location == (domainLength - requestedDomainLength);
90 | } else if (domainLength == (requestedDomainLength - 1)) {
91 | matches = ([inString compare:domain options:NSCaseInsensitiveSearch range:NSMakeRange(1, domainLength)] == NSOrderedSame);
92 | }
93 | }
94 |
95 | return matches;
96 | }
97 |
98 | @end
99 |
--------------------------------------------------------------------------------
/Source/Framework/NSURLResponse+Encoding.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSURL+MPEncodingAdditions.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface NSURLResponse (EncodingAdditions)
13 | - (NSStringEncoding)encoding;
14 | @end
15 |
--------------------------------------------------------------------------------
/Source/Framework/NSURLResponse+Encoding.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSURL+MPEncodingAdditions.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "NSURLResponse+Encoding.h"
10 |
11 |
12 | @implementation NSURLResponse (EncodingAdditions)
13 |
14 | - (NSStringEncoding)encoding {
15 | NSStringEncoding encoding = NSUTF8StringEncoding;
16 |
17 | if ([self textEncodingName]) {
18 | CFStringEncoding cfStringEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)[self textEncodingName]);
19 | if (cfStringEncoding != kCFStringEncodingInvalidId) {
20 | encoding = CFStringConvertEncodingToNSStringEncoding(cfStringEncoding);
21 | }
22 | }
23 |
24 | return encoding;
25 | }
26 |
27 | @end
28 |
--------------------------------------------------------------------------------
/Source/Mobile Test App/MPOAuthMobileAppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthMobileAppDelegate.h
3 | // MPOAuthMobile
4 | //
5 | // Created by Karl Adam on 08.12.14.
6 | // Copyright matrixPointer 2008. All rights reserved.
7 | //
8 |
9 | #import
10 | //#import "MPOAuthAPI.h"
11 |
12 | @interface MPOAuthMobileAppDelegate : NSObject {
13 | UIWindow *window_;
14 | UINavigationController *navigationController_;
15 | NSString *oauthVerifier_;
16 | }
17 |
18 | @property (nonatomic, readwrite, retain) IBOutlet UIWindow *window;
19 | @property (nonatomic, readwrite, retain) IBOutlet UINavigationController *navigationController;
20 | @property (nonatomic, readwrite, copy) NSString *oauthVerifier;
21 | @end
22 |
23 |
--------------------------------------------------------------------------------
/Source/Mobile Test App/MPOAuthMobileAppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthMobileAppDelegate.m
3 | // MPOAuthMobile
4 | //
5 | // Created by Karl Adam on 08.12.14.
6 | // Copyright matrixPointer 2008. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthAuthenticationMethodOAuth.h"
10 | #import "MPOAuthMobileAppDelegate.h"
11 | #import "RootViewController.h"
12 |
13 | #import "MPURLRequestParameter.h"
14 |
15 | @implementation MPOAuthMobileAppDelegate
16 |
17 | @synthesize window = window_;
18 | @synthesize navigationController = navigationController_;
19 | @synthesize oauthVerifier = oauthVerifier_;
20 |
21 | - (void)applicationDidFinishLaunching:(UIApplication *)application {
22 |
23 | // Configure and show the window
24 | [window_ addSubview:[navigationController_ view]];
25 | [window_ makeKeyAndVisible];
26 | }
27 |
28 |
29 | - (void)applicationWillTerminate:(UIApplication *)application {
30 | // Save data if appropriate
31 | }
32 |
33 |
34 | - (void)dealloc {
35 | self.navigationController = nil;
36 | self.window = nil;
37 | [super dealloc];
38 | }
39 |
40 | #pragma mark - MPOAuthAPIDelegate Methods -
41 |
42 | - (NSURL *)callbackURLForCompletedUserAuthorization {
43 | // The x-com-mpoauth-mobile URI is a claimed URI Type
44 | // check Info.plist for details
45 | return [NSURL URLWithString:@"x-com-mpoauth-mobile://success"];
46 | }
47 |
48 | - (NSString *)oauthVerifierForCompletedUserAuthorization {
49 | return oauthVerifier_;
50 | }
51 |
52 | - (BOOL)automaticallyRequestAuthenticationFromURL:(NSURL *)inAuthURL withCallbackURL:(NSURL *)inCallbackURL {
53 | return YES;
54 | }
55 |
56 | - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
57 | // the url is the callback url with the query string including oauth_token and oauth_verifier in 1.0a
58 | if ([[url host] isEqualToString:@"success"] && [url query].length > 0) {
59 | NSDictionary *oauthParameters = [MPURLRequestParameter parameterDictionaryFromString:[url query]];
60 | oauthVerifier_ = [oauthParameters objectForKey:@"oauth_verifier"];
61 | }
62 |
63 | return YES;
64 | }
65 |
66 | @end
67 |
--------------------------------------------------------------------------------
/Source/Mobile Test App/RootViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // RootViewController.h
3 | // MPOAuthMobile
4 | //
5 | // Created by Karl Adam on 08.12.14.
6 | // Copyright matrixPointer 2008. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @class MPOAuthAPI;
12 |
13 | @interface RootViewController : UIViewController {
14 | MPOAuthAPI *_oauthAPI;
15 | UITextField *methodInput;
16 | UITextField *parametersInput;
17 | UITextView *textOutput;
18 | }
19 |
20 | @property (nonatomic, retain) IBOutlet UITextField *methodInput;
21 | @property (nonatomic, retain) IBOutlet UITextField *parametersInput;
22 |
23 | - (IBAction)clearCredentials;
24 | - (IBAction)reauthenticate;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/Source/Mobile Test App/RootViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // RootViewController.m
3 | // MPOAuthMobile
4 | //
5 | // Created by Karl Adam on 08.12.14.
6 | // Copyright matrixPointer 2008. All rights reserved.
7 | //
8 |
9 | #import "RootViewController.h"
10 | #import "MPOAuthMobileAppDelegate.h"
11 | #import "MPOAuthAPI.h"
12 | #import "MPOAuthAuthenticationMethodOAuth.h"
13 | #import "MPURLRequestParameter.h"
14 |
15 | #define kConsumerKey @"key"
16 | #define kConsumerSecret @"secret"
17 |
18 | @implementation RootViewController
19 |
20 | - (void)dealloc {
21 | [super dealloc];
22 | }
23 |
24 | @synthesize methodInput;
25 | @synthesize parametersInput;
26 |
27 | #pragma mark -
28 |
29 | - (void)viewDidLoad {
30 | [super viewDidLoad];
31 | [self.navigationItem setPrompt:@"Performing Request Token Request"];
32 | [self.navigationItem setTitle:@"OAuth Test"];
33 | [methodInput addTarget:self action:@selector(methodEntered:) forControlEvents:UIControlEventEditingDidEndOnExit];
34 |
35 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestTokenReceived:) name:MPOAuthNotificationRequestTokenReceived object:nil];
36 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessTokenReceived:) name:MPOAuthNotificationAccessTokenReceived object:nil];
37 |
38 | }
39 |
40 | - (void)viewDidAppear:(BOOL)animated {
41 | if (!_oauthAPI) {
42 | NSDictionary *credentials = [NSDictionary dictionaryWithObjectsAndKeys: kConsumerKey, kMPOAuthCredentialConsumerKey,
43 | kConsumerSecret, kMPOAuthCredentialConsumerSecret,
44 | nil];
45 | _oauthAPI = [[MPOAuthAPI alloc] initWithCredentials:credentials
46 | authenticationURL:[NSURL URLWithString:@"https://twitter.com/oauth/"]
47 | andBaseURL:[NSURL URLWithString:@"https://twitter.com/"]];
48 |
49 | if ([[_oauthAPI authenticationMethod] respondsToSelector:@selector(setDelegate:)]) {
50 | [(MPOAuthAuthenticationMethodOAuth *)[_oauthAPI authenticationMethod] setDelegate:(id )[UIApplication sharedApplication].delegate];
51 | }
52 | } else {
53 | [_oauthAPI authenticate];
54 | }
55 | }
56 |
57 | - (void)requestTokenReceived:(NSNotification *)inNotification {
58 | [self.navigationItem setPrompt:@"Awaiting User Authentication"];
59 | }
60 |
61 | - (void)accessTokenReceived:(NSNotification *)inNotification {
62 | [self.navigationItem setPrompt:@"Access Token Received"];
63 |
64 | NSData *downloadedData = [_oauthAPI dataForMethod:@"/statuses/friends_timeline.xml"];
65 | NSLog(@"downloadedData of size - %d", [downloadedData length]);
66 | }
67 |
68 | - (void)errorOccurred:(NSNotification *)inNotification {
69 | [self.navigationItem setPrompt:@"Error Occurred"];
70 | textOutput.text = [[inNotification userInfo] objectForKey:@"oauth_problem"];
71 | }
72 |
73 | - (void)_methodLoadedFromURL:(NSURL *)inURL withResponseString:(NSString *)inString {
74 | textOutput.text = inString;
75 | }
76 |
77 | - (void)methodEntered:(UITextField *)aTextField {
78 | NSString *method = methodInput.text;
79 | NSString *paramsString = parametersInput.text;
80 |
81 | NSArray *params = nil;
82 | if (paramsString.length > 0) {
83 | params = [MPURLRequestParameter parametersFromString:paramsString];
84 | }
85 |
86 | [_oauthAPI performMethod:method atURL:_oauthAPI.baseURL withParameters:params withTarget:self andAction:@selector(_methodLoadedFromURL:withResponseString:)];
87 | }
88 |
89 | - (void)clearCredentials {
90 | [self.navigationItem setPrompt:@"Credentials Cleared"];
91 | textOutput.text = @"";
92 | [_oauthAPI discardCredentials];
93 | }
94 |
95 | - (void)reauthenticate {
96 | [self.navigationItem setPrompt:@"Reauthenticating User"];
97 | textOutput.text = @"";
98 | [_oauthAPI authenticate];
99 | }
100 |
101 | @end
102 |
103 |
--------------------------------------------------------------------------------
/Source/Mobile Test App/UserAuthViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // UserAuthViewController.h
3 | // MPOAuthMobile
4 | //
5 | // Created by Karl Adam on 09.02.03.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface UserAuthViewController : UIViewController {
13 | IBOutlet UIWebView *webview;
14 | NSURL *_userAuthURL;
15 | }
16 |
17 | @property (nonatomic, readwrite, retain) NSURL *userAuthURL;
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/Source/Mobile Test App/UserAuthViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // UserAuthViewController.m
3 | // MPOAuthMobile
4 | //
5 | // Created by Karl Adam on 09.02.03.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "UserAuthViewController.h"
10 | #import "MPOAuthAPI.h"
11 | #import "MPOAuthAuthenticationMethodOAuth.h"
12 |
13 | @implementation UserAuthViewController
14 |
15 | - (id)initWithURL:(NSURL *)inURL {
16 | if ((self = [super initWithNibName:@"UserAuthViewController" bundle:nil])) {
17 | self.title = @"User Auth";
18 | self.navigationItem.prompt = @"Request Authorization for this application";
19 | self.userAuthURL = inURL;
20 | }
21 |
22 | return self;
23 | }
24 |
25 | - (void)dealloc {
26 | self.userAuthURL = nil;
27 |
28 | [super dealloc];
29 | }
30 |
31 | @synthesize userAuthURL = _userAuthURL;
32 |
33 | - (void)didReceiveMemoryWarning {
34 | [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
35 | // Release anything that's not essential, such as cached data
36 | }
37 |
38 | - (void)viewDidLoad {
39 | [super viewDidLoad];
40 | [webview setDelegate:self];
41 | [webview loadRequest:[NSURLRequest requestWithURL:self.userAuthURL]];
42 | }
43 |
44 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
45 | return YES;
46 | }
47 |
48 | #pragma mark - UIWebView Delegate Methods -
49 |
50 | - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
51 | // this is a ghetto way to handle this, but it's for when you must use http:// URIs
52 | // so that this demo will work correctly, this is an example, DONT.BE.GHETTO
53 | NSURL *userAuthURL = [(id )[UIApplication sharedApplication].delegate callbackURLForCompletedUserAuthorization];
54 | if ([request.URL isEqual:userAuthURL]) {
55 | [[self navigationController] popViewControllerAnimated:YES];
56 | return NO;
57 | }
58 |
59 | return YES;
60 | }
61 |
62 |
63 | @end
64 |
--------------------------------------------------------------------------------
/Source/Mobile Test App/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // MPOAuthMobile
4 | //
5 | // Created by Karl Adam on 08.12.14.
6 | // Copyright matrixPointer 2008. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | int main(int argc, char *argv[]) {
12 |
13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
14 | int retVal = UIApplicationMain(argc, argv, nil, nil);
15 | [pool release];
16 | return retVal;
17 | }
18 |
--------------------------------------------------------------------------------
/Source/Test App/OAuthClientController.h:
--------------------------------------------------------------------------------
1 | //
2 | // OAuthClientController.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @class MPOAuthAPI;
13 |
14 | @interface OAuthClientController : NSObject {
15 | IBOutlet NSTextField *baseURLField;
16 | IBOutlet NSTextField *authenticationURLField;
17 | IBOutlet NSTextField *consumerKeyField;
18 | IBOutlet NSTextField *consumerSecretField;
19 | IBOutlet NSButton *authenticationButton;
20 | IBOutlet NSProgressIndicator *progressIndicator;
21 | IBOutlet NSTextField *methodField;
22 | IBOutlet NSTextField *requestBodyField;
23 | IBOutlet NSTextView *responseBodyView;
24 | MPOAuthAPI *_oauthAPI;
25 | }
26 |
27 | - (IBAction)performAuthentication:(id)sender;
28 | - (IBAction)performMethod:(id)sender;
29 |
30 | @end
31 |
--------------------------------------------------------------------------------
/Source/Test App/OAuthClientController.m:
--------------------------------------------------------------------------------
1 | //
2 | // OAuthClientController.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "OAuthClientController.h"
10 |
11 | @implementation OAuthClientController
12 |
13 | - (id)init {
14 | if ((self = [super init])) {
15 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestTokenReceived:) name:MPOAuthNotificationRequestTokenReceived object:nil];
16 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessTokenReceived:) name:MPOAuthNotificationAccessTokenReceived object:nil];
17 | }
18 | return self;
19 | }
20 |
21 | - (oneway void)dealloc {
22 | [_oauthAPI release];
23 |
24 | [super dealloc];
25 | }
26 |
27 | - (void)awakeFromNib {
28 | if (_oauthAPI) {
29 | [progressIndicator setHidden:NO];
30 | [progressIndicator startAnimation:self];
31 | }
32 | }
33 |
34 | - (void)requestTokenReceived:(NSNotification *)inNotification {
35 | [progressIndicator stopAnimation:self];
36 | [authenticationButton setTitle:@"Request User Access"];
37 | }
38 |
39 | - (void)accessTokenReceived:(NSNotification *)inNotification {
40 | [progressIndicator stopAnimation:self];
41 | [authenticationButton setTitle:@"Access Token Acquired"];
42 | }
43 |
44 | - (IBAction)performAuthentication:(id)sender {
45 | if (!_oauthAPI) {
46 | NSDictionary *credentials = [NSDictionary dictionaryWithObjectsAndKeys: [consumerKeyField stringValue], kMPOAuthCredentialConsumerKey,
47 | [consumerSecretField stringValue], kMPOAuthCredentialConsumerSecret,
48 | nil];
49 | _oauthAPI = [[MPOAuthAPI alloc] initWithCredentials:credentials
50 | authenticationURL:[NSURL URLWithString:[authenticationURLField stringValue]]
51 | andBaseURL:[NSURL URLWithString:[baseURLField stringValue]]];
52 | } else {
53 | [_oauthAPI authenticate];
54 | }
55 | }
56 |
57 | - (IBAction)performMethod:(id)sender {
58 | [_oauthAPI performMethod:[methodField stringValue] withTarget:self andAction:@selector(performedMethodLoadForURL:withResponseBody:)];
59 | }
60 |
61 | - (void)performedMethodLoadForURL:(NSURL *)inMethod withResponseBody:(NSString *)inResponseBody {
62 | [responseBodyView setString:inResponseBody];
63 | }
64 |
65 | @end
66 |
--------------------------------------------------------------------------------
/Source/Test App/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.05.
6 | // Copyright matrixPointer 2008. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | int main(int argc, char *argv[])
12 | {
13 | return NSApplicationMain(argc, (const char **) argv);
14 | }
15 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPOAuthAPIRequestLoaderTests.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAPIRequestLoaderTests.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface MPOAuthAPIRequestLoaderTests : SenTestCase {
13 | NSTask *server;
14 | }
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPOAuthAPIRequestLoaderTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthAPIRequestLoaderTests.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | // Adapted entirely from Jon Crosby's OAuthConsumer Test Suite OADataFetcherTest
10 |
11 | #import "MPOAuthAPIRequestLoaderTests.h"
12 | #import "MPOAuthCredentialConcreteStore.h"
13 | #import "MPOAuthAPI.h"
14 | #import "MPOAuthAPIRequestLoader.h"
15 | #import "MPOAuthURLRequest.h"
16 |
17 | @implementation MPOAuthAPIRequestLoaderTests
18 |
19 | - (void)setUp {
20 | NSString *currentDir = [[NSFileManager defaultManager] currentDirectoryPath];
21 | NSString *serverPath = [currentDir stringByAppendingPathComponent:@"Source/Unit Tests/OATestServer.rb"];
22 |
23 | server = [[NSTask alloc] init];
24 | [server setArguments:[NSArray arrayWithObject:serverPath]];
25 | [server setLaunchPath:@"/usr/bin/ruby"];
26 | [server launch];
27 | sleep(2); // let the server get ready to respond
28 |
29 | // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessTokenReceived:) name:MPOAuthNotificationAccessTokenReceived object:nil];
30 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestTokenReceived:) name:MPOAuthNotificationRequestTokenReceived object:nil];
31 | }
32 |
33 | - (void)tearDown {
34 | [server terminate];
35 | }
36 |
37 | - (void)testFetchData {
38 | NSDictionary *credentials = [NSDictionary dictionaryWithObjectsAndKeys: @"dpf43f3p2l4k3l03", kMPOAuthCredentialConsumerKey,
39 | @"kd94hf93k423kf44", kMPOAuthCredentialConsumerSecret,
40 | nil];
41 | NSURL *url = [NSURL URLWithString:@"http://localhost:4567/request_token"];
42 | MPOAuthCredentialConcreteStore *credentialStore = [[MPOAuthCredentialConcreteStore alloc] initWithCredentials:credentials forBaseURL:url withAuthenticationURL:url];
43 | credentialStore.signatureMethod = @"PLAINTEXT";
44 |
45 | MPOAuthURLRequest *urlRequest = [[MPOAuthURLRequest alloc] initWithURL:url andParameters:nil];
46 | [urlRequest setHTTPMethod:@"POST"];
47 | MPOAuthAPIRequestLoader *requestLoader = [[MPOAuthAPIRequestLoader alloc] initWithRequest:urlRequest];
48 | requestLoader.credentials = credentialStore;
49 | [requestLoader loadSynchronously:YES];
50 | }
51 |
52 | - (void)requestTokenReceived:(NSNotification *)inNotification {
53 | NSString *token = [[inNotification userInfo] objectForKey:@"oauth_token"];
54 | NSString *tokenSecret = [[inNotification userInfo] objectForKey:@"oauth_token_secret"];
55 |
56 | STAssertEqualObjects(token, @"nnch734d00sl2jdk", @"Expected Token Not Found");
57 | STAssertEqualObjects(tokenSecret, @"pfkkdhi9sl3r4s00", @"Expected Token Secret Not Found");
58 | }
59 |
60 | //- (void)accessTokenReceived:(NSNotification *)inNotification {
61 | //
62 | //}
63 |
64 | @end
65 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPOAuthCredentialConcreteStoreKeychainTests.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthCredentialConcreteStoreKeychainTests.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import "MPOAuthCredentialConcreteStore.h"
12 | #import "MPOAuthCredentialConcreteStore+KeychainAdditions.h"
13 |
14 | @interface MPOAuthCredentialConcreteStoreKeychainTests : SenTestCase {
15 | MPOAuthCredentialConcreteStore *store_;
16 | }
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPOAuthCredentialConcreteStoreKeychainTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthCredentialConcreteStoreKeychainTests.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthCredentialConcreteStoreKeychainTests.h"
10 |
11 |
12 | @implementation MPOAuthCredentialConcreteStoreKeychainTests
13 |
14 | - (void)setUp {
15 | store_ = [[MPOAuthCredentialConcreteStore alloc] initWithCredentials:nil forBaseURL:[NSURL URLWithString:@"http://example.com/oauth"]];
16 | }
17 |
18 | - (void)tearDown {
19 | [store_ release];
20 | store_ = nil;
21 | }
22 |
23 | - (void)testWritingToAndReadingFromKeychain {
24 | NSString *testValue = [store_ findValueFromKeychainUsingName:@"test_name"];
25 | STAssertNil(testValue, @"The value read from the keychain for \"test_name\" should start as nil");
26 |
27 | [store_ addToKeychainUsingName:@"test_name" andValue:@"test_value"];
28 | NSString *savedValue = [store_ findValueFromKeychainUsingName:@"test_name"];
29 | STAssertEqualObjects(savedValue, @"test_value", @"The value read from the keychain \"%@\" was different from the one written to the keychain: %@", savedValue, @"test_value");
30 |
31 |
32 | [store_ addToKeychainUsingName:@"test_name" andValue:@"test_value2"];
33 | NSString *savedValue2 = [store_ findValueFromKeychainUsingName:@"test_name"];
34 | STAssertEqualObjects(savedValue2, @"test_value2", @"The value read from the keychain \"%@\" was different from the one written to the keychain \"%@\" to overwrite \"%@\"", savedValue, @"test_value2", @"test_value");
35 |
36 | [store_ removeValueFromKeychainUsingName:@"test_name"];
37 | NSString *deletedValue = [store_ findValueFromKeychainUsingName:@"test_name"];
38 | STAssertNil(deletedValue, @"The value read from the keychain for \"test_name\" should now be nil");
39 | }
40 |
41 | @end
42 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPOAuthParameterFactoryTests.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthParameterFactoryTests.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MPOAuthParameterFactory.h"
11 |
12 | @interface MPOAuthParameterFactoryTests : SenTestCase {
13 | id _factory;
14 | }
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPOAuthParameterFactoryTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthParameterFactoryTests.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthParameterFactoryTests.h"
10 | #import "MPOAuthCredentialConcreteStore.h"
11 | #import "MPURLRequestParameter.h"
12 |
13 | @implementation MPOAuthParameterFactoryTests
14 |
15 | - (void)setUp {
16 | _factory = [[MPOAuthCredentialConcreteStore alloc] init];
17 | }
18 |
19 | - (void)testNonceGeneration {
20 | MPURLRequestParameter *nonceParameter = [_factory oauthNonceParameter];
21 | STAssertNotNil(nonceParameter, @"A Nonce needs to be successfully generated");
22 | }
23 |
24 | - (void)testOAuthVersion {
25 | MPURLRequestParameter *versionParameter = [_factory oauthVersionParameter];
26 | STAssertEqualObjects(versionParameter.value, @"1.0", @"OAuth version 1.0 is the only supported version of OAuth currently" );
27 | }
28 |
29 |
30 | @end
31 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPOAuthSignatureParameterTests.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthSignatureParameterTests.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MPOAuthSignatureParameter.h"
11 |
12 | @interface MPOAuthSignatureParameterTests : SenTestCase {
13 | MPOAuthSignatureParameter *_signatureParameter;
14 | }
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPOAuthSignatureParameterTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthSignatureParameterTests.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthSignatureParameterTests.h"
10 | #import "MPOAuthURLRequest.h"
11 | #import "MPOAuthCredentialConcreteStore.h"
12 | #import "NSString+URLEscapingAdditions.h"
13 |
14 | @implementation MPOAuthSignatureParameterTests
15 |
16 | - (void)testPlainTextSignature {
17 | _signatureParameter = [[MPOAuthSignatureParameter alloc] initWithText:@"abcdefg" andSecret:@"123456789" forRequest:nil usingMethod:kMPOAuthSignatureMethodPlaintext];
18 |
19 | STAssertEqualObjects(_signatureParameter.value, @"123456789", @"The plain text signature method failed, the expected value was 123456789");
20 | [_signatureParameter release];
21 | _signatureParameter = nil;
22 | }
23 |
24 |
25 |
26 | - (void)testHMACSHA1Signature {
27 | NSMutableArray *parameters = [NSMutableArray arrayWithObject:[[[MPURLRequestParameter alloc] initWithName:@"file" andValue:@"vacation.jpg"] autorelease]];
28 | MPOAuthURLRequest *request = [[MPOAuthURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://photots.example.net/photos"]
29 | andParameters:parameters];
30 |
31 | NSDictionary *credentialsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"abcdefghijklmnopqestuvwxyz", kMPOAuthCredentialConsumerKey, nil];
32 | MPOAuthCredentialConcreteStore *mockCredentials = [[MPOAuthCredentialConcreteStore alloc] initWithCredentials:credentialsDictionary forBaseURL:nil];
33 | mockCredentials.signatureMethod = @"HMAC-SHA1";
34 |
35 | [parameters addObjectsFromArray:[mockCredentials oauthParameters]];
36 | [parameters sortUsingSelector:@selector(compare:)];
37 |
38 | MPURLRequestParameter *nonce = [parameters objectAtIndex:2];
39 | MPURLRequestParameter *timestamp = [parameters objectAtIndex:4];
40 |
41 | STAssertEqualObjects( nonce.name, @"oauth_nonce", @"This is not the nonce you're looking for, it's %@", nonce.name);
42 | STAssertEqualObjects( timestamp.name, @"oauth_timestamp", @"This is not the timestamp you're looking for, it's %@", timestamp.name);
43 |
44 | [nonce setValue:@"A0652B19-B977-45F1-A0B9-7C8621F95871"]; // set an explicit nonce
45 | [timestamp setValue:@"0"]; // set timestamp to 0
46 |
47 | _signatureParameter = [[MPOAuthSignatureParameter alloc] initWithText:[MPURLRequestParameter parameterStringForParameters:parameters] andSecret:@"123456789" forRequest:request usingMethod:kMPOAuthSignatureMethodHMACSHA1];
48 |
49 | STAssertEqualObjects(_signatureParameter.value, @"9WSQnB6gafEmHUlzF0cLtN0Tfvk=", @"The plain text signature method failed, the expected value was \"/AvKxaXD0WjtRZc8G6H9ENWTX5Q=\"");
50 |
51 | [mockCredentials release];
52 | [_signatureParameter release];
53 | _signatureParameter = nil;
54 | }
55 |
56 | - (void)testHMACSHA1Signature_Core92 {
57 | STAssertEqualObjects([MPOAuthSignatureParameter HMAC_SHA1SignatureForText:@"bs" usingSecret:@"cs&"],
58 | @"egQqG5AJep5sJ7anhXju1unge2I=",
59 | @"Generated HMAC_SHA1 Signature is incorrect, Core 9.2");
60 |
61 | STAssertEqualObjects([MPOAuthSignatureParameter HMAC_SHA1SignatureForText:@"bs" usingSecret:@"cs&ts"],
62 | @"VZVjXceV7JgPq/dOTnNmEfO0Fv8=",
63 | @"Generated HMAC_SHA1 Signature is incorrect, Core 9.2");
64 |
65 | STAssertEqualObjects([MPOAuthSignatureParameter HMAC_SHA1SignatureForText:@"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal" usingSecret:@"kd94hf93k423kf44&pfkkdhi9sl3r4s00"],
66 | @"tR3+Ty81lMeYAr/Fid0kMTYa/WM=",
67 | @"Generated HMAC_SHA1 Signature is incorrect, Core 9.2");
68 |
69 | }
70 |
71 | - (void)testURIEscapedGeneratedSignatures_Core941 {
72 | NSDictionary *credentialsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"abcdefghijklmnopqestuvwxyz", kMPOAuthCredentialConsumerKey,
73 | @"djr9rjt0jd78jf88", kMPOAuthCredentialConsumerSecret, nil];
74 | MPOAuthCredentialConcreteStore *mockCredentials = [[MPOAuthCredentialConcreteStore alloc] initWithCredentials:credentialsDictionary forBaseURL:nil];
75 | mockCredentials.signatureMethod = @"PLAINTEXT";
76 |
77 | mockCredentials.requestToken = @"empty";
78 | mockCredentials.requestTokenSecret = @"";
79 | STAssertEqualObjects([mockCredentials.signingKey stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding], @"djr9rjt0jd78jf88%26", @"Generated Signature does not conform to OAuth Core 9.4.1");
80 |
81 |
82 | mockCredentials.requestTokenSecret = @"jjd999tj88uiths3";
83 | STAssertEqualObjects([mockCredentials.signingKey stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding], @"djr9rjt0jd78jf88%26jjd999tj88uiths3", @"Generated Signature does not conform to OAuth Core 9.4.1");
84 |
85 | mockCredentials.requestTokenSecret = @"jjd99$tj88uiths3";
86 | STAssertEqualObjects([mockCredentials.signingKey stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding], @"djr9rjt0jd78jf88%26jjd99%2524tj88uiths3", @"Generated Signature does not conform to OAuth Core 9.4.1");
87 |
88 | mockCredentials.signatureMethod = @"HMAC-SHA1";
89 | mockCredentials.requestTokenSecret = @"";
90 | STAssertEqualObjects(mockCredentials.signingKey, @"djr9rjt0jd78jf88&", @"Generated Signature does not conform to OAuth Core 9.4.1");
91 |
92 | mockCredentials.requestTokenSecret = @"jjd999tj88uiths3";
93 | STAssertEqualObjects(mockCredentials.signingKey, @"djr9rjt0jd78jf88&jjd999tj88uiths3", @"Generated Signature does not conform to OAuth Core 9.4.1");
94 |
95 | mockCredentials.requestTokenSecret = @"jjd99$tj88uiths3";
96 | STAssertEqualObjects(mockCredentials.signingKey, @"djr9rjt0jd78jf88&jjd99%24tj88uiths3", @"Generated Signature does not conform to OAuth Core 9.4.1");
97 |
98 | }
99 |
100 | - (void)testConcatenationOfRequestElementsForBASEString_Core912 {
101 | NSURL *testURL = [NSURL URLWithString:@"http://example.com/"];
102 | MPURLRequestParameter *aParameter = [[[MPURLRequestParameter alloc] initWithName:@"n" andValue:@"v"] autorelease];
103 | NSMutableArray *parameterArray = [NSMutableArray arrayWithObject:aParameter];
104 | MPOAuthURLRequest *urlRequest = [[[MPOAuthURLRequest alloc] initWithURL:testURL andParameters:[NSArray arrayWithObject:aParameter]] autorelease];
105 |
106 | NSString *baseString = [MPOAuthSignatureParameter signatureBaseStringUsingParameterString:[MPURLRequestParameter parameterStringForParameters:parameterArray]
107 | forRequest:urlRequest];
108 | STAssertEqualObjects(baseString, @"GET&http%3A%2F%2Fexample.com%2F&n%3Dv", @"Base String does not conform to Core 9.1.2");
109 |
110 | urlRequest.url = [NSURL URLWithString:@"http://example.com"];
111 | baseString = [MPOAuthSignatureParameter signatureBaseStringUsingParameterString:[MPURLRequestParameter parameterStringForParameters:parameterArray]
112 | forRequest:urlRequest];
113 | STAssertEqualObjects(baseString, @"GET&http%3A%2F%2Fexample.com%2F&n%3Dv", @"Base String does not conform to Core 9.1.2");
114 |
115 | urlRequest.HTTPMethod = @"POST";
116 | urlRequest.url = [NSURL URLWithString:@"https://photos.example.net/request_token"];
117 | [parameterArray removeAllObjects];
118 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_version" andValue:@"1.0"] autorelease]];
119 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_consumer_key" andValue:@"dpf43f3p2l4k3l03"] autorelease]];
120 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_timestamp" andValue:@"1191242090"] autorelease]];
121 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_nonce" andValue:@"hsu94j3884jdopsl"] autorelease]];
122 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_signature_method" andValue:@"PLAINTEXT"] autorelease]];
123 | // This is not part of the test, it's added later by the API, only here to document the discrepancy between the site's test and here
124 | // [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_signature" andValue:@"ignored"] autorelease]];
125 | [parameterArray sortUsingSelector:@selector(compare:)];
126 | baseString = [MPOAuthSignatureParameter signatureBaseStringUsingParameterString:[MPURLRequestParameter parameterStringForParameters:parameterArray]
127 | forRequest:urlRequest];
128 | STAssertEqualObjects(baseString,
129 | @"POST&https%3A%2F%2Fphotos.example.net%2Frequest_token&oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dhsu94j3884jdopsl%26oauth_signature_method%3DPLAINTEXT%26oauth_timestamp%3D1191242090%26oauth_version%3D1.0",
130 | @"Base String does not conform to Core 9.1.2");
131 |
132 | urlRequest.HTTPMethod = @"GET";
133 | urlRequest.url = [NSURL URLWithString:@"http://photos.example.net/photos"];
134 | [parameterArray removeAllObjects];
135 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_version" andValue:@"1.0"] autorelease]];
136 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_consumer_key" andValue:@"dpf43f3p2l4k3l03"] autorelease]];
137 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_token" andValue:@"nnch734d00sl2jdk"] autorelease]];
138 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_timestamp" andValue:@"1191242096"] autorelease]];
139 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_nonce" andValue:@"kllo9940pd9333jh"] autorelease]];
140 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_signature_method" andValue:@"HMAC-SHA1"] autorelease]];
141 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"file" andValue:@"vacation.jpg"] autorelease]];
142 | [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"size" andValue:@"original"] autorelease]];
143 | // This is not part of the test, it's added later by the API, only here to document the discrepancy between the site's test and here
144 | // [parameterArray addObject:[[[MPURLRequestParameter alloc] initWithName:@"oauth_signature" andValue:@"ignored"] autorelease]];
145 | [parameterArray sortUsingSelector:@selector(compare:)];
146 | baseString = [MPOAuthSignatureParameter signatureBaseStringUsingParameterString:[MPURLRequestParameter parameterStringForParameters:parameterArray]
147 | forRequest:urlRequest];
148 | STAssertEqualObjects(baseString,
149 | @"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal",
150 | @"Base String does not conform to Core 9.1.2");
151 |
152 | }
153 |
154 |
155 | @end
156 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPOAuthURLRequestTests.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthURLRequestTests.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import "MPOAuthURLRequest.h"
12 | #import "MPOAuthCredentialStore.h"
13 |
14 | @interface MPOAuthURLRequestTests : SenTestCase {
15 | MPOAuthURLRequest *_request;
16 | id _credentials;
17 | }
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPOAuthURLRequestTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPOAuthURLRequestTests.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPOAuthURLRequestTests.h"
10 | #import "MPOAuthAPI.h"
11 | #import "MPOAuthCredentialConcreteStore.h"
12 | #import "MPURLRequestParameter.h"
13 | #import "NSString+URLEscapingAdditions.h"
14 |
15 | @implementation MPOAuthURLRequestTests
16 |
17 | - (void)setUp {
18 | NSDictionary *credentials = [NSDictionary dictionaryWithObjectsAndKeys: @"dpf43f3p2l4k3l03", kMPOAuthCredentialConsumerKey,
19 | @"kd94hf93k423kf44", kMPOAuthCredentialConsumerSecret,
20 | nil];
21 | MPOAuthCredentialConcreteStore *credentialStore = [[MPOAuthCredentialConcreteStore alloc] initWithCredentials:credentials forBaseURL:nil];
22 | credentialStore.signatureMethod = @"PLAINTEXT";
23 |
24 | NSURL *url = [NSURL URLWithString:@"http://example.com/request_token"];
25 | _request = [[MPOAuthURLRequest alloc] initWithURL:url andParameters:nil];
26 | }
27 |
28 | - (void)testNSURLParameterEncoding_Core51 {
29 | STAssertEqualObjects([@"abcABC123" stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding],
30 | @"abcABC123", @"Incorrectly encoded Parameter String, Core 5.1");
31 |
32 | STAssertEqualObjects([@"-._~" stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding],
33 | @"-._~", @"Incorrectly Encoded Parameter String, Core 5.1");
34 |
35 | STAssertEqualObjects([@"%" stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding],
36 | @"%25", @"Incorrectly Encoded Parameter String, Core 5.1");
37 |
38 | STAssertEqualObjects([@"+" stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding],
39 | @"%2B", @"Incorrectly Encoded Parameter String, Core 5.1");
40 |
41 | STAssertEqualObjects([@"&=*" stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding],
42 | @"%26%3D%2A", @"Incorrectly Encoded Parameter String, Core 5.1");
43 |
44 | STAssertEqualObjects([@"\n" stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding],
45 | @"%0A", @"Incorrectly Encoded Parameter String, Core 5.1");
46 |
47 | STAssertEqualObjects([@" " stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding],
48 | @"%20", @"Incorrectly Encoded Parameter String, Core 5.1");
49 |
50 |
51 | STAssertEqualObjects([@"\x7F" stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding],
52 | @"%7F", @"Incorrectly Encoded Parameter String, Core 5.1");
53 |
54 | // STAssertEqualObjects([@"\u80" stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding],
55 | // @"%C2%80", @"Incorrectly Encoded Parameter String, Core 5.1");
56 |
57 | STAssertEqualObjects([@"\u3001" stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding],
58 | @"%E3%80%81", @"Incorrectly Encoded Parameter String, Core 5.1");
59 |
60 | }
61 |
62 | - (void)testNormalizeRequestParameters_Core911 {
63 | NSMutableArray *parameterArray = [NSMutableArray arrayWithCapacity:10];
64 |
65 | MPURLRequestParameter *nameParameter = [[[MPURLRequestParameter alloc] initWithName:@"name" andValue:nil] autorelease];
66 | STAssertEqualObjects([nameParameter URLEncodedParameterString], @"name=", @"Incorrectly Normalized Request Parameters, Core 9.1.1");
67 |
68 | MPURLRequestParameter *aParameter = [[[MPURLRequestParameter alloc] initWithName:@"a" andValue:@"b"] autorelease];
69 | STAssertEqualObjects([aParameter URLEncodedParameterString], @"a=b", @"Incorrectly Normalized Request Parameters, Core 9.1.1");
70 |
71 | MPURLRequestParameter *anotherParameter = [[[MPURLRequestParameter alloc] initWithName:@"c" andValue:@"d"] autorelease];
72 | [parameterArray addObject:aParameter];
73 | [parameterArray addObject:anotherParameter];
74 | STAssertEqualObjects([MPURLRequestParameter parameterStringForParameters:parameterArray], @"a=b&c=d", @"Incorrectly Normalized Request Parameters, Core 9.1.1");
75 |
76 | aParameter.value = @"x!y";
77 | anotherParameter.name = @"a";
78 | anotherParameter.value = @"x y"; // the test cases online use + as space
79 | [parameterArray sortUsingSelector:@selector(compare:)];
80 | STAssertEqualObjects([MPURLRequestParameter parameterStringForParameters:parameterArray], @"a=x%20y&a=x%21y", @"Incorrectly Normalized Request Parameters, Core 9.1.1");
81 |
82 | aParameter.name = @"x!y";
83 | aParameter.value = @"a";
84 | anotherParameter.name = @"x";
85 | anotherParameter.value = @"a";
86 | [parameterArray sortUsingSelector:@selector(compare:)];
87 | STAssertEqualObjects([MPURLRequestParameter parameterStringForParameters:parameterArray], @"x=a&x%21y=a", @"Incorrectly Normalized Request Parameters, Core 9.1.1");
88 | }
89 |
90 | - (void)testParameterDictionaries {
91 | NSDictionary *parameterDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"b", @"a", @"d", @"c", nil];
92 | STAssertEqualObjects([MPURLRequestParameter parameterStringForDictionary:parameterDictionary], @"a=b&c=d", @"Incorrectly Normalized Request Parameters, Core 9.1.1");
93 |
94 | parameterDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"x!y", @"a", @"x", nil];
95 | NSArray *parameters = [MPURLRequestParameter parametersFromDictionary:parameterDictionary];
96 | parameters = [parameters sortedArrayUsingSelector:@selector(compare:)];
97 | STAssertEqualObjects([MPURLRequestParameter parameterStringForParameters:parameters], @"x=a&x%21y=a", @"Incorrectly Normalized Request Parameters, Core 9.1.1");
98 | }
99 |
100 | @end
101 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPURLRequestParameterTests.h:
--------------------------------------------------------------------------------
1 | //
2 | // MPURLRequestParameterTests.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import "MPURLRequestParameter.h"
12 |
13 | @class MPURLRequestParameter;
14 |
15 | @interface MPURLRequestParameterTests : SenTestCase {
16 | MPURLRequestParameter *_parameter;
17 | }
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/Source/Unit Tests/MPURLRequestParameterTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // MPURLRequestParameterTests.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 08.12.18.
6 | // Copyright 2008 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "MPURLRequestParameterTests.h"
10 | #import "MPURLRequestParameter.h"
11 | #import "NSString+URLEscapingAdditions.h"
12 |
13 | @implementation MPURLRequestParameterTests
14 |
15 | - (void)setUp {
16 | _parameter = [[MPURLRequestParameter alloc] init];
17 | _parameter.name = @"simon";
18 | _parameter.value = @"did not say";
19 | }
20 |
21 | - (void)testSetup {
22 | STAssertEqualObjects(_parameter.name, @"simon", @"The parameter name was incorrectly set to: %@", _parameter.name);
23 | STAssertEqualObjects(_parameter.value, @"did not say", @"The parameter value was incorrectly set to: %@", _parameter.value);
24 | }
25 |
26 | - (void)testURLEncodedNameValuePair {
27 | STAssertEqualObjects([_parameter URLEncodedParameterString], @"simon=did\%20not\%20say", @"The parameter pair was incorrectly encoded as: %@", [_parameter URLEncodedParameterString]);
28 | }
29 |
30 | - (void)testEncodedURLParameterString {
31 | //TODO gather complete set of test chars -> encoded values
32 | NSString *starter = @"\"<>\%{}[]|\\^`hello #";
33 | STAssertEqualObjects([starter stringByAddingURIPercentEscapesUsingEncoding:NSUTF8StringEncoding], @"\%22\%3C\%3E\%25\%7B\%7D\%5B\%5D\%7C\%5C\%5E\%60hello\%20\%23", @"The string was not encoded properly.");
34 | }
35 |
36 |
37 | @end
38 |
--------------------------------------------------------------------------------
/Source/Unit Tests/NSString+URLAdditionsTests.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+URLAdditionsTests.h
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 09.01.29.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface NSString_URLAdditionsTests : SenTestCase {
13 |
14 | }
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/Source/Unit Tests/NSString+URLAdditionsTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSString+URLAdditionsTests.m
3 | // MPOAuthConnection
4 | //
5 | // Created by Karl Adam on 09.01.29.
6 | // Copyright 2009 matrixPointer. All rights reserved.
7 | //
8 |
9 | #import "NSString+URLAdditionsTests.h"
10 | #import "MPURLRequestParameter.h"
11 | #import "NSURL+MPURLParameterAdditions.h"
12 | #import "NSString+URLEscapingAdditions.h"
13 |
14 | @implementation NSString_URLAdditionsTests
15 |
16 | - (void)testDomainMatching {
17 | NSURL *aURLToDomainMatch = nil;
18 | NSString *domainName = @".apple.com";
19 | NSArray *urlsThatShouldMatch = [NSArray arrayWithObjects:@"http://apple.com", @"http://apple.com/imac", @"http://www.apple.com", @"http://itunes.apple.com", nil];
20 | NSArray *urlsThatShouldNotMatch = [NSArray arrayWithObjects:@"http://macnn.com", @"http://crabapple.com", @"http://apple.crabapple.com", nil];
21 |
22 | for (NSString *aURLString in urlsThatShouldMatch) {
23 | aURLToDomainMatch = [NSURL URLWithString:aURLString];
24 | STAssertTrue([aURLToDomainMatch domainMatches:domainName], @"The URL's fully quantified domain name %@ should be a match for %@", aURLToDomainMatch, domainName);
25 | }
26 |
27 | for (NSString *aURLString in urlsThatShouldNotMatch) {
28 | aURLToDomainMatch = [NSURL URLWithString:aURLString];
29 | STAssertFalse([aURLToDomainMatch domainMatches:domainName], @"The URL's fully quantified domain name %@ should not be a match for %@", aURLToDomainMatch, domainName);
30 |
31 | }
32 |
33 | }
34 |
35 | - (void)testIsIPAddress {
36 | NSArray *possibleIPsToMatch = [NSArray arrayWithObjects:@"192.168.1.1", @"17.251.200.70", @"68.180.206.184", nil];
37 | NSArray *possibleIPsToNotMatch = [NSArray arrayWithObjects:@"999.999.1.1", @"666.666", @"42", nil];
38 |
39 | for (NSString *anIP in possibleIPsToMatch) {
40 | STAssertTrue([anIP isIPAddress], @"%@ should look like an IP address", anIP);
41 | }
42 |
43 | for (NSString *anIP in possibleIPsToNotMatch) {
44 | STAssertFalse([anIP isIPAddress], @"%@ should not look like an IP address", anIP);
45 |
46 | }
47 | }
48 |
49 | - (void)testURLByAddingParameters {
50 | NSURL *nakedURL = [NSURL URLWithString:@"http://apple.com"];
51 | NSURL *parameterizedURL = [NSURL URLWithString:@"http://example.com/index.php?a=b&c=d"];
52 |
53 | MPURLRequestParameter *aParameter = [[[MPURLRequestParameter alloc] initWithName:@"x" andValue:@"y"] autorelease];
54 | MPURLRequestParameter *anotherParameter = [[[MPURLRequestParameter alloc] initWithName:@"zeta" andValue:@"beta"] autorelease];
55 | NSArray *testParameters = [NSArray arrayWithObjects:aParameter, anotherParameter, nil];
56 |
57 | STAssertEqualObjects( [nakedURL urlByAddingParameters:testParameters],
58 | [NSURL URLWithString:@"http://apple.com?x=y&zeta=beta"],
59 | @"-urlByAddingParameters failed to correctly add the requested parameters"
60 | );
61 |
62 | STAssertEqualObjects( [parameterizedURL urlByAddingParameters:testParameters],
63 | [NSURL URLWithString:@"http://example.com/index.php?a=b&c=d&x=y&zeta=beta"],
64 | @"-urlByAddingParameters failed to correctly add the requested parameters"
65 | );
66 |
67 | }
68 |
69 | - (void)testURLByAddingParameterDictionary {
70 | NSURL *nakedURL = [NSURL URLWithString:@"http://apple.com"];
71 | NSURL *parameterizedURL = [NSURL URLWithString:@"http://example.com/index.php?a=b&c=d"];
72 |
73 | NSDictionary *parameterDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"y", @"x", @"beta", @"zeta", nil];
74 | NSArray *parameters = [MPURLRequestParameter parametersFromDictionary:parameterDictionary];
75 | parameters = [parameters sortedArrayUsingSelector:@selector(compare:)];
76 |
77 | // This tests are actually a little bit disingenious but they're a quick sanity check to make sure things are spit out
78 | // as expected
79 | STAssertEqualObjects( [nakedURL urlByAddingParameters:parameters],
80 | [NSURL URLWithString:@"http://apple.com?x=y&zeta=beta"],
81 | @"-urlByAddingParameters failed to correctly add the requested parameters"
82 | );
83 |
84 |
85 | STAssertEqualObjects( [parameterizedURL urlByAddingParameters:parameters],
86 | [NSURL URLWithString:@"http://example.com/index.php?a=b&c=d&x=y&zeta=beta"],
87 | @"-urlByAddingParameters failed to correctly add the requested parameters"
88 | );
89 |
90 | }
91 |
92 | @end
93 |
--------------------------------------------------------------------------------
/Source/Unit Tests/OATestServer.rb:
--------------------------------------------------------------------------------
1 | #
2 | # OATestServer.rb
3 | # OAuthConsumer
4 | #
5 | # Created by Jon Crosby on 10/19/07.
6 | # Copyright 2007 Kaboomerang LLC. All rights reserved.
7 | #
8 | # Permission is hereby granted, free of charge, to any person obtaining a copy
9 | # of this software and associated documentation files (the "Software"), to deal
10 | # in the Software without restriction, including without limitation the rights
11 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | # copies of the Software, and to permit persons to whom the Software is
13 | # furnished to do so, subject to the following conditions:
14 | #
15 | # The above copyright notice and this permission notice shall be included in
16 | # all copies or substantial portions of the Software.
17 | #
18 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 | # THE SOFTWARE.
25 |
26 | # Note: Before running this, install Sinatra: http://sinatra.rubyforge.org/
27 |
28 | require 'rubygems'
29 | require 'sinatra'
30 |
31 | get '/' do
32 | "Testing..."
33 | end
34 |
35 | post '/request_token' do
36 | "oauth_token=nnch734d00sl2jdk&oauth_token_secret=pfkkdhi9sl3r4s00"
37 | end
--------------------------------------------------------------------------------
/Unit Tests Static-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | com.yourcompany.${PRODUCT_NAME:identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Unit Tests-Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | English
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIdentifier
10 | com.yourcompany.${PRODUCT_NAME:identifier}
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundlePackageType
14 | BNDL
15 | CFBundleSignature
16 | ????
17 | CFBundleVersion
18 | 1.0
19 |
20 |
21 |
--------------------------------------------------------------------------------