This module currently build with Xcode 7 and supports iOS7 [1], iOS8, iOS9.
OAuth2 Client based on aerogear-ios-http. Taking care of:
- account manager for multiple OAuth2 accounts,
- request access and refresh token,
- grant access through secure external browser and URI schema to re-enter app,
- (implicit or explicit) refresh tokens,
- revoke tokens,
- permanent secure storage,
- adaptable to OAuth2 specific providers. Existing extensions: Google, Facebook, Keycloak 1.5.0.Final etc...
- openID Connect login
100% Swift 2.0.
Project Info | |
---|---|
License: | Apache License, Version 2.0 |
Build: | Cocoapods |
Documentation: | https://aerogear.org/docs/guides/aerogear-ios-2.X/ |
Issue tracker: | https://issues.jboss.org/browse/AGIOS |
Mailing lists: | aerogear-users (subscribe) |
aerogear-dev (subscribe) |
Note [1]: Cocoapod central repo supports dynamic library from iOS8+. If you want to deploy on iOS7, use areoger-ios-http fom master source with its podspec pointing to iOS7.
var Http = Http() // [1]
let facebookConfig = FacebookConfig( // [2]
clientId: "YYY",
clientSecret: "XXX",
scopes:["photo_upload, publish_actions"])
var oauth2Module = AccountManager.addFacebookAccount(facebookConfig) // [3]
http.authzModule = oauth2Module // [4]
http.GET("/get", completionHandler: {(response, error) in // [5]
// handle response
})
Create an instance of Http [1] from aerogear-ios-http a thin layer on top of NSURLSession.
Fill-in the OAuth2 configuration in [2], here we use a predefined Config with all Facebook endpoint filled-in for us.
Create an OAuth2Module from AccountManager's factory method in [3].
Inject OAuth2Module into http object in [4] and uses the http object to GET/POST etc...
See full description in aerogear.org
var Http = Http()
let keycloakConfig = KeycloakConfig(
clientId: "sharedshoot-third-party",
host: "http://localhost:8080",
realm: "shoot-realm",
isOpenIDConnect: true)
var oauth2Module = AccountManager.addKeycloakAccount(keycloakConfig)
http.authzModule = oauth2Module
oauth2Module.login {(accessToken: AnyObject?, claims: OpenIDClaim?, error: NSError?) in // [1]
// Do your own stuff here
}
Similar approach for configuration, here we want to login as Keycloak user, using login
method we get some user information back in OpenIDClaim object.
NOTE: The latest version of the library works with Keycloak 1.1.0.Final. Previous version of Keycloak 1.0.x will work except for the transparent refresh of tokens (ie: after access token expires you will have to go through grant process).
-
Clone this project
-
Get the dependencies
The project uses cocoapods 0.36 release for handling its dependencies. As a pre-requisite, install cocoapods and then install the pod. On the root directory of the project run:
pod install
- open AeroGearOAuth2.xcworkspace
To add the library in your project, you can either use Cocoapods or manual install in your project. See the respective sections below for instructions:
Using Cocoapods
Support for Swift frameworks is supported from CocoaPods-0.36 release upwards. In your Podfile
add:
pod 'AeroGearOAuth2'
and then:
pod install
to install your dependencies
Follow these steps to add the library in your Swift project:
- Add AeroGearOAuth2 as a submodule in your project. Open a terminal and navigate to your project directory. Then enter:
git submodule add https://github.com/aerogear/aerogear-ios-oauth2.git
- Open the
aerogear-ios-oauth2
folder, and drag theAeroGearOAuth2.xcodeproj
into the file navigator in Xcode. - In Xcode select your application target and under the "Targets" heading section, ensure that the 'iOS Deployment Target' matches the application target of AeroGearOAuth2.framework (Currently set to 8.0).
- Select the "Build Phases" heading section, expand the "Target Dependencies" group and add
AeroGearOAuth2.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 addAeroGearOAuth2.framework
.
For more details about the current release, please consult our documentation.
If you would like to help develop AeroGear you can join our developer's mailing list, join #aerogear on Freenode, or shout at us on Twitter @aerogears.
Also takes some time and skim the contributor guide
Join our user mailing list for any questions or help! We really hope you enjoy app development with AeroGear!
If you found a bug please create a ticket for us on Jira with some steps to reproduce it.