ConcurAPI 0.0.5

ConcurAPI 0.0.5

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Feb 2016

Maintained by Richard Puckett.



 
Depends on:
AFNetworking>= 0
JSONModel>= 0
 

ConcurAPI 0.0.5

  • By
  • Richard Puckett and Lance Hughes

Concur API for Objective C

Overview

To start the OAuth flow, use the beginConcurAuthentication method. Provide your client ID, an array of scope values, a presenting view controller, and a callback handler.

This method will present a single-use viewcontroller containing a UIWebView to the user. The web view will contain a login page hosted by Concur that the user can use to provide his/her username and password directly to Concur in order to authenticate.

If log in is not successful then an error will be returned; otherwise short-lived code (nonce) will be provided to the handler, which it must then exchange for a token. There is no universal way to accomplish this step and so is left to the client code to implement in a way that is appropriate within its own environment. This will often be accomplished by sending the nonce to a client-owned web service which would then be responsible for sending the nonce (along with client's private key) to Concur's code-exchange web service. An example of this is shown in the demo app.

Once the nonce has been successfully exchanged then the client should create an instance of the AccessToken object from the exchange response and pass that into the ConcurClient.

A full demonstration of the process is shown below and is available in the demo app at https://github.com/concurlabs/concur-api-objc-demo.

Set Up

In the application:didFinishLaunchingWithOptions method of your AppDelegate configure CXConcurClient with your client ID and an array consisting of the scopes that you're requesting access for.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    [CXConcurClient.sharedInstance setupWithClientId:@"0123456789ABCDEF0123" scope:@[@"EXPRPT"]];
}

Add application:openURL:options to your AppDelegate if it's not already there, and allow CXConcurClient to attempt to handle the URL passed into your app. If the URL relates to the Concur OAuth login process this method will return true, otherwise it will return NO.

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
    BOOL handled = false;

    handled = [CXConcurClient.sharedInstance handleOpenUrl:url];

    return handled;
}

Login

Communication between CXConcurClient and client code is through a delegate. Once you set your calling code as the delegate you will be notified of significant events as you perform authentication procedures such as logging in and out. Consider that you will want to begin OAuth authentication from a UIViewController:

- (void)viewDidLoad {
    [super viewDidLoad];

    CXConcurClient.sharedInstance.client = [CXConcurClient sharedInstance];

    ...
}

And then at some point, say in response to a sign-in button being pressed, you kick off the OAuth process.

- (IBAction)didTapSignIn:(id)sender {
    [CXConcurClient.sharedinstance login];
}

This will cause the Concur OAuth authentication page to appear on the user's screen, prompt for username and password, and then request permission to access resources on behalf of your application, as determined by which scopes you've specified. Once this has been completed CXConcurClient will invoke the appropriate delegate methods, which will be one of the following:

#pragma mark - ConcurClient Delegate Methods

- (void)onLoginSuccess {
}

- (void)onLoginFailure:(NSError*)error {
}

- (void)onLogoutSuccess {
}

- (void)onLogoutFailure:(NSError*)error {
}