[![CI Status](http://img.shields.io/travis/Brayden Morris/RockauthIOS.svg?style=flat)](https://travis-ci.org/Brayden Morris/RockauthIOS)
RockauthIOS is available through CocoaPods.
- Add the following line to your Podfile:
pod 'RockauthiOS', :git => 'https://github.com/rocketmade/rockauth-ios', :branch => 'dev'
- Run
pod install
- In order for API requests to work, add the following to your AppDelegate (The second part should go in
didFinishLaunchingWithOptions
):
import RockauthiOS
...
RockauthClient.sharedClient = RockauthClient(baseURL: <#apiBaseURL: String#>, clientID: <#apiClientID: String#>, clientSecret: <#apiClientSecret: String#>)
- If your app was not created with Liftoff, the app's Info.plist must contain the following:
<key>Configuration</key>
<string>${CONFIGURATION}</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Or like this:
Currently disabled
- Add the following to your Podfile:
pod 'Fabric'
pod 'TwitterKit'
pod 'TwitterCore'
-
Run
pod install
-
Add the following to your project (possibly in your AppDelegate, specifically in
didFinishLaunchingWithOptions
):
import TwitterKit
...
Twitter.sharedInstance().startWithConsumerKey(<#twitterKey: String#>, consumerSecret: <#twitterSecret: String#>)
- Where you want to invoke
import RockauthiOS
import TwitterKit
...
func logInWithTwitter() {
Twitter.sharedInstance().logInWithCompletion { session, error in
if (session != nil) {
print("signed in as \(session!.userName)");
let tp = TwitterProvider(token: session!.authToken, secret: session!.authTokenSecret)
tp.login(success: { () -> Void in
<#code#>
}, failure: { (error) -> Void in
print(error)
})
} else {
print("error: \(error!.localizedDescription)");
}
}
}
- Add the following to your podfile:
pod 'Google/SignIn'
-
Run
pod install
-
In your AppDelegate's didFinishLaunchingWithOptions add:
// Initialize Google sign-in
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")
- In the viewController that will be responsible for interacting with Rockauth add the following protocols to your class definition:
class ViewController: UIViewController, GIDSignInDelegate, GIDSignInUIDelegate, ConnectWithGoogleDelegate {
- In the viewController that will be responsible for interacting with Rockauth add the following to
ViewDidLoad
:
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
(GoogleProvider.sharedProvider as! GoogleProvider).delegate = self
- Add the following method that will get called when the Google button in the Rockauth UI is clicked:
func googleButtonClicked() {
self.dismissViewControllerAnimated(true, completion: { () -> Void in
GIDSignIn.sharedInstance().signIn()
})
}
- Add the
didSignInForUser
delegate method:
func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
let idToken = user.authentication.idToken
let gp = GoogleProvider.sharedProvider as! GoogleProvider
gp.token = idToken
gp.connect(fromViewController: self, success: { (user) -> Void in
print(user)
// User is successfully signed in
<#code#>
}, failure: { (error) -> Void in
print(error)
})
} else {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
let alertController = UIAlertController(title: "Error Signing In", message: error.localizedDescription, preferredStyle: .Alert)
let okButton = UIAlertAction(title: "OK", style: .Default, handler:nil)
alertController.addAction(okButton)
self.presentViewController(alertController, animated: true, completion: nil)
})
}
}
- After creating your app in the Google developer console you must download and add
GoogleService-Info.plist
to your project. If you want the correct plist to be used for the current build configuration eg. Debug, Staging, Release, you can add the following run script to your Build Phases:
rm ${SRCROOT}/${PRODUCT_NAME}/GoogleService-Info.plist
/usr/libexec/PlistBuddy -c "Merge ${SRCROOT}/${PRODUCT_NAME}/${CONFIGURATION}-GoogleService-Info.plist" ${SRCROOT}/${PRODUCT_NAME}/GoogleService-Info.plist
Just make sure it is run before 'Copy Bundle Resources'
You will also need to name each plist like this: Debug-GoogleService-Info.plist
or Release-GoogleService-Info.plist
Rocketmade, [email protected]
RockauthIOS is available under the MIT license. See the LICENSE file for more info.