Integrating Microsoft Accounts

This topic explains how to allow your users to sign up for and log in to your mobile app with their Microsoft 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 Live integration

Creating a Live application

To get started, you first need to create a Live application and get your Live client ID and client secret. For the detailed instructions, see the Microsoft official documentation.

You will need to fill in the following information.

  • Application Name
  • Language

When your Live application is created, you will get a Live client ID and client secret.

Next, please configure your application. In "Redirect URL", please specify the value that corresponds to the server location you've selected (please put your AppID in ${your-app-id}).

  • "API Setting" > "Redirect 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

Configuring a Kii application

Take the following steps in the developer portal to configure your application by setting your Live client ID and client secret.

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

  2. Click "SOCIAL NETWORKS".

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

  4. Set your Live client ID and client secret.

Logging in with a Microsoft account

Here is the sample code for letting a new user log in with their Microsoft 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: .Live, 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:kiiConnectorLive
                  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 Microsoft 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(.Live)! 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:kiiConnectorLive];

// 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"];