LoginRadius API Documentation

Developers, we have compiled these comprehensive guides and documentation to help you work with the LoginRadius API in ways that will meet your company’s requirements as quickly and efficiently as possible. On this page, you will find essential documentation on getting started, process flows and comprehensive guides for implementing various platform features, our SDK libraries and much more!

Get Started

iOS Library

This document provides instructions to integrate the LoginRadius User Registration Service or Social Login in an iOS app.

Disclaimer

This library is meant to help you with a quick implementation of the LoginRadius platform and also to serve as a reference point for the LoginRadius API. Keep in mind that it is an open source library, which means you are free to download and customize the library functions based on your specific application needs.

This release has breaking changes from the previous SDK.

This version is a complete revamp of the previous SDK. Please refer to the changelog for a complete list of changes and improvements.

Installation

We recommend to use CocoaPods for installing the library in a project.

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like AFNetworking in your projects. See the "Getting Started" guide for more information. You can install it with the following command:

$ gem install cocoapods

Podfile

To integrate LRSDK into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target 'TargetName' do
pod 'LRSDK', '~> 3.2.0'
end

Then, run the following command:

$ pod install

Configure Your LoginRadius Account

To get your app supported by LoginRadius IOS SDK, you need to slightly configure your LoginRadius user account.

  • Enable cdn.loginradius.com in your site list

Since this page is hosted in cdn.loginradius.com, please put it under your website URL list in Site Settings

Configure Registration Service

For configuring user registration service please refer to this doc.

Configure Social Login

For Social login configuration please refer to this doc.

Configure Email Templates

By default your email template should look like this:

Change the following url

"#Url#?vtype=emailverification&vtoken=#GUID#"

to

"#Url#?vtype=emailverification&vtoken=#GUID#&apikey=<Your-LoginRadius-API-Key>"

And the same changes should also be applied to your "Reset Password Email Template Configuration".

For more customization please refer to this doc.

Initailize SDK

  • Import the module in your source code.
#import <LRSDK/LRSDK.h>

Swift

For Swift projects, you need to create an Objective-C Bridging Header, please check Apple Documentation

Application is launched

Initilize the SDK with your API key and Site name in your AppDelegate.m

Obtaining Sitename and API key

Details on obtaining Sitename here and API key here

#import <LRSDK/LRSDK.h>
//  AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
	[LoginRadiusSDK instanceWithAPIKey:<your api key>
	                          siteName:<your site name>
	                       application:application
	                     launchOptions:launchOptions];
	//Your code
	return YES;
}

Application is asked to open URL

Call this to handle URL's for social login to work properly in your AppDelegate.m

//  AppDelegate.m

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return  [[LoginRadiusSDK sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}
```

Integrate Registration Service

Registration service supports traditional registration and login methods using hosted pages.
Call this function in the view controller you have setup for the button views.

Supported Actions

Supported actions are

  • login - to show login interface
  • registration - to show the registration form as per your configuration
  • forgotpassword - to show forgot password interface
  • social - to show a list of social login providers for login

Example using login action:


/*
	Registration Service with the action
	@param action - user registration action should be one of these @"login", 	@"registration", @"forgotpassword", @"social"
	@param controller - view controller where user registration actions take place should not be nil
	@param handler - code block executed after completion
 */

[LoginRadiusSDK registrationServiceWithAction:@"login" inController:self
completionHandler:^(BOOL success, NSError *error) {
	if (success) {
		NSLog(@"successfully logged in");
	} else {
		NSLog(@"Error: %@", [error description]);
	}
}];

Missing fields

It is very common that a social ID provider does not return all of the fields you specified in your LoginRadius dashboard, and twitter does not return "Email" field. This situation has been handled in the SDK, if there are missing fields and our system finds it after the user logs in, it will popup a form asking for the missing fields.

Customize Your Form

If you want a customized form so it is closer to your colour scheme or culture, you can contact us at support@loginradius.com, since all the forms are essentially HTML and CSS, you can host the central mobile page yourself as well, and give it a different outlooking.

Language Support

The user registration system supports the following languages:

English - https://cdn.loginradius.com/hub/prod/Theme/mobile/index.html
Spanish - https://cdn.loginradius.com/hub/prod/Theme/mobile-spanish/index.html
German - https://cdn.loginradius.com/hub/prod/Theme/mobile-german/index.html
French - https://cdn.loginradius.com/hub/prod/Theme/mobile-french/index.html

By default the language is set to english you can set the language to the above supported languages
by calling for example [LoginRadiusSDK sharedInstance].appLanguage = @"es"; to set the language to spanish. Set this to @"de" for german and @"fr" for french after SDK initialization.

Check the demo apps for sample user registration service implementation.

Integrate Social Login

Social Login with the given provider. Call this function in the view controller you have setup for the button views.

Provider name is uncapitalized. e.g facebook, twitter, linkedin, google e.t.c
For complete list of social login providers: Ref to this support doc

/*	@param provider - provider name
	@param parameters - dict of parameters
			These are the valid keys
			- facebookPermissions : should be an array of strings
			- facebookLoginBehavior : should be FBSDKLoginBehaviorNative / FBSDKLoginBehaviorBrowser / FBSDKLoginBehaviorSystemAccount / FBSDKLoginBehaviorWeb
				recommended approach is to use FBSDKLoginBehaviorSystemAccount
	@param controller - view controller where social login take place should not be nil
	@param handler - code block executed after completion
 
	@note Params are only valid when native login is configured, otherwise the settings configured in the user account
		are taken
*/

[LoginRadiusSDK socialLoginWithProvider:@"facebook" parameters:nil inController:self completionHandler:^(BOOL success, NSError *error) {
	if (success) {
		NSLog(@"successfully logged in with facebook");
	} else {
		NSLog(@"Error: %@", [error description]);
	}
}];

Native social login

Native Social Login

LoginRadius iOS SDK only supports Facebook & Twitter native login.

By default all social authentication will be done using Safari, if you want native integration set useNativeSocialLogin to YES after SDK initilisation
[LoginRadiusSDK sharedInstance].useNativeSocialLogin = YES;

Facebook native login

For Native facebook login to work, configure the Xcode project as per the facebook docs. https://developers.facebook.com/docs/ios/getting-started#xcode

Twitter native login

For Native Twitter login to work, add these keys to Info.plist.

    <key>TWITTER_CONSUMER_KEY</key>
    <string>your twitter consumer key</string>
    <key>TWITTER_CONSUMER_SECRET</key>
    <string>your twitter consumer secret</string>

Check the demo app for sample social login implementation

Logout

Log out the user.

[LoginRadiusSDK logout];

Access Token and User Profile

After successful login or social login loginradius access token and user profile can be accessed like this.

NSUserDefaults *lrUser = [NSUserDefaults standardUserDefaults];
NSDictionary *profile =  [lrUser objectForKey:@"lrUserProfile"];
NSString *access_token =  [lrUser objectForKey:@"lrAccessToken"];

// If the user have any linked accounts, you can fetch them.
NSArray *linkedProfiles = [lrUser objectForKey:@"lrUserLinkedProfile"];

Calling API's

You can access the LoginRadius User API's, Social API's using our REST client or your own networking library.

Example using the REST client distributed as part of the library.

To get user's company details with the API

NSUserDefaults *lrUser = [NSUserDefaults standardUserDefaults];
NSString * access_token =  [lrUser objectForKey:@"lrAccessToken"];

  [[LoginRadiusREST sharedInstance] callAPIEndpoint:@"api/v2/company"
                                             method:@"GET"
                                             params:@{
                                                      @"access_token": access_token
                                                     }
                                  completionHandler:^(NSDictionary *data, NSError *error) {
                                      NSLog(@"error %@  data %@", error, data);
                                  }];

Demo

Link to Demo app

The demo app contains implementations of social login and user registration service.

  • Add your Sitename and API key in the AppDelegate.m
  • For Native social login to work follow the Social Login guide above.

iOS Library

This document provides instructions to integrate the LoginRadius User Registration Service or Social Login in an iOS app.