aerogear-ios-oauth2 Build Status

NOTE: The library has been tested with Xcode 6.3

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.1.0.Final etc…
  • openID Connect login

100% Swift.

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)

Example Usage

OAuth2 grant for GET with a predefined config like Facebook

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

OpenID Connect with Keycloak

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).

Build, test and play with aerogear-ios-oauth2

  1. Clone this project

  2. 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: bash pod install 3. open AeroGearOAuth2.xcworkspace

Adding the library to your project

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

Manual Installation

Follow these steps to add the library in your Swift project:

  1. Add AeroGearOAuth2 as a submodule in your project. Open a terminal and navigate to your project directory. Then enter: bash git submodule add https://github.com/aerogear/aerogear-ios-oauth2.git
  2. Open the aerogear-ios-oauth2 folder, and drag the AeroGearOAuth2.xcodeproj into the file navigator in Xcode.
  3. 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).
  4. Select the Build Phases heading section, expand the Target Dependencies group and add AeroGearOAuth2.framework.
  5. 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 add AeroGearOAuth2.framework.

Documentation

For more details about the current release, please consult our documentation.

Development

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

Questions?

Join our user mailing list for any questions or help! We really hope you enjoy app development with AeroGear!

Found a bug?

If you found a bug please create a ticket for us on Jira with some steps to reproduce it.