├── .gitignore ├── English.lproj └── InfoPlist.strings ├── Info.plist ├── README ├── oauth2.xcodeproj ├── leebyron.pbxuser └── project.pbxproj ├── source ├── auth │ ├── O2AuthFlow.h │ ├── O2AuthFlow.m │ ├── O2Client.h │ └── O2Client.m └── other │ └── oauth2_Prefix.pch └── version.plist /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build/ 3 | -------------------------------------------------------------------------------- /English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleName 10 | ${PRODUCT_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.yourcompany.${PRODUCT_NAME:rfc1034Identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundlePackageType 18 | FMWK 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | CFBundleShortVersionString 24 | 1.0 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leebyron/cocoa-oauth2/18ebdad4c860ab1887f685656480d7a84d2c30d2/README -------------------------------------------------------------------------------- /oauth2.xcodeproj/leebyron.pbxuser: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | 0867D690FE84028FC02AAC07 /* Project object */ = { 4 | activeBuildConfigurationName = Debug; 5 | activeTarget = 8DC2EF4F0486A6940098B216 /* oauth2 */; 6 | addToTargets = ( 7 | 8DC2EF4F0486A6940098B216 /* oauth2 */, 8 | ); 9 | codeSenseManager = 535A7E85116EDBAB003D90A8 /* Code sense */; 10 | perUserDictionary = { 11 | PBXPerProjectTemplateStateSaveDate = 292477919; 12 | PBXWorkspaceStateSaveDate = 292477919; 13 | }; 14 | sourceControlManager = 535A7E84116EDBAB003D90A8 /* Source Control */; 15 | userBuildSettings = { 16 | }; 17 | }; 18 | 535A7E84116EDBAB003D90A8 /* Source Control */ = { 19 | isa = PBXSourceControlManager; 20 | fallbackIsa = XCSourceControlManager; 21 | isSCMEnabled = 0; 22 | scmConfiguration = { 23 | repositoryNamesForRoots = { 24 | "" = ""; 25 | }; 26 | }; 27 | }; 28 | 535A7E85116EDBAB003D90A8 /* Code sense */ = { 29 | isa = PBXCodeSenseManager; 30 | indexTemplatePath = ""; 31 | }; 32 | 8DC2EF4F0486A6940098B216 /* oauth2 */ = { 33 | activeExec = 0; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /oauth2.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 45; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 535A7EA1116EDC8F003D90A8 /* oauth2_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = 535A7EA0116EDC8F003D90A8 /* oauth2_Prefix.pch */; }; 11 | 535A7EA9116EDF53003D90A8 /* O2AuthFlow.h in Headers */ = {isa = PBXBuildFile; fileRef = 535A7EA5116EDF53003D90A8 /* O2AuthFlow.h */; }; 12 | 535A7EAA116EDF53003D90A8 /* O2AuthFlow.m in Sources */ = {isa = PBXBuildFile; fileRef = 535A7EA6116EDF53003D90A8 /* O2AuthFlow.m */; }; 13 | 535A7EAB116EDF53003D90A8 /* O2Client.h in Headers */ = {isa = PBXBuildFile; fileRef = 535A7EA7116EDF53003D90A8 /* O2Client.h */; }; 14 | 535A7EAC116EDF53003D90A8 /* O2Client.m in Sources */ = {isa = PBXBuildFile; fileRef = 535A7EA8116EDF53003D90A8 /* O2Client.m */; }; 15 | 8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; }; 16 | 8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 0867D69BFE84028FC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 21 | 0867D6A5FE840307C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 22 | 089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = ""; }; 23 | 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = ""; }; 24 | 535A7EA0116EDC8F003D90A8 /* oauth2_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = oauth2_Prefix.pch; sourceTree = ""; }; 25 | 535A7EA5116EDF53003D90A8 /* O2AuthFlow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = O2AuthFlow.h; sourceTree = ""; }; 26 | 535A7EA6116EDF53003D90A8 /* O2AuthFlow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = O2AuthFlow.m; sourceTree = ""; }; 27 | 535A7EA7116EDF53003D90A8 /* O2Client.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = O2Client.h; sourceTree = ""; }; 28 | 535A7EA8116EDF53003D90A8 /* O2Client.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = O2Client.m; sourceTree = ""; }; 29 | 8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | 8DC2EF5B0486A6940098B216 /* oauth2.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = oauth2.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | D2F7E79907B2D74100F64583 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = ""; }; 32 | /* End PBXFileReference section */ 33 | 34 | /* Begin PBXFrameworksBuildPhase section */ 35 | 8DC2EF560486A6940098B216 /* Frameworks */ = { 36 | isa = PBXFrameworksBuildPhase; 37 | buildActionMask = 2147483647; 38 | files = ( 39 | 8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */, 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 034768DFFF38A50411DB9C8B /* Products */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 8DC2EF5B0486A6940098B216 /* oauth2.framework */, 50 | ); 51 | name = Products; 52 | sourceTree = ""; 53 | }; 54 | 0867D691FE84028FC02AAC07 /* oauth2 */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 535A7E9D116EDC51003D90A8 /* source */, 58 | 089C1665FE841158C02AAC07 /* Resources */, 59 | 0867D69AFE84028FC02AAC07 /* External Frameworks and Libraries */, 60 | 034768DFFF38A50411DB9C8B /* Products */, 61 | ); 62 | name = oauth2; 63 | sourceTree = ""; 64 | }; 65 | 0867D69AFE84028FC02AAC07 /* External Frameworks and Libraries */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | 1058C7B0FEA5585E11CA2CBB /* Linked Frameworks */, 69 | 1058C7B2FEA5585E11CA2CBB /* Other Frameworks */, 70 | ); 71 | name = "External Frameworks and Libraries"; 72 | sourceTree = ""; 73 | }; 74 | 089C1665FE841158C02AAC07 /* Resources */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 8DC2EF5A0486A6940098B216 /* Info.plist */, 78 | 089C1666FE841158C02AAC07 /* InfoPlist.strings */, 79 | ); 80 | name = Resources; 81 | sourceTree = ""; 82 | }; 83 | 1058C7B0FEA5585E11CA2CBB /* Linked Frameworks */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */, 87 | ); 88 | name = "Linked Frameworks"; 89 | sourceTree = ""; 90 | }; 91 | 1058C7B2FEA5585E11CA2CBB /* Other Frameworks */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 0867D6A5FE840307C02AAC07 /* AppKit.framework */, 95 | D2F7E79907B2D74100F64583 /* CoreData.framework */, 96 | 0867D69BFE84028FC02AAC07 /* Foundation.framework */, 97 | ); 98 | name = "Other Frameworks"; 99 | sourceTree = ""; 100 | }; 101 | 535A7E9D116EDC51003D90A8 /* source */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 535A7E9E116EDC59003D90A8 /* auth */, 105 | 535A7E9F116EDC5E003D90A8 /* other */, 106 | ); 107 | path = source; 108 | sourceTree = ""; 109 | }; 110 | 535A7E9E116EDC59003D90A8 /* auth */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 535A7EA5116EDF53003D90A8 /* O2AuthFlow.h */, 114 | 535A7EA6116EDF53003D90A8 /* O2AuthFlow.m */, 115 | 535A7EA7116EDF53003D90A8 /* O2Client.h */, 116 | 535A7EA8116EDF53003D90A8 /* O2Client.m */, 117 | ); 118 | path = auth; 119 | sourceTree = ""; 120 | }; 121 | 535A7E9F116EDC5E003D90A8 /* other */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | 535A7EA0116EDC8F003D90A8 /* oauth2_Prefix.pch */, 125 | ); 126 | path = other; 127 | sourceTree = ""; 128 | }; 129 | /* End PBXGroup section */ 130 | 131 | /* Begin PBXHeadersBuildPhase section */ 132 | 8DC2EF500486A6940098B216 /* Headers */ = { 133 | isa = PBXHeadersBuildPhase; 134 | buildActionMask = 2147483647; 135 | files = ( 136 | 535A7EA1116EDC8F003D90A8 /* oauth2_Prefix.pch in Headers */, 137 | 535A7EA9116EDF53003D90A8 /* O2AuthFlow.h in Headers */, 138 | 535A7EAB116EDF53003D90A8 /* O2Client.h in Headers */, 139 | ); 140 | runOnlyForDeploymentPostprocessing = 0; 141 | }; 142 | /* End PBXHeadersBuildPhase section */ 143 | 144 | /* Begin PBXNativeTarget section */ 145 | 8DC2EF4F0486A6940098B216 /* oauth2 */ = { 146 | isa = PBXNativeTarget; 147 | buildConfigurationList = 1DEB91AD08733DA50010E9CD /* Build configuration list for PBXNativeTarget "oauth2" */; 148 | buildPhases = ( 149 | 8DC2EF500486A6940098B216 /* Headers */, 150 | 8DC2EF520486A6940098B216 /* Resources */, 151 | 8DC2EF540486A6940098B216 /* Sources */, 152 | 8DC2EF560486A6940098B216 /* Frameworks */, 153 | ); 154 | buildRules = ( 155 | ); 156 | dependencies = ( 157 | ); 158 | name = oauth2; 159 | productInstallPath = "$(HOME)/Library/Frameworks"; 160 | productName = oauth2; 161 | productReference = 8DC2EF5B0486A6940098B216 /* oauth2.framework */; 162 | productType = "com.apple.product-type.framework"; 163 | }; 164 | /* End PBXNativeTarget section */ 165 | 166 | /* Begin PBXProject section */ 167 | 0867D690FE84028FC02AAC07 /* Project object */ = { 168 | isa = PBXProject; 169 | buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "oauth2" */; 170 | compatibilityVersion = "Xcode 3.1"; 171 | hasScannedForEncodings = 1; 172 | mainGroup = 0867D691FE84028FC02AAC07 /* oauth2 */; 173 | productRefGroup = 034768DFFF38A50411DB9C8B /* Products */; 174 | projectDirPath = ""; 175 | projectRoot = ""; 176 | targets = ( 177 | 8DC2EF4F0486A6940098B216 /* oauth2 */, 178 | ); 179 | }; 180 | /* End PBXProject section */ 181 | 182 | /* Begin PBXResourcesBuildPhase section */ 183 | 8DC2EF520486A6940098B216 /* Resources */ = { 184 | isa = PBXResourcesBuildPhase; 185 | buildActionMask = 2147483647; 186 | files = ( 187 | 8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */, 188 | ); 189 | runOnlyForDeploymentPostprocessing = 0; 190 | }; 191 | /* End PBXResourcesBuildPhase section */ 192 | 193 | /* Begin PBXSourcesBuildPhase section */ 194 | 8DC2EF540486A6940098B216 /* Sources */ = { 195 | isa = PBXSourcesBuildPhase; 196 | buildActionMask = 2147483647; 197 | files = ( 198 | 535A7EAA116EDF53003D90A8 /* O2AuthFlow.m in Sources */, 199 | 535A7EAC116EDF53003D90A8 /* O2Client.m in Sources */, 200 | ); 201 | runOnlyForDeploymentPostprocessing = 0; 202 | }; 203 | /* End PBXSourcesBuildPhase section */ 204 | 205 | /* Begin PBXVariantGroup section */ 206 | 089C1666FE841158C02AAC07 /* InfoPlist.strings */ = { 207 | isa = PBXVariantGroup; 208 | children = ( 209 | 089C1667FE841158C02AAC07 /* English */, 210 | ); 211 | name = InfoPlist.strings; 212 | sourceTree = ""; 213 | }; 214 | /* End PBXVariantGroup section */ 215 | 216 | /* Begin XCBuildConfiguration section */ 217 | 1DEB91AE08733DA50010E9CD /* Debug */ = { 218 | isa = XCBuildConfiguration; 219 | buildSettings = { 220 | ALWAYS_SEARCH_USER_PATHS = NO; 221 | COPY_PHASE_STRIP = NO; 222 | DYLIB_COMPATIBILITY_VERSION = 1; 223 | DYLIB_CURRENT_VERSION = 1; 224 | FRAMEWORK_VERSION = A; 225 | GCC_DYNAMIC_NO_PIC = NO; 226 | GCC_ENABLE_FIX_AND_CONTINUE = YES; 227 | GCC_MODEL_TUNING = G5; 228 | GCC_OPTIMIZATION_LEVEL = 0; 229 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 230 | GCC_PREFIX_HEADER = oauth2_Prefix.pch; 231 | INFOPLIST_FILE = Info.plist; 232 | INSTALL_PATH = "$(HOME)/Library/Frameworks"; 233 | PRODUCT_NAME = oauth2; 234 | WRAPPER_EXTENSION = framework; 235 | }; 236 | name = Debug; 237 | }; 238 | 1DEB91AF08733DA50010E9CD /* Release */ = { 239 | isa = XCBuildConfiguration; 240 | buildSettings = { 241 | ALWAYS_SEARCH_USER_PATHS = NO; 242 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 243 | DYLIB_COMPATIBILITY_VERSION = 1; 244 | DYLIB_CURRENT_VERSION = 1; 245 | FRAMEWORK_VERSION = A; 246 | GCC_MODEL_TUNING = G5; 247 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 248 | GCC_PREFIX_HEADER = oauth2_Prefix.pch; 249 | INFOPLIST_FILE = Info.plist; 250 | INSTALL_PATH = "$(HOME)/Library/Frameworks"; 251 | PRODUCT_NAME = oauth2; 252 | WRAPPER_EXTENSION = framework; 253 | }; 254 | name = Release; 255 | }; 256 | 1DEB91B208733DA50010E9CD /* Debug */ = { 257 | isa = XCBuildConfiguration; 258 | buildSettings = { 259 | ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 260 | GCC_C_LANGUAGE_STANDARD = gnu99; 261 | GCC_OPTIMIZATION_LEVEL = 0; 262 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 263 | GCC_WARN_UNUSED_VARIABLE = YES; 264 | ONLY_ACTIVE_ARCH = YES; 265 | PREBINDING = NO; 266 | SDKROOT = macosx10.6; 267 | }; 268 | name = Debug; 269 | }; 270 | 1DEB91B308733DA50010E9CD /* Release */ = { 271 | isa = XCBuildConfiguration; 272 | buildSettings = { 273 | ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; 274 | GCC_C_LANGUAGE_STANDARD = gnu99; 275 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 276 | GCC_WARN_UNUSED_VARIABLE = YES; 277 | PREBINDING = NO; 278 | SDKROOT = macosx10.6; 279 | }; 280 | name = Release; 281 | }; 282 | /* End XCBuildConfiguration section */ 283 | 284 | /* Begin XCConfigurationList section */ 285 | 1DEB91AD08733DA50010E9CD /* Build configuration list for PBXNativeTarget "oauth2" */ = { 286 | isa = XCConfigurationList; 287 | buildConfigurations = ( 288 | 1DEB91AE08733DA50010E9CD /* Debug */, 289 | 1DEB91AF08733DA50010E9CD /* Release */, 290 | ); 291 | defaultConfigurationIsVisible = 0; 292 | defaultConfigurationName = Release; 293 | }; 294 | 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "oauth2" */ = { 295 | isa = XCConfigurationList; 296 | buildConfigurations = ( 297 | 1DEB91B208733DA50010E9CD /* Debug */, 298 | 1DEB91B308733DA50010E9CD /* Release */, 299 | ); 300 | defaultConfigurationIsVisible = 0; 301 | defaultConfigurationName = Release; 302 | }; 303 | /* End XCConfigurationList section */ 304 | }; 305 | rootObject = 0867D690FE84028FC02AAC07 /* Project object */; 306 | } 307 | -------------------------------------------------------------------------------- /source/auth/O2AuthFlow.h: -------------------------------------------------------------------------------- 1 | 2 | // OAuthFlow 3 | 4 | // This factory class defines an abstract interface 5 | // for interface controller code for the different 6 | // cocoa platforms 7 | 8 | @interface O2AuthFlow : NSObject 9 | { 10 | id mDelegate; 11 | NSString* identifier; 12 | } 13 | 14 | // Factory 15 | + (O2AuthFlow*)authFlowWithIdentifier:(NSString*)identifier 16 | 17 | // Authorization 18 | - (void)visitAuthorizationServer:(NSURL*)url; 19 | 20 | // Delegate 21 | @property (assign) id delegate; 22 | @property (retain) NSString* identifer; 23 | 24 | @end 25 | 26 | 27 | // OAuthFlow Delegates 28 | 29 | // For now delegates only are notified if authentication 30 | // succeeds or is cancelled. 31 | 32 | @protocol O2AuthDelegate 33 | 34 | @required 35 | 36 | - (void)authFlowDone:(O2AuthFlow*)authFlow; 37 | - (void)authFlowCancelled:(O2AuthFlow*)authFlow; 38 | 39 | @end 40 | 41 | 42 | // OAuthMacFlow 43 | 44 | // Interface controller class for Mac that implements 45 | // the OAuthFlow contract. For now, pops a window 46 | // with an webview and watches for URL changes. 47 | 48 | // In the future, will send users to their 49 | // preferred browser and brings them back with a 50 | // protocol scheme handler. 51 | 52 | @class WebView; 53 | 54 | @interface O2AuthMacFlow : O2AuthFlow 55 | { 56 | NSWindow* mWindow; 57 | WebView* mWebView; 58 | } 59 | 60 | @end 61 | 62 | -------------------------------------------------------------------------------- /source/auth/O2AuthFlow.m: -------------------------------------------------------------------------------- 1 | #import "O2AuthFlow.h" 2 | 3 | @implementation O2AuthFlow 4 | 5 | @synthesize delegate = mDelegate; 6 | 7 | + (O2AuthFlow*)authFlowWithIdentifier:(NSString*)identifier 8 | { 9 | O2AuthMacFlow* flow = [[[O2AuthMacFlow alloc] init] autorelease]; 10 | flow.identifier = identifier; 11 | return flow; 12 | } 13 | 14 | - (void)visitAuthorizationServer:(NSURL*)url 15 | { 16 | // Must override 17 | [NSException exceptionWithName:@"abstract class" 18 | reason:@"Must use an overriding class of O2AuthFlow" 19 | userInfo:nil]; 20 | } 21 | 22 | @end 23 | 24 | 25 | @implementation O2AuthMacFlow 26 | 27 | - (id)init 28 | { 29 | self = [super init]; 30 | if(!self) return nil; 31 | 32 | return self; 33 | } 34 | 35 | - (void)dealloc 36 | { 37 | 38 | } 39 | 40 | - (void)visitAuthorizationServer:(NSURL*)url 41 | { 42 | NSURL* serverWithParams; 43 | 44 | serverWithParams = [url absoluteString] 45 | [[NSWorkspace sharedWorkspace] openURL:url]; 46 | } 47 | 48 | @end -------------------------------------------------------------------------------- /source/auth/O2Client.h: -------------------------------------------------------------------------------- 1 | 2 | @class O2AuthFlow; 3 | 4 | @interface O2Client : NSObject 5 | { 6 | NSURL* mServer; 7 | NSString* mIdentifier; 8 | NSString* mSecret; 9 | 10 | NSString* mAccessToken; 11 | NSString* mRefreshToken; 12 | 13 | O2AuthFlow* mAuthFlow; 14 | id mDelegate; 15 | } 16 | 17 | // Factory 18 | + (O2Client*)clientWithServer:(NSURL*)server 19 | identifier:(NSString*)identifier 20 | secret:(NSString*)secret; 21 | 22 | // Initialization 23 | - (O2Client*)initWithServer:(NSURL*)server 24 | identifier:(NSString*)identifier 25 | secret:(NSString*)secret; 26 | 27 | // Authorization 28 | - (void)authorize; 29 | @property (readonly) NSString* accessToken; 30 | @property (readonly) NSString* refreshToken; 31 | 32 | // Reauthorization 33 | - (void)reauthorizeWithRefreshToken:(NSString*)refreshToken; 34 | 35 | // Delegate 36 | @property (assign) id delegate; 37 | 38 | @end 39 | 40 | @interface NSObject (O2ClientDelegate) 41 | 42 | // Authorization 43 | - (void)O2ClientAuthorizationDone:(O2Client*)client; 44 | - (void)O2Client:(O2Client*)client authorizationError:(NSError*)error; 45 | 46 | // Errors 47 | - (void)O2ClientError:(O2Client*)client error:(NSError*)error; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /source/auth/O2Client.m: -------------------------------------------------------------------------------- 1 | 2 | #import "O2Client.h" 3 | #import "O2AuthFlow.h" 4 | 5 | @implementation O2Client 6 | 7 | @synthesize delegate = mDelegate; 8 | @synthesize accessToken = mAccessToken; 9 | @synthesize refreshToken = mRefreshToken; 10 | 11 | + (O2Client*)clientWithServer:(NSURL*)server 12 | identifier:(NSString*)identifier 13 | secret:(NSString*)secret 14 | { 15 | return [[[O2Client alloc] initWithServer:server 16 | identifier:identifier 17 | secret:secret] autorelease]; 18 | } 19 | 20 | - (O2Client*)initWithServer:(NSURL*)server 21 | identifier:(NSString*)identifier 22 | secret:(NSString*)secret 23 | { 24 | self = [super init]; 25 | if(!self) return nil; 26 | 27 | mServer = [server copy]; 28 | mIdentifier = [identifier copy]; 29 | mSecret = [secret copy]; 30 | 31 | return self; 32 | } 33 | 34 | - (void)dealloc 35 | { 36 | mDelegate = nil; 37 | [mServer release]; 38 | [mIdentifier release]; 39 | [mSecret release]; 40 | [mAccessToken release]; 41 | [mRefreshToken release]; 42 | [mAuthFlow release]; 43 | [super dealloc]; 44 | } 45 | 46 | #pragma mark - 47 | 48 | - (void)authorize 49 | { 50 | // Forget tokens and reauthorize from scratch 51 | 52 | // Open Authentication URL 53 | if(!mAuthFlow) mAuthFlow = [[O2AuthFlow authFlow] retain]; 54 | [mAuthFlow visitAuthorizationServer:mServer identifier:mIdentifier]; 55 | } 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /source/other/oauth2_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'oauth2' target in the 'oauth2' project. 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /version.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildVersion 6 | 2 7 | CFBundleShortVersionString 8 | 1.0 9 | CFBundleVersion 10 | 1 11 | ProjectName 12 | DevToolsWizardTemplates 13 | SourceVersion 14 | 15920000 15 | 16 | 17 | --------------------------------------------------------------------------------