Swift based OAuth library for iOS
Twitter, Flickr, Github, Instagram, Foursquare. Fitbit, Withings, Linkedin, Dropbox etc
Twitter
Flickr
Github
Instagram
Foursquare
Fitbit
Withings
Linkedin
Dropbox
- Add OAuthSwift as a submodule by opening the Terminal,
cd
-ing into your top-level project directory, and entering the commandgit submodule add https://github.com/rjourde/OAuthSwift.git
- Open the
OAuthSwift
folder, and dragOAuthSwift.xcodeproj
into the file navigator of your app project. - In Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar.
- Ensure that the deployment target of OAuthSwift.framework matches that of the application target.
- In the tab bar at the top of that window, open the "Build Phases" panel.
- Expand the "Target Dependencies" group, and add
OAuthSwift.framework
. - Click on the
+
button at the top left of the panel and select "New Copy Files Phase". Rename this new phase to "Copy Frameworks", set the "Destination" to "Frameworks", and addOAuthSwift.framework
. - In top-level OAuthSwift directory, create a new folder named
CommonCrypto
. - Open the
CommonCrypto
folder, and create a new file namedmodule.map
. - Open the
module.map
file, and add the following lines:module CommonCrypto [system] { header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk/usr/include/CommonCrypto/CommonCrypto.h" link "CommonCrypto" export * }
- Open the "Build Settings" panel and set
<OAuthSwift_Path>/CommonCrypto
to "Import Paths".
// AppDelegate
func application(application: UIApplication!, openURL url: NSURL!, sourceApplication: String!, annotation: AnyObject!) -> Bool {
if (url.host == "oauth-callback") {
if (url.path!.hasPrefix("/twitter")){
OAuth1.handleOpenURL(url)
}
if ( url.path!.hasPrefix("/github" )){
OAuth2.handleOpenURL(url)
}
}
return true
}
// OAuth1.0
let oauthswift = OAuth1(
consumerKey: "********",
consumerSecret: "********",
requestTokenUrl: "https://api.twitter.com/oauth/request_token",
authorizeUrl: "https://api.twitter.com/oauth/authorize",
accessTokenUrl: "https://api.twitter.com/oauth/access_token"
)
oauthswift.authorizeWithCallbackURL( NSURL(string: "oauth-swift://oauth-callback/twitter"), success: {
credential, response in
println(credential.oauth_token)
println(credential.oauth_token_secret)
}, failure: failureHandler)
// OAuth2.0
let oauthswift = OAuth2(
consumerKey: "********",
consumerSecret: "********",
authorizeUrl: "https://api.instagram.com/oauth/authorize",
responseType: "token"
)
oauthswift.authorizeWithCallbackURL( NSURL(string: "oauth-swift://oauth-callback/instagram"), scope: "likes+comments", state:"INSTAGRAM", success: {
credential, response in
println(credential.oauth_token)
}, failure: failureHandler)