Integrating LinkedIn Accounts

This topic explains how to allow your users to sign up for and log in to your mobile app with their LinkedIn account. Just add a few parameters in the developer portal and a few lines of code in your mobile app and you will be social-ready!

Configuring LinkedIn integration

Creating a LinkedIn application

To get started, you first need to create a LinkedIn application and get your LinkedIn API key and secret key. For the detailed instructions, see the LinkedIn official documentation.

You will need to fill in the following information. In the "OAuth 2.0 Redirection URL", please specify the value that corresponds to the server location you've selected (please put your AppID in ${your-app-id}).:

  • Company name
  • Application name
  • Application description
  • Website URL
  • Application Use
  • Live Status
  • Developer Contact Email
  • Developer Phone
  • OAuth User Agreement
    • Default Scope (Make sure to select "r_basicprofile")
    • Agreement Language
    • OAuth 2.0 Redirection URL:
      • United States: https://${your-app-id}.us.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback
      • Japan: https://${your-app-id}.jp.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback
      • China: https://${your-app-id}.cn3.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback
      • Singapore: https://${your-app-id}.sg.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback
      • Europe: https://${your-app-id}.eu.kiiapps.com/api/apps/${your-app-id}/integration/webauth/callback

When your LinkedIn application is created, you will get a LinkedIn API key and secret key.

Configuring a Kii application

Take the following steps in the developer portal to configure your application by setting your LinkedIn API key and secret key.

  1. Click on the "Edit" button in your application console in the developer portal.

  2. Click "SOCIAL NETWORKS".

  3. Click "LinkedIn" to open the configuration screen for LinkedIn.

  4. Set your LinkedIn API key and secret key.

Logging in with a LinkedIn account

Here is the sample code for letting a new user log in with their LinkedIn account:

Swift 3:

func myRegistrationMethod(){
  // Set options to nil to indicate that SDK will handle the UI
  let options : Dictionary<String,AnyObject>? = nil

  //Login

  KiiSocialConnect.log(in: .LinkedIn, options: options) { (retUser :KiiUser?, provider : KiiConnectorProvider, retError : Error? ) -> Void in
    if (retError != nil) {
      // Handle the error.
      return
    }
    // The user has logged in successfully
  }
}

Objective-C:

- (void)myRegistrationMethod {
  // Set options to nil to indicate that SDK will handle the UI
  NSDictionary *options = nil;

  // Login.
  [KiiSocialConnect logIn:kiiConnectorLinkedIn
                  options:options
                    block:^(KiiUser *retUser, KiiConnectorProvider provider, NSError *retError) {
    if (retError != nil) {
      // Handle the error.
      return;
    }
    // The user has logged in successfully
  }];
}

The basic steps are as follows.

  1. Set nil to options to specify the authentication mechanism.
  2. Authenticate the user with the logIn:options:block: method. If the specified LinkedIn account is new to Kii Cloud, the user is registered before the login. The logIn:options:block: method is non-blocking and receives the processing result with the callback method.

If the login is successful, the user is cached inside the SDK as the current user and you can get the user information with the currentUser method. You can also retrieve the access token and related parameters with the accessTokenDictionary: method as follows:

Swift 3:

let dict  = KiiSocialConnect.accessTokenDictionary(.LinkedIn)! as NSDictionary

// The access token.
let accessToken = (dict.object(forKey: "oauth_token") as? String)!

// User id provided by the social network provider.
let providerUserId = (dict.object(forKey: "provider_user_id") as? String)!

// If a new Kii user is created with the logIn method.
let kiiNewUser : Bool = (dict.object(forKey: "kii_new_user") as? NSNumber)!.boolValue

Objective-C:

NSDictionary *dict = [KiiSocialConnect accessTokenDictionary:kiiConnectorLinkedIn];

// The access token.
NSString *accessToken = [dict objectForKey:@"oauth_token"];

// User id provided by the social network provider.
NSString *providerUserId = [dict objectForKey:@"provider_user_id"];

// If a new Kii user is created with the logIn method.
BOOL kiiNewUser = [dict valueForKey:@"kii_new_user"];