Skip to content

Latest commit

History

History
114 lines (79 loc) 路 4.53 KB

README.md

File metadata and controls

114 lines (79 loc) 路 4.53 KB

Documentation

CONNECT ID iOS SDK documentation

Get notified of releases and changes

Please use the GitHub Watch feature to get notified on new releases of the SDK, at the top of the page.

Hello World app using the SDK

TelenorConnectIosHelloWorld

Implements the API's for docs.telenordigital.com/apis/connect/id/authentication.html.

Adding the library to your project

To add the library in your project, you can either use CocoaPods or manual install in your project.

Using CocoaPods

In your Podfile add:

pod 'TDConnectIosSdk'

and then:

pod install

to install your dependencies

Manual Installation

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

  1. Add TDConnectIosSdk as a submodule in your project. Open a terminal and navigate to your project directory. Then enter:
git submodule add https://github.com/telenordigital/connect-ios-sdk.git
  1. Open the connect-ios-sdk folder, and drag the TDConnectIosSdk.xcodeproj into the file navigator in Xcode.
  2. In Xcode select your application target and under the "Targets" heading section, ensure that the 'iOS Deployment Target' matches the application target of TDConnectIosSdk.framework (Currently set to 8.0).
  3. Select the "Build Phases" heading section, expand the "Target Dependencies" group and add TDConnectIosSdk.framework.
  4. 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 TDConnectIosSdk.framework.

Using Carthage

Create Cartfile in your project that contains

github "telenordigital/connect-ios-sdk"

Because the SDK project manages it's depencies with Cocoapods you will have to install the SDK depencies with Cocoapod locally, even though you don't have to use it for your project

carthage update # this will give an error but will generate the files needed
cd Carthage/Checkouts/connect-ios-sdk
pod install
cd ../../..
carthage update

Note: Make sure you have the latest version of Cocoapods (1.4.0 at the time of writing)

Advanced Usage

Confidential Client

To set the SDK to Confidential Client mode set the optional init parameter in the Config object named isPublicClient to false. Otherwise it will default to a public client. A confidential client will not exchange the authorization code but simply return this to the client through the callback. The app code can then send this to the server-side component of the client.

See http://docs.telenordigital.com/connect/id/native_apps.html for more information.

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    let config = TelenorConnectConfig(clientId: "telenordigital-connectexample-ios",
                                      redirectUrl: "telenordigital-connectexample-ios://oauth2callback",
                                      useStaging: true,
                                      scopes: ["profile", "openid", "email"],
                                      accountId: "telenor-connect-ios-hello-world",
                                      isPublicClient: false) // this variable needs to be present
    
    let oauth2Module = AccountManager.getAccountBy(config: config)
        ?? AccountManager.addAccountWith(config: self.config, moduleClass: TelenorConnectOAuth2Module.self)
    
    oauth2Module.requestAuthorizationCode { (authorizationCode: AnyObject?, error: NSError?) in
        if (error != nil) {
            // handle error
            return
        }
        
        // use authorizationCode
    }
}

Build, test and play with connect-ios-sdk

  1. Clone this project

  2. Get the dependencies

The project uses CocoaPods 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
  1. open TDConnectIosSdk.xcworkspace

Acknowledgements

OAuth2 Client based on aerogear-ios-http.

Forked from aerogear/aerogear-ios-oauth2.