Integrating Yahoo Accounts

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

Creating a Yahoo application

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

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

  • Application Name
  • Application Type (Please specify "Web-based" here)
  • Description
  • Home Page URL
  • Access Scopes (Please specify "This app requires access to private user data" here)
  • Callback Domain

    • United States: https://${your-app-id}.us.kiiapps.com
    • Japan: https://${your-app-id}.jp.kiiapps.com
    • China: https://${your-app-id}.cn3.kiiapps.com
    • Singapore: https://${your-app-id}.sg.kiiapps.com
    • Europe: https://${your-app-id}.eu.kiiapps.com
  • Select APIs for private user data access (Please specify "Contacts" here)

When your Yahoo application is created, you will get a Yahoo consumer key and consumer secret.

Configuring a Kii application

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

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

  2. Click "SOCIAL NETWORKS".

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

  4. Set your Yahoo consumer key and consumer secret.

Logging in with a Yahoo account

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

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