Skip to main content

iOS Library


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

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.

Requirements

OS X, Xcode and iOS 11 or higher.

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 using CocoaPods for installing the library in a project.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

Podfile

Open a terminal window and navigate to the location of the Xcode project for your application. If you have not already created a Podfile for your application, create one now:

$ pod init

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

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '11.0'
target 'TargetName' do

# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'LoginRadiusSDK', '~> 5.9.0'
end

Then, run the following command:

$ pod install

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

To add LoginRadiusSDK to your project using SwiftPM follow these steps:

  1. Open your project in Xcode
  2. In the main menu, select File > Swift Packages > Add Package Dependency.
  3. In the window, enter the package url: https://github.com/LoginRadius/ios-sdk.git.

To use LoginRadiusSDK in your code, import the module or header files as needed:

#import <LoginRadiusSDK/LoginRadius.h>

Setup Prerequisites

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

  • Configure Email Templates.

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.

Initialize SDK

  1. Create a new File LoginRadius.plist and add it to your App

  2. Add the following entries to your LoginRadius.plist

KeyTypeRequired
apiKeyStringYes
siteNameStringYes
verificationUrlStringOptional,(Default URL: https://auth.lrcontent.com/mobile/verification/index.html)
useKeychain*BooleanOptional, No by default
customDomainStringOptional,(Default URL: https://api.loginradius.com/)
customHeadersDictionaryOptional,(add string type key value pairs, e.g “x-headerkeyExample": “<< header value>>" )
registrationSourceStringOptional,(Default: iOS)
*useKeychain needs to enable keychain sharing to work properly, to see visually how to enable it see here

Obtaining Sitename and API key

Details on obtaining Sitename can be found here and for API key click here

  1. Import the module in your source code.
#import <LoginRadiusSDK/LoginRadius.h>

Swift

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

Application is launched

Initialize the SDK with your API key and Site name in your AppDelegate.m or AppDelegate.swift

//  AppDelegate.m

#import <LoginRadiusSDK/LoginRadius.h>

- (BOOL)application:(UIApplication _)application didFinishLaunchingWithOptions:(NSDictionary _)launchOptions {
LoginRadiusSDK \* sdk = [LoginRadiusSDK instance];
[sdk applicationLaunchedWithOptions:launchOptions];

//Your code

return YES;

}

Application to listen your URL

You need to configure your Custom URL Scheme for this library to work.

  1. In Xcode, right-click on your project's .plist file and select Open As -> Source Code. Default plist is usually your Info.plist file
  2. Insert the following XML snippet into the body of your file just before the final </dict> element. Replace {your-sitename} with your LoginRadius Site Name. And then Replace {your-app-bundle-identifier} with your app's bundle identifier. If you don't know where is your app bundle identifier, see 2a.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>`{your-sitename}.{your-app-bundle-identifier}`</string>
</array>
</dict>
</array>
  1. If you don't know where is your app bundle identifier, see below

How to get bundle identifier in xcode

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 *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
return [[LoginRadiusSDK sharedInstance] application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}

Integrate Registration Service

Registration service supports traditional registration and login methods.

Registration Service is done through the Authentication API.

Registration requires a parameter called SOTT. You can create the SOTT token by following this doc

Parameters and their Description:

NameDescriptionRequired
SOTTSecure One-time Token which you can check information about sott hereYes for Registration. You can generate a long term SOTT token from the Admin Console under Deployment -> Apps -> Mobile Apps (SOTT).
smstemplateSMS template allows you to customize the formatting and text of SMS sent by users who share your content.NO
emailTemplateEmail templates allow you to customize the formatting and text of emails sent by users who share your content. Templates can be text-only, or HTML and text, in which case the user's email client will determine which is displayed.NO Go To API Configuration -> Email Workflow to get the template names

Registration by Email:

NSDictionary *payload=@{ @"Email": @[ @{ @"Type": @"Primary", @"Value": @"[email protected]"}],@"Password": @"password" };

[[AuthenticationAPI authInstance] userRegistrationWithSott:@"<your sott here>" payload:payload emailtemplate:nil smstemplate:nil preventVerificationEmail:false completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {

if (!error) {
// Registration only registers the user. Call login to set the session
NSLog(@"successfully reg %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}

}];

Registration API will only create a user. To retrieve userprofile and access_token, please call Login API.

For all the possible payload fields, please check the Auth User Registration by Email API

Registration by Phone:

NSDictionary *payload=@{ @"PhoneId": @"xxxxxxxxxxx",
@"Password": @"password"
};

[[AuthenticationAPI authInstance] userRegistrationWithSott:@"<your sott here>" payload:payload emailtemplate:nil smstemplate:nil preventVerificationEmail:false completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {

if (!error) {
// Registration only registers the user. Call login to set the session
NSLog(@"successfully reg %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}

}];

Integrate Traditional Login

Following code can be used for the implementation of traditional login:

Login by Email:

Call this function to login the user by email.

NSDictionary *parameter =  @{ @"Email":@"email",
@"Password":@"password",
@"securityanswer":@""
};

[[AuthenticationAPI authInstance] loginWithPayload:parameter loginurl:nil emailtemplate:nil smstemplate:nil g_recaptcha_response:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"successfully logged in %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Login by Phone:

Call this function to login the user by phone.

NSDictionary *parameter =  @{ @"Phone":@"",
@"Password":@"",
@"securityanswer":@""
};
[[AuthenticationAPI authInstance] loginWithPayload:parameter loginurl:nil emailtemplate:nil smstemplate:nil g_recaptcha_response:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"successfully logged in %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Login by UserName:

Call this function to login the user by username.

NSDictionary *parameter =  @{ @"username":@"",
@"Password":@"",
@"securityanswer":@""
};
[[AuthenticationAPI authInstance] loginWithPayload:parameter loginurl:nil emailtemplate:nil smstemplate:nil g_recaptcha_response:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"successfully logged in %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

You can store access_token and userProfile after successful login in LRSession for a long time.

LRSession *session = [[LRSession alloc] initWithAccessToken:access_token userProfile:[[data mutableCopy] replaceNullWithBlank]];

After storing the value, you can get the userProfile and access_token from LRSession.

// Check for `isLoggedIn` on app launch to check if the user is logged in.

NSDictionary *profile = [[[LoginRadiusSDK sharedInstance] session] userProfile];
NSString *access_token = [[[LoginRadiusSDK sharedInstance] session] accessToken];
NSString *alreadyLoggedIn = [[[LoginRadiusSDK sharedInstance] session] isLoggedIn];

Integrate Forgot Password

Following code can used for the implementation of forgot password feature:

Forgot Password by Email

This API is used to send the reset password URL to a specified account. Note: If you have the UserName workflow-enabled, you may replace the 'email' parameter with 'username.' Call this function to send a reset password link to the specified account.

[[AuthenticationAPI authInstance] forgotPasswordWithEmail:@"<your email>" emailtemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Successfully sent email");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Forgot Password By Phone

Call this function to send a reset password link to the specified account.

[[AuthenticationAPI authInstance ] forgotPasswordWithPhone:@"<phone>" smstemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Successfully sent email");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Integrate Social Login

Social Login can be done in two ways.

  1. Web Social Login: This is done using SFSafariViewController or WKWebView.

Note: Facebook and Google no longer allow OAuth requests in embedded browsers on iOS. For Google or Facebook social login to work, you will need to use the Native Social Login implementation method.

  1. Native Social Login

Login is done natively, utilizing the respective provider SDK's.

Web Social Login

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

To integrate Web Social Login. Follow the steps

  • Enable https://auth.lrcontent.com in your site list, please add it under Deployment > Apps > Web Apps for Social Login to work correctly.

  • Whitelist the Apps callback URL where you want to redirect your users after successfuly social login in the Deployment > Apps > Web Apps section of the Admin console. e.g <<LoginRadius Site Name>>.com.loginradius.SwiftDemo://

  • Call loginWithProvider:inController:completionHandler: method with the appropriate params in your Application to start Web Social Login.

    For complete list of social login providers: Ref to this support doc

    Example:

[[LoginRadiusSocialLoginManager sharedInstance] loginWithProvider:@"facebook" inController:self completionHandler:^(NSDictionary *data, NSError *error) {
if (success) {
NSLog(@"Successfully logged in");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Native Social Login

Apple native login

For Native Apple login to work, create and configure your apple app as per loginradius docs.

Apple sign-in is being done by the Xcode inbuild apple authentication services. This is an inbuilt service that provides Sign in with Apple Feature. By adding the Apple sign in from Xcode prebuild libraries, get added, and for implementing apple sign in for IOS, please follow the below steps.

Project Configuration First, set the development team in the Signing & Capabilities tab in your project so Xcode can create a provisioning profile that. If you've already created a project and provisioning profile, then ignore this. After that, click on capability and Add the Sign In with Apple in your project. This will add an entitlement that lets your app use Sign In with Apple.

  • Add Apple Login Button AuthenticationServices framework provides ASAuthorizationAppleIDButton to enables users to initiate the Sign In with Apple flow. Adding this button is very simple. You just need to create an instance of ASAuthorizationAppleIDButton and add a target for touchUpInside action. After that, you can add this button in your view.
let btnAuthorization = ASAuthorizationAppleIDButton()
btnAuthorization.frame = CGRect(x: 0, y: 0, width: 200, height: 40)
btnAuthorization.center = self.view.center
btnAuthorization.addTarget(self, action: #selector(actionHandleAppleSignin), for: .touchUpInside)
self.view.addSubview(btnAuthorization)
  • Handle Login Process Now on the press of Sign In with Apple Button, we need to use a provider (ASAuthorizationAppleIDProvider) to create a request (ASAuthorizationAppleIDRequest), which we then use to initialize a controller (ASAuthorizationController) that performs the request. We can use one or more of ASAuthorization.Scope values in the requested scopes array to request certain contact information from the user.
 // Perform acton on click of Sign in with Apple button
@objc func actionHandleAppleSignin() {
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]

let authorizationController = ASAuthorizationController(authorizationRequests: [request])
authorizationController.delegate = self
authorizationController.presentationContextProvider = self
authorizationController.performRequests()
}
  • ASAuthorizationController Delegate AuthorizationController(controller: didCompleteWithAuthorization:) tells the delegate that authorization completed successfully.
 // ASAuthorizationControllerDelegate function for successful authorization
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
// Create an account as per your requirement
let appleId = appleIDCredential.user
let appleUserFirstName = appleIDCredential.fullName?.givenName
let appleUserLastName = appleIDCredential.fullName?.familyName
let appleUserEmail = appleIDCredential.email
let appleUserToken = appleIDCredential.authorizationCode as! Data
if let string = String(bytes: appleUserToken, encoding: .utf8) {
print(string)
exchangeAppleToken(code : string)
} else {
print("not a valid UTF-8 sequence")
}
//Write your code
} else if let passwordCredential = authorization.credential as? ASPasswordCredential {
let appleUsername = passwordCredential.user
let applePassword = passwordCredential.password
//Write your code
}
}
  • Exchange LoginRadius Token After getting Authorization Code from Apple you should exchange the code with LoginRadius with a simple LoginRadius Apple Sign in Native API.
func exchangeAppleToken(code : String) {
//@param socialAppName should have unique social app name as a provider in case of multiple social apps for the same provider (eg. apple_<social app name> )

LoginRadiusSocialLoginManager.sharedInstance()?.convertAppleCode(toLRToken:code, withSocialAppName:"", completionHandler: {(data, error) in
if let _ = data
{
//Your Code after LoginRadius Authenticate Apple Code
}else if let err = error
{
//User canceled or errored on LoginRadius Authentication Page
}
})
}

Note:-

In the iOS device, if you want to setup multiple social apps for the same social provider then you can provide a unique app name for that provider.This unique social app name will be passed in the native login as a provider name like : + (eg: "apple_myproduct1" )

For more information regarding the apple setup please look the swift demo

Facebook native login

For Native Facebook login to work, create and configure your Facebook app as per facebook docs.

You don't need to download and integrate the Facebook SDK with your project. It is distributed as a dependency with LoginRadius SDK. Just make sure your Info.plist looks like this.

Facebook Native Login Configuration

If you are using our demo, then go to our AppDelegate.m / AppDelegate.swift and set useFacebookNative to true to display our native facebook ui.

If you are making your app, then proceed to add these lines of codes.

and you are calling application:openURL:sourceApplication:annotation in your AppDelegate.m.

//  AppDelegate.m

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
return [[LoginRadiusSDK sharedInstance] application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}

Replace the values with your Facebook App ID and Display name from your App Settings page in Facebook Developer portal

Call the function to start Facebook Native Login.

//@param socialAppName  should have unique social app name as a provider in case of multiple social apps for the same provider (eg. facebook_<social app name> )

[[LoginRadiusSocialLoginManager sharedInstance] nativeFacebookLoginWithPermissions:@{@"facebookPermissions":@[@"public_profile"]} withSocialAppName:@"" inController:self
completionHandler: ^(NSDictionary *data, NSError *error){
if(error){
[self errorMessage:data error:error];
}else {
NSString *access_token= [data objectForKey:@"access_token"];
NSString *refresh_token= [data objectForKey:@"refresh_token"];
NSLog(@"LR Token%@",access_token);
NSLog(@"LR Refresh Token%@",refresh_token);

}
}];

Twitter native login

As of iOS 11, Twitter Native Login is done through the TwitterKit Library. The TwitterKit library works to perform native login on previous iOS versions.

First, you need to create a Twitter App. Get your Twitter Keys from Twitter Dev Console. Go to your App Page, and you will find the keys under Keys And Access Tokens tab.

Then add "TwitterKit" Library to your iOS Project's Podfile.


pod 'TwitterKit'

You can follow the original guide over at Twitter's documentation

Or follow these steps:

1. Instantiate the TwitterKit in AppDelegate during app launch

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[[TWTRTwitter sharedInstance] startWithConsumerKey:@"Your twitter consumer key" consumerSecret:@"Your twitter consumer SECRET key"];

//Your other Library that needs instantiation, e.g. LoginRadiusSDK
}

2. Add these in your Info.plist


<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>twitterkit-<consumerKey></string>
</array>
</dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>twitter</string>
<string>twitterauth</string>
</array>

3. Linking your UIButton to Twitter Native Login link it with LoginRadius on success

//This is the function call linked to a UIButton, you can add IBAction in here to link with the storyboard
- (void)showNativeTwitterLogin {
[[TWTRTwitter sharedInstance] logInWithCompletion:
^(TWTRSession * _Nullable session, NSError * _Nullable error) {
if (session){
//@param socialAppName should have unique social app name as a provider in case of multiple social apps for the same provider (eg. twitter_<social app name> )

[[LoginRadiusSocialLoginManager sharedInstance] convertTwitterTokenToLRToken:session.authToken twitterSecret:session.authTokenSecret withSocialAppName:@"" inController:self
completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (error){
//User cancelled or errored on LoginRadius Authentication Page
}else{
//Your Code after LoginRadius Authenticate Twitter Token
}
}];
} else if (error){
//User cancelled or errored on Twitter Authentication Page
}
}];
}

4. Add these code to handle Twitter's URL Redirection in AppDelegate

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL canOpen = NO;
canOpen = (canOpen || [[TWTRTwitter sharedInstance] application:app openURL:url options:options]);
canOpen = (canOpen || [[LoginRadiusSDK sharedInstance] application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]);
return canOpen;
}

5. As the final step, handle Twitter log out

- (void)logoutPressed:(id)sender {

[self twitterLogout];
[LoginRadiusSDK logout];

//do your UI logout behaviour, e.g:
[self.navigationController popViewControllerAnimated:YES];
}

- (void) twitterLogout
{
NSArray * twitterSessions;
twitterSessions = [[[Twitter sharedInstance] sessionStore] existingUserSessions];
if (twitterSessions){
for (id session in twitterSessions){
[[[TWTRTwitter sharedInstance] sessionStore] logOutUserID:[session userID]];
}
}
}

We suggest you to OBFUSCATE YOUR KEYS.

Google native login

Google Native Login is done through Google SignIn Library since this is a static library and has problems when you are using CocoaPods with uses_frameworks!, you have to manually install the SDK.

Follow these steps:

  1. For Google SignIn, you would need a configuration file GoogleServices-Info.plist. You can generate one following the steps here.

  2. Drag the GoogleService-Info.plist file you just downloaded into the root of your Xcode project and add it to all targets.

  3. Google SignIn requires a custom URL Scheme to be added to your project. Add it to your Info.plist file. Make sure your URL Schemes in URL Types look like this.

    enter image description here

    Replace {your REVERSED_CLIENT_ID} with value of REVERSED_CLIENT_ID from GoogleServices-Info.plist file.

  4. Add Google Sign In by following the documentation

  5. If you are using our demo, go to our AppDelegate.m / AppDelegate.swift and set useGoogleNative to true to display our native google ui. Our demo already contain all the necessary code to perform native Google Sign in, you just have to uncomment any instance of /* Google Native SignIn <code block> */

    If you are making your own app, proceed to add these lines of codes. You can also see our demo to see the native google sign in action!

  6. Add Google SignIn Library to your Podfile. pod 'Google/SignIn'

  7. Now change your App Delegate's open URL to handle both google native sign in and our default logins

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

BOOL canOpen = NO;

canOpen = [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];

canOpen = (canOpen || [[LoginRadiusSDK sharedInstance]
application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]);

return canOpen;
}

8. You have to exchange the Google token with LoginRadius Token. Call the following function in the SignIn delegate method after successful sign in.

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

BOOL canOpen = NO;

canOpen = [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];

canOpen = (canOpen || [[LoginRadiusSDK sharedInstance]
application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]);

return canOpen;
}

9. As the final step, add the google native signOut on your logout button.

- (IBAction)logoutPressed:(id)sender {

[[GIDSignIn sharedInstance] signOut];

[LoginRadiusSDK logout];
[self.navigationController popViewControllerAnimated:YES];
}

WeChat native login

Firstly you will need to apply for a WeChat ID. The English site is at https://open.wechat.com and the Chinese: https://open.weixin.qq.com. It may only be possible to get the ID using the Chinese site so you will need to enlist the help of a Chinese speaker or Google Translate 😜 There are also two different versions of the SDK, the Chinese and English version.

For Native WeChat login to work, create and configure please look wechat official guide

Wechat Native Login is done through Wechat SignIn Library you can add the library via CocoaPods with use_modular_headers!.

pod 'WechatOpenSDK'

As there are several Objective-C header (.h) files we need to add them to our projects Bridging Header file, just #import "WXApi.h" will suffice.

We also need to add the URL Scheme. Just go to the Info tab in your project and expand URL Types. Add a type with the identifier weixin and the URL Schemes set to the WeChat AppID you got when registering your app.

Finally right click on the Info.plist and edit source to look like so:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

This is necessary because iOS9 limits HTTP access.

Exchange LoginRadius Token After getting Authorization Code from Apple you should exchange the code with LoginRadius with a simple LoginRadius Wechat Native API.

 [[LoginRadiusSocialLoginManager sharedInstance] convertWeChatCodeToLRToken:code completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if(error){
self.completion(nil, error);
}else {
NSString *access_token= [data objectForKey:@"access_token"];
NSString *refresh_token= [data objectForKey:@"refresh_token"];
NSLog(@"LR Token%@",access_token);
NSLog(@"LR Refresh Token%@",refresh_token);
}
}];

For more details please look the WeChat Demo.

Touch ID

LoginRadius SDK provides local authentication with TouchID, if available.

Call the function to start Authentication using TouchID.


[[LRTouchIDAuth sharedInstance] localAuthenticationWithFallbackTitle:@"" completion:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"successfully authenticated with touch id");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

This way, on logout, the access token, and user profile are conserved, and the TouchID UI appears. You can use the TouchID authentication to go to the profile page. You can only do this if the user logged in once using social login or traditional login.

Face ID

Face ID revolutionizes authentication using facial recognition. Biometric authentication for iOS applications is implemented using the Local Authentication Framework. For detailed information, please refer to the following link https://developer.apple.com/documentation/localauthentication/logging_a_user_into_your_app_with_face_id_or_touch_id.

LoginRadius SDK contains a helper named FaceID. You can use this helper to authenticate using facial recognition, to enable the biometric authentication using face id you need to include the NSFaceIDUsageDescription (Privacy - Face ID Usage Description) key in your app’s Info.plist file. Without this key, the system won’t allow your app to use Face ID. The value for this key is a string that the system presents to the user the first time your app attempts to use Face ID.

KeyTypeValue
Privacy - Face ID Usage DescriptionStringThis app uses facial recognition

Please call the following function for facilitating facial recognition:

[[LRFaceIDAuth sharedInstance]localAuthenticationWithFallbackTitle:@""    completion:^(BOOL success, NSError *error) {
if (success){
NSLog(@"Successfully authenticated with Face ID");
[self showProfileController];
}
else{
NSLog(@"Error: %@", [error description]);
}
}];

If you want to validate the type of biometry supported by your device i.e., either FaceID or TouchID, you can use the following code:


- (void) biometryType
{
LAContext *laContext = [[LAContext alloc] init];

NSError *error;

if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {

if (error != NULL) {
NSLog(error.description);
} else {

if (@available(iOS 11.0.1, *)) {
if (laContext.biometryType == LABiometryTypeFaceID) {
//localizedReason = "Unlock using Face ID"
[self showFaceIDLogin];
NSLog(@"FaceId support");

} else if (laContext.biometryType == LABiometryTypeTouchID) {
//localizedReason = "Unlock using Touch ID"
[self showTouchIDLogin];
NSLog(@"TouchId support");

} else {
//localizedReason = "Unlock using Application Passcode"
NSLog(@"No Biometric support");
}

}
}
}
}

Face ID and Touch ID implementation for native iOS applications

Touch ID and Face ID are preferred because these authentication mechanisms let the users access their devices in a secured manner, with minimal efforts. When you adopt the LocalAuthentication framework, you streamline the consumer authentication experience in the typical case while providing a fallback option when biometrics are not available.

Below are the implementation steps to authenticate a user using Face ID or Touch ID :

  1. Login a user with email and password leveraging the LoginRadius Login by Email API in LoginRadius iOS SDK.

  2. After the successful authentication, the Access Token session will be created and validated as per the Access Token lifetime configured for your site.

  3. Now you can leverage the below method to store the token and profile value in the session.

LRSession.init(accessToken:access_token as String, userProfile:data!)
  1. You can make your users authenticate using Touch ID or Face ID each time they open the app, and the session will be continued as per their Access Token lifetime.

  2. To check if the session already exists or not, use the below method:

    let alreadyLoggedIn = LoginRadiusSDK.sharedInstance().session.isLoggedIn
  3. Now you can implement the Touch ID and Face ID Native Code in your mobile application as per your business requirement.

Refer to the documentation here for more information on logging a user into your application with Touch ID or Face ID.

In the success method, that is called after the success of biometric authentication, you can implement the LoginRadius Auth Read all Profiles by Token API and call this API based on the session store token or you may also be able to get the profile as a well using the below method:

NSDictionary *profile = [[[LoginRadiusSDK sharedInstance] session] userProfile];

NSString *access_token = [[[LoginRadiusSDK sharedInstance] session] accessToken];

//We added a small boolean function if you want to check whether the user is logged in or not.

BOOL isUserLoggedIn = [[[LoginRadiusSDK sharedInstance] session] isLoggedIn];

Refer to the following flow for user’s experience while interacting with the application:

  1. User runs the application and needs to login via their credentials (email and password).

  2. User closes the application and visits the application after some time (say 2 days).

  3. After 2 days, the application will ask the user to login again via Face ID or Touch ID.

  4. When a user is successfully authenticated with any of these Biometric Authentication methods, then they can proceed to use the application.

Credential Encryption in Secure Enclave

The Secure Enclave is a hardware-based key manager that’s isolated from the main processor to provide an extra layer of security. Using a secure enclave, we can create the key, securely store the key, and perform operations with the key. Thus makes it difficult for the key to be compromised. For detailed information, please refer to the following link. https://support.apple.com/en-in/guide/security/sec59b0b31ff/web

LoginRadius SDK contains a helper named as SecEnclaveWrapper. You can use this wrapper to encrypt/decrypt sensitive data using Secure Enclave. It provides an extra level of security for Api Credentials inside the SDK using secure enclave encryption, this encryption will encrypt the LoginRadius ApiKey, to enable this encryption you need to set true for setEncryption key into LoginRadius.plist.

KeyTypeValue
setEncryptionBooleanYES

By default, LoginRadius stores ApiKey in a secure enclave but if you want to store access token or some sensitive data. Please call the following function which return the decrypted NSData value :

NSData  *AccessToken = [@<access_token_value>”dataUsingEncoding:NSUTF8StringEncoding];
NSData *DecryptedValue = [[LoginRadiusEncryptor sharedInstance]EncryptDecryptText : AccessToken];
NSString *myString:
myString = [[NSString alloc] initWithData:DecryptedValue encoding:NSASCIIStringEncoding];
NSLog(myString);

IP Address

This code retrieves the IP address of your iPhone.


#include <ifaddrs.h>
#include <arpa/inet.h
#include <net/if.h>
- (NSString *)getIPAddress {
NSString *address = @"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
int success = 0;

// retrieve the current interfaces - returns 0 on success
success = getifaddrs(&interfaces);
if (success == 0) {
// Loop through linked list of interfaces
temp_addr = interfaces;
while(temp_addr != NULL) {
if(temp_addr->ifa_addr->sa_family == AF_INET) {
// Check if interface is en0 which is the wifi connection on the iPhone
if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) {
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
else if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"pdp_ip0"]) {
// Get NSString from C String
address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];
}
}

temp_addr = temp_addr->ifa_next;
}
}

// Free memory
freeifaddrs(interfaces);

return address;
}

Latitude and Longitude

This method retrieves the current latitude and longitude of the location. Add a key NSLocationAlwaysUsageDescription in your info.plist.

KeyTypeValue
Privacy - Location Always Usage DescriptionStringApp required Location

#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.


_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.distanceFilter = kCLDistanceFilterNone;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
[self.locationManager requestWhenInUseAuthorization];{

[_locationManager startUpdatingLocation];
}

}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *location = [locations lastObject];
NSLog(@"lat%f - lon%f", location.coordinate.latitude, location.coordinate.longitude);
[_locationManager stopUpdatingLocation];
}
@end

Device OS Version

This code retrieves the current ios version of your iPhone.

- (void) OSVersion
{
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
NSLog(osVersion);

}

Device Type

This code retrieves the machine code that represents the model of your iPhone, which indicates the type of device you own.


#import <sys/utsname.h>

NSString* deviceName()
{
struct utsname systemInfo;
uname(&systemInfo);

return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}

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.

NSDictionary *profile = [[[LoginRadiusSDK sharedInstance] session] userProfile];
NSString *access_token = [[[LoginRadiusSDK sharedInstance] session] accessToken];

We added a small boolean function if you want to check whether the user is logged in or not.

BOOL isUserLoggedIn = [[[LoginRadiusSDK sharedInstance] session] isLoggedIn];

Single Sign-On

If you have multiple iOS apps and want to have a single sign-on across all of them, here are the steps to do it with the LoginRadius iOS SDK. Under the hood, we use iOS' keychain to do this.

Add this to your LoginRadius.plist for your apps.

KeyTypeValue
useKeychainBOOLYES

Go to your Project Folder -> Capabilities and under Keychain Sharing add your sitename.

How to add sso in xcode

If you are just testing Single Sign-On on LoginRadius' demo apps, you can stop here. All the coding implementation is already done in the demo, and you can just try out the objective c demo and swift demo for the functionality.

If you are creating a fresh new app, continue. For SSO to work, you need to add a few more things to trigger the sign in when the app is moving from background to foreground. Add NSNotification observer on the view controllers that could log the user in. You can see the examples in objective c demo and swift demo.

- (void)viewWillAppear: (BOOL)animated {
[super viewWillAppear: animated];

...

[
[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(showProfileController)
name: UIApplicationWillEnterForegroundNotification
object: nil
];


...
}

- (void)viewWillDisappear: (BOOL)animated {
[super viewWillDisappear: animated];

...

[[NSNotificationCenter defaultCenter] removeObserver: self name: UIApplicationWillEnterForegroundNotification object: nil];

...
}

When the app triggers "UIApplicationWillEnterForegroundNotification" check our accessToken and userProfile to fetch it from the keychain

- (void) showProfileController {
if ([[[LoginRadiusSDK sharedInstance] session] isLoggedIn])
{
//go to vc after user logged in
}else
{
//failed to logged in
}
}

Do this with all your iOS apps that use the same site name.

To make your app, other apps logged out when one of your apps logged out. You need to the same observers to the same events on the viewcontrollers that assumes that the user logged in.

- (void)viewWillAppear: (BOOL)animated {
[super viewWillAppear: animated];

...

[
[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(checkForLogin)
name: UIApplicationWillEnterForegroundNotification
object: nil
];


...
}

- (void)viewWillDisappear: (BOOL)animated {
[super viewWillDisappear: animated];

...

[[NSNotificationCenter defaultCenter] removeObserver: self name: UIApplicationWillEnterForegroundNotification object: nil];

...
}

- (void)setupForm{
BOOL loggedIn = [[[LoginRadiusSDK sharedInstance] session] isLoggedIn];
if (!loggedIn)
{
[self showAlert: @"ERROR" message: @"User is not logged in"];
[self logoutPressed];
return;
}

//do normal logged in view controller behavior
}

LoginRadius API Showcase

This section helps you to explore various API methods of LoginRadius IOS SDK. They can be used to fulfill your identity-based needs related to traditional login, registration, social login, and many more.

Authentication API

This API is used to perform operations on a user account after the user has authenticated himself for the changes to be made. Generally, it is used for front end API calls. Following is the list of methods covered under this API:

Registration By Email

This API creates a user in the database as well as sends a verification email to the user. For all the possible payload fields, please check the Auth User Registration by Email API

NSDictionary *payload=@{ @"Email": @[ @{ @"Type": @"Primary", @"Value": @"[email protected]"}
],@"Password": @"password" };

[[AuthenticationAPI authInstance] userRegistrationWithSott:@"<your sott here>" payload:payload emailtemplate:nil smstemplate:nil preventVerificationEmail:false completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {

if (!error) {
// Registration only registers the user. Call login to set the session
NSLog(@"successfully reg %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}

}];

Note : The referer header is used to determine the registration source from which the user has created the account and is synced in the RegistrationSource field for the user profile. Add the registrationSource entity in the LoginRadius.plist file as follows to change the registration source of the user in IOS SDK.

referer

Login By Email

This API retrieves a copy of the user data based on the Email.

NSDictionary *parameter =  @{ @"Email":@"email",
@"Password":@"password",
@"securityanswer":@""
};

[[AuthenticationAPI authInstance] loginWithPayload:parameter loginurl:nil emailtemplate:nil smstemplate:nil g_recaptcha_response:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"successfully logged in %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Login By Username

This API retrieves a copy of the user data based on the Username.

NSDictionary *parameter =  @{ @"username":@"",
@"Password":@"",
@"securityanswer":@""
};
[[AuthenticationAPI authInstance] loginWithPayload:parameter loginurl:nil emailtemplate:nil smstemplate:nil g_recaptcha_response:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"successfully logged in %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Read Complete User Profile

This API retrieves a copy of the user data based on the access_token.

[[AuthenticationAPI authInstance] profilesWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"success %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Social Identity

This API is called just after account linking API, and it prevents the raas profile of the second account from getting created.

[[AuthenticationAPI authInstance] socialIdentityWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"success %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

This API is called just after account linking API, and it prevents the raas profile of the second account from getting created.

[[AuthenticationAPI authInstance] linkSocialIdentitiesWithAccessToken:@"<access_token>" candidatetoken:@"<candidatetoken>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"successfully Link Account %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];
[[AuthenticationAPI authInstance] unlinkSocialIdentitiesWithAccessToken:@"<access_token>" provider:@"<provider>" providerid:@"<providerid>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"successfully Unlink Account %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Update User Profile

This API is used to update the user profile by the access token. For all the possible payload fields, please check the Auth Update Profile by Token API.

NSDictionary *parameter=   @{
@"FirstName":@"Test",
@"Gender": @"M"
};
[[AuthenticationAPI authInstance] updateProfileWithAccessToken:@"<access_token>" emailtemplate:nil smstemplate:nil payload:parameter completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"success %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Check Email Availability

This API is used to check the email exists or not on your site.

[[AuthenticationAPI authInstance] checkEmailAvailability:@"<email>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"success %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Add Email

This API is used to add additional emails to a user's account.

NSDictionary *parameter =   @{
@"email":@"[email protected]",
@"type":@"Secondary"
};
[[AuthenticationAPI authInstance] addEmailWithAccessToken:@"<access_token>" emailtemplate:nil payload:parameter completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"success %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Verify Email

This API is used to verify the email of the user.

[[AuthenticationAPI authInstance] verifyEmailWithVerificationToken:@"<verificationtoken>" url:nil welcomeemailtemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"success %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Remove Email

This API is used to remove additional emails from a user's account.

[[AuthenticationAPI authInstance] removeEmailWithAccessToken:@"<access_token>" email:@"<email>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"success %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Resend Verification Email

This API resends the verification email to the user.

[[AuthenticationAPI authInstance] resendEmailVerification:@"<email>" emailtemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"success %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Change Password

This API is used to change the account's password based on the previous password.

[[AuthenticationAPI authInstance] changePasswordWithAccessToken:@"<access_token>" oldpassword:@"" newpassword:@"" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"success %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Forgot Password By Email Or UserName

This API is used to send the reset password URL to a specified account. Note: If you have the UserName workflow-enabled, you may replace the 'email' parameter with 'username.'

[[AuthenticationAPI authInstance] forgotPasswordWithEmail:@"<your email>" emailtemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Validate Access Token

This api validates the access token, if valid, then returns a response with its expiry otherwise error.

[[AuthenticationAPI authInstance] validateAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Invalidate Access Token

This api call invalidates the active access token or expires an access token's validity.

[[AuthenticationAPI authInstance] invalidateAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Security Questions By Email

This API is used to retrieve the list of questions that are configured on the respective LoginRadius site.

[[AuthenticationAPI authInstance] getSecurityQuestionsWithEmail:@"<email>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Security Questions By Username

This API is used to retrieve the list of questions that are configured on the respective LoginRadius site.

[[AuthenticationAPI authInstance] getSecurityQuestionsWithUserName:@"<username>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Security Questions By AccessToken

This API is used to retrieve the list of questions that are configured on the respective LoginRadius site.

[[AuthenticationAPI authInstance] getSecurityQuestionsWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Update Security Questions By AccessToken

This API is used to update security questions by the access token.

NSDictionary *securityquestionanswer = @{@"<Put Your Security Question ID>":@"<Put Your Answer>"};
NSDictionary *parameter = @{@"securityquestionanswer":securityquestionanswer};

[[AuthenticationAPI authInstance] updateSecurityQuestionWithAccessToken:@"<access_token>" payload:parameter completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Check Username Availability

This API is used to check the UserName exists or not on your site.

[[AuthenticationAPI authInstance] checkUserNameAvailability:@"<username>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Set or Change Username

This API is used to set or change UserName by the access token.

[[AuthenticationAPI authInstance] changeUserNameWithAccessToken:@"<access_token>" username:@"<username>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset Password By Reset Token

This API is used to set a new password for the specified account.

NSDictionary *parameter =   @{
@"resettoken": @"xxxxxxxxxxxxxxxxxxxx",
@"password": @"xxxxxxxxxxxxx",
@"welcomeemailtemplate": @"",
@"resetpasswordemailtemplate": @""
};
[[AuthenticationAPI authInstance] resetPasswordByResetToken:parameter completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset Password By Security Questions using Email

This API is used to reset the password for the specified account by a security question.

NSDictionary *securityquestionanswer = @{@"<Put Your Security Question ID>":@"<Put Your Answer>"};
NSDictionary *parameter = @{
@"securityanswer": securityquestionanswer,
@"email": @"",
@"password": @"xxxxxxxxxxxxx",
@"resetpasswordemailtemplate": @""
};

[[AuthenticationAPI authInstance] resetPasswordBySecurityAnswer_and_Email:parameter completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset Password By Security Questions using Username

This API is used to reset the password for the specified account by a security question.

NSDictionary *securityquestionanswer = @{@"<Put Your Security Question ID>":@"<Put Your Answer>"};
NSDictionary *parameter = @{
@"securityanswer": securityquestionanswer,
@"username": @"",
@"password": @"xxxxxxxxxxxxx",
@"resetpasswordemailtemplate": @""
};

[[AuthenticationAPI authInstance] resetPasswordBySecurityAnswer_and_UserName:parameter completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Auth Verify Email by OTP

This API is used to verify the email of the user when the OTP Email verification flow is enabled, and please note that you must contact LoginRadius to have this feature enabled.

NSDictionary *securityquestionanswer = @{@"<Put Your Security Question ID>":@"<Put Your Answer>"};
NSDictionary *payload = @{ @"otp":@"",
@"email":@""
};
[[AuthenticationAPI authInstance] verifyEmailByOtpWithPayload:payload url:@"" welcomeemailtemplate:@"" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Auth Reset Password by OTP

This API is used to set a new password for the specified account.

NSDictionary *payload =  @{ @"password":@"xxxxx",
@"email":@"",
@"otp":@"",
@"welcomeemailtemplate":@"",
@"resetpasswordemailtemplate":@""
};

[[AuthenticationAPI authInstance]resetPasswordByOtpWithPayload:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Auth Send Welcome Email

This API will send a welcome email.

[[AuthenticationAPI authInstance]sendWelcomeEmailWithAccessToken:@"<access_token>" welcomeemailtemplate:@""  completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Auth Privacy Policy Accept

This API is used to update the privacy policy stored in the user's profile by providing the access_token of the user accepting the privacy policy.

[[AuthenticationAPI authInstance]privacyPolicyAcceptWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Delete Account

This API is used to delete the account using a delete token.

[[AuthenticationAPI authInstance] deleteAccountWithDeleteToken:@"<deletetoken>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Delete Account with Email confirmation

API deletes the user account by the access token.

[[AuthenticationAPI authInstance] deleteAccountWithEmailConfirmation:@"<access_token>" emailtemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Phone Authentication API

This API is used to perform operations on a user account by Phone after the user has authenticated himself for the changes to be made. Generally, it is used for front end API calls. Following is the list of methods covered under this API:

Registration By Phone

This API registers the new users into your Cloud Directory and triggers the phone verification process. For all the possible payload fields, please check the Auth User Registration by Email API

NSDictionary *payload=@{ @"PhoneId": @"xxxxxxxxxxx",
@"Password": @"password"
};

[[AuthenticationAPI authInstance] userRegistrationWithSott:@"<your sott here>" payload:payload emailtemplate:nil smstemplate:nil preventVerificationEmail:false completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {

if (!error) {
// Registration only registers the user. Call login to set the session
NSLog(@"successfully reg %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}

}];

Login By Phone

This API retrieves a copy of the user data based on the Phone.

NSDictionary *parameter =  @{ @"Phone":@"",
@"Password":@"",
@"securityanswer":@""
};
[[AuthenticationAPI authInstance] loginWithPayload:parameter loginurl:nil emailtemplate:nil smstemplate:nil g_recaptcha_response:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"successfully logged in %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Forgot Password By Phone

This API is used to send the OTP to reset the account password.

[[AuthenticationAPI authInstance ] forgotPasswordWithPhone:@"<phone>" smstemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Phone ResetPassword By Otp

This API is used to reset the password.

NSDictionary *payload =  @{ @"password":@"xxxxx",
@"phone":@"",
@"otp":@"",
@"smstemplate":@"",
@"resetpasswordemailtemplate":@""
};

[[AuthenticationAPI authInstance]phoneResetPasswordByOtpWithPayload:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Check Phone Availability

This API is used to check the Phone Number exists or not on your site.

[[AuthenticationAPI authInstance ] phoneNumberAvailability:@"<phone>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Phone Resend OTP

This API is used to resend a verification OTP to verify a user's Phone Number. The user will receive a verification code that they will need to input.

[[AuthenticationAPI authInstance] resendOtpWithPhone:@"<phone>" smstemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Phone Resend OTP By Access Token

This API is used to resend a verification OTP to verify a user's Phone Number in cases in which an active token already exists.

[[AuthenticationAPI authInstance] resendOtpWithAccessToken:@"<access_token>" smstemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Phone Verify OTP

This API is used to validate the verification code sent to verify a user's phone number.

[[AuthenticationAPI authInstance] phoneVerificationWithOtp:@"<otp>" phone:@"<phone>" smstemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Phone Verify OTP By Token

This API is used to consume the verification code sent to verify a user's phone number. Use this call for front-end purposes in cases where the user is already logged in by passing the user's access token.

[[AuthenticationAPI authInstance] phoneVerificationOtpWithAccessToken:@"<access_token>" otp:@"<otp>" smstemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Security Questions By Phone

This API is used to retrieve the list of questions that are configured on the respective LoginRadius site.

[[AuthenticationAPI authInstance] getSecurityQuestionsWithPhone:@"<phone>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Update Phone

This API is used to update the login Phone Number of users

[[AuthenticationAPI authInstance] phoneNumberUpdateWithAccessToken:@"<access_token>" phone:@"<phone>" smstemplate:nil completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset Password By Security Questions using Phone

This API is used to reset password for the specified account by security question.

NSDictionary *securityquestionanswer = @{@"<Put Your Security Question ID>":@"<Put Your Answer>"};
NSDictionary *parameter = @{
@"securityanswer": securityquestionanswer,
@"phone": @"",
@"password": @"xxxxxxxxxxxxx",
@"resetpasswordemailtemplate": @""
};

[[AuthenticationAPI authInstance] resetPasswordBySecurityAnswer_and_Phone:parameter completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Remove Phone ID by Access Token

This API is used to update the privacy policy stored in the user's profile by providing the access_token of the user accepting the privacy policy.

[[AuthenticationAPI authInstance] removePhoneIDWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"success %@", data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Social API

This API is used to fetch information about the social accounts of the user. It helps to get several type of information such as social profile, status, likes, messages, posts and more. Following are the methods covered under this API:

Social User Profile

The User Profile API is used to get social profile data from the user’s social account after authentication.

[[SocialAPI socialInstance] getUserprofileWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Status

The Status API is used to get the status messages from the user’s social account.

[[SocialAPI socialInstance] getPostWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Contacts

The Contact API is used to get contacts/friends/connections data from the user’s social account. This is one of the APIs that makes up the LoginRadius Friend Invite System. The data will be normalized into LoginRadius’ standard data format. This API requires setting permissions in your LoginRadius Admin Console. Supported Providers: Facebook, Foursquare, Google, LinkedIn, Live, Twitter, Vkontakte, Yahoo

[[SocialAPI socialInstance] getContactWithAccessToken:@"<access_token>" nextcursor:@"<nextcursor>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Album

This API returns the photo albums associated with the passed in access tokens Social Profile. Supported Providers: Facebook, Google, Live, Vkontakte.

[[SocialAPI socialInstance] getAlbumWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Audio

The Audio API is used to get audio files data from the user’s social account. Supported Providers: Live, Vkontakte

[[SocialAPI socialInstance] getAudioWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get CheckIn

The Check In API is used to get check Ins data from the user’s social account. Supported Providers: Facebook, Foursquare, Vkontakte

[[SocialAPI socialInstance] getCheckInWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Company

The Company API is used to get the followed companies data from the user’s social account. Supported Providers: Facebook,LinkedIn

[[SocialAPI socialInstance] getCompanyWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];
[[SocialAPI socialInstance] getEventWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Following

Get the following user list from the user’s social account. Supported Providers: Twitter

[[SocialAPI socialInstance] getFollowingWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Groups

The Group API is used to get group data from the user’s social account. Supported Providers: Facebook, Vkontakte

[[SocialAPI socialInstance] getGroupWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Likes

The Like API is used to get likes data from the user’s social account. Supported Providers: Facebook

[[SocialAPI socialInstance] getLikeWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Mention

The Mention API is used to get mentions data from the user’s social account. Supported Providers: Twitter

[[SocialAPI socialInstance] getMentionWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Photo

The Photo API is used to get photo data from the user’s social account. *Supported Providers:*Facebook, Foursquare, Google, Live, Vkontakte

[[SocialAPI socialInstance] getPhotoWithAccessToken:@"<access_token>" albumid:@"<albumid>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Page

The Page API is used to get the page data from the user’s social account. *Supported Providers:*Facebook, LinkedIn

[[SocialAPI socialInstance] getPageWithAccessToken:@"<access_token>" pagename:@"<pagename>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Video

The Video API is used to get video files data from the user’s social account. *Supported Providers:*Facebook, Google, Live, Vkontakte

[[SocialAPI socialInstance] getVideoWithAccessToken:@"<access_token>" nextcursor:@"" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Post Message

Post Message API is used to post messages to the user’s contacts. *Supported Providers:*Twitter, LinkedIn

[[SocialAPI socialInstance] postMessageWithAccessToken:@"<access_token>" to:@"<to>" subject:@"<subject>" message:@"<message>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Get Posts

The Post API is used to get post message data from the user’s social account. *Supported Providers:*Facebook

[[SocialAPI socialInstance] getPostWithAccessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Status Update

The Status API is used to update the status on the user’s wall *Supported Providers:*Facebook, Twitter, LinkedIn

[[SocialAPI socialInstance] statusPostingWithAccessToken:@"<access_token>" title:@"<title>" url:@"<url>" imageurl:@"imageurl" status:@"status" caption:@"caption" description:@"description" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success %@",data);
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Custom Object API

This API is used to create additional custom fields for user registration. It provides methods for creating, updating and deleting custom objects. Following is the list of methods covered under this API:

Create Custom Object

This API is used to write information in JSON format to the custom object for the specified account.

NSDictionary *parameter =   @{
@"customdata1":@"Store my customdata1 value",
@"customdata2":@"Store my customdata2 value"
};
[[CustomObjectAPI customInstance] createCustomObjectWithObjectName:@"<objectname>" accessToken:@"<access_token>" payload:parameter completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Read Custom Object By Token

This API is used to retrieve the Custom Object data for the specified account.

[[CustomObjectAPI customInstance] getCustomObjectWithObjectName:@"<objectname>" accessToken:@"<access_token>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Read Custom Object By Record ID

This API is used to retrieve the Custom Object data for the specified account.

[[CustomObjectAPI customInstance] getCustomObjectWithObjectRecordId:@"<objectrecordid>" accessToken:@"<access_token>" objectname:@"<objectname>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Update Custom Object

This API is used to update the specified custom object data of the specified account. If the value of updatetype is 'replace', then it will fully replace the custom object with the new custom object, and if the value of updatetype is 'partialreplace', then it will perform an upsert type operation.

NSDictionary *parameter =   @{
@"field1":@"Store my field1 value",
@"field2":@"Store my field2 value"
};
[[CustomObjectAPI customInstance] updateCustomObjectWithObjectName:@"<objectname>" accessToken:@"<access_token>" objectRecordId:@"<objectrecordid>" updatetype:@"<updatetype>" payload:parameter completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Delete Custom Object

This API is used to remove the specified Custom Object data using ObjectRecordId of a specified account.

[[CustomObjectAPI customInstance] deleteCustomObjectWithObjectRecordId:@"<objectrecordid>" accessToken:@"<access_token>" objectname:@"<objectname>" completionHandler:^(NSDictionary * _Nullable data, NSError * _Nullable error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

PIN Authentication API

PIN Authentication is a mechanism for prompting your customers to provide a PIN code as part of your Authentication processes.

Login By PIN

Use this endpoint to allow customers to login by providing their PIN.

NSDictionary *payload=@{ @"pin": @""};
[[PinAuthentication pinAuthInstance] loginWithPin:@"session_token" payload:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Set PIN By PinAuthToken

Use this Endpoint to allow your customers to change their PIN using a PIN Auth Token.

[[PinAuthentication pinAuthInstance] setPinWithPinAuthToken:@"pinauthtoken" pin:@"pin" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Forgot PIN By Email

Use this Endpoint to trigger the Forgot PIN process, where an email is sent to the customer.

[[PinAuthentication pinAuthInstance] forgotPinWithEmail:@"email" emailtemplate:@"emailtemplate" resetpinurl:@"resetpinurl" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Forgot PIN By Phone

Use this Endpoint to trigger the Forgot PIN process, where an SMS is sent to the customer with a One Time Passcode (OTP) to use in order to change their PIN.

[[PinAuthentication pinAuthInstance] forgotPinWithPhone:@"phone" smstemplate:@"smstemplate"  completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Forgot PIN By UserName

Use this Endpoint to trigger the Forgot PIN process, where an email is sent to the customer.

[[PinAuthentication pinAuthInstance] forgotPinWithUserName:@"username" emailtemplate:@"emailtemplate" resetpinurl:@"resetpinurl" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Invalidate PIN Session Token

Use this endpoint to invalidate session tokens that have been created as part of the PIN workflows.

[[PinAuthentication pinAuthInstance] invalidatePinSessionToken:@"session_token" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset PIN By Email and OTP

Use this Endpoint to complete the forgot PIN Process by setting a new PIN on the account by providing the Email and OTP.

NSDictionary *payload=@{ @"pin": @"",
@"otp":@"",
@"email":@""
};
[[PinAuthentication pinAuthInstance] resetPinWithEmailAndOtp:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset PIN By UserName and OTP

Use this Endpoint to complete the forgot PIN Process by setting a new PIN on the account by providing the username and OTP.

NSDictionary *payload=@{ @"pin": @"",
@"otp":@"",
@"username":@""
};
[[PinAuthentication pinAuthInstance] resetPinWithUserNameAndOtp:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset PIN By Phone and OTP

Use this Endpoint to complete the forgot PIN Process by setting a new PIN on the account by providing the Phone and OTP.

NSDictionary *payload=@{ @"pin": @"",
@"otp":@"",
@"phone":@""
};
[[PinAuthentication pinAuthInstance] resetPinWithPhoneAndOtp:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset PIN By ResetToken

Use this Endpoint to complete the forgot PIN Process by setting a new PIN on the account by providing the ResetToken.

NSDictionary *payload=@{ @"pin": @"",
@"ResetToken":@""
};
[[PinAuthentication pinAuthInstance] resetPinWithResetToken:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset PIN By ResetToken

Use this Endpoint to complete the forgot PIN Process by setting a new PIN on the account by providing the ResetToken.

NSDictionary *payload=@{ @"pin": @"",
@"ResetToken":@""
};
[[PinAuthentication pinAuthInstance] resetPinWithResetToken:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset PIN By SecurityAnswer and Email

Use this Endpoint to complete the forgot PIN Process by setting a new PIN on the account by providing the SecurityAnswer and Email on the account.

NSDictionary *payload=@{ @"pin": @"",
@"email":@"",
@"securityanswer":@""
};
[[PinAuthentication pinAuthInstance] resetPinWithSecurityAnswerAndEmail:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset PIN By SecurityAnswer and UserName

Use this Endpoint to complete the forgot PIN Process by setting a new PIN on the account by providing the SecurityAnswer and UserName on the account.

NSDictionary *payload=@{ @"pin": @"",
@"username":@"",
@"securityanswer":@""
};
[[PinAuthentication pinAuthInstance] resetPinWithSecurityAnswerAndUserName:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Reset PIN By SecurityAnswer and Phone

Use this Endpoint to complete the forgot PIN Process by setting a new PIN on the account by providing the SecurityAnswer and Phone on the account.

NSDictionary *payload=@{ @"pin": @"",
@"phone":@"",
@"securityanswer":@""
};
[[PinAuthentication pinAuthInstance] resetPinWithSecurityAnswerAndPhone:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Change PIN By Access Token

Use this Endpoint to allow the customer to change their PIN (Provided that they know the existing PIN) and are logged in with a valid access_token.

NSDictionary *payload=@{ @"oldpin": @"",
@"newpin":@""
};
[[PinAuthentication pinAuthInstance] changePinWithAccessToken:@"access_token" payload:payload completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

One Touch Login API

This API is used to simplify the registration process to the minimum steps. It is really useful when there is a need to avoid hassles related to user registration. Following is the list of methods covered under this API:

One Touch Login by Email

This API is used to send a link to a specified email for a frictionless login/registration.

NSDictionary *payload =  @{ @"clientguid":@"",
@"email":@"",
@"name":@"",
@"qq_captcha_ticket":@"",
@"qq_captcha_randstr":@"",
@"g-recaptcha-response":@""
};

[[OneTouchLoginAPI oneTouchInstance] oneTouchLoginEmailWithPayload:payload redirecturl:@"" onetouchloginemailtemplate:@"" welcomeemailtemplate:@"" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

One Touch Login by Phone

This API is used to send one time password to a given phone number for a frictionless login/registration.

NSDictionary *payload =  @{
@"phone":@"",
@"name":@"",
@"qq_captcha_ticket":@"",
@"qq_captcha_randstr":@"",
@"g-recaptcha-response":@""
};

[[OneTouchLoginAPI oneTouchInstance] oneTouchLoginPhoneWithPayload:payload smstemplate:@"" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

One Touch Email Verification

This API verifies the provided token for One Touch Login.

[[OneTouchLoginAPI oneTouchInstance] oneToucEmailVerificationWithVerificationtoken:@"<verificationtoken>" welcomeemailtemplate:@"" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

One Touch OTP Verification

This API is used to verify the otp for One Touch Login.

[[OneTouchLoginAPI oneTouchInstance] oneTouchLoginVerificationWithOtp:@"<otp>" phone:@"<phone>" smstemplate:@""  completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

One Touch Login Ping

This API is used to check if the One Touch Login link has been clicked or not.

[[OneTouchLoginAPI oneTouchInstance] oneTouchLoginPingWithClientguid:@"<clientguid>" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Smart Login API

The LoginRadius Smart Login set of APIs that do not require a password to login and are designed to help you delegate the authentication process to a different device. This type of Authentication workflow while not limited to, is common among Smart TV apps, Smart Phone Apps and IoT devices. Following is the list of methods covered under this API:

Smart Login By Email

This API sends a Smart Login link to the user's Email Id.

[[SmartLoginAPI smartLoginInstance] smartLoginWithEmail:@"<email>" clientguid:@"" smartloginemailtemplate:@"" welcomeemailtemplate:@"" redirecturl:@"" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Smart Login By UserName

This API sends auto login link to the user's Email Id.

[[SmartLoginAPI smartLoginInstance] smartLoginWithUsername:@"username" clientguid:@"" smartloginemailtemplate:@"" welcomeemailtemplate:@"" redirecturl:@"" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Smart Login Ping

This API is used to check if the Smart Login link has been clicked or not.

[[SmartLoginAPI smartLoginInstance] smartLoginPingWithClientguid:@"clientguid" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Smart Login Verify Token

This API verifies the provided token for Smart Login.

[[SmartLoginAPI smartLoginInstance] smartAutoLoginWithVerificationToken:@"verificationtoken" welcomeemailtemplate:@"" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Passwordless Login API

This API is used for implementing Passwordless login. It includes methods for sending instant login links through email and username. Also, they allow to verify those links. Following is the list of methods covered under this API:

Passwordless Login By Email

This API is used to send a Passwordless Login verification link to the provided Email ID.

[[PasswordlessLoginAPI passwordlessInstance] passwordlessLoginWithEmail:@"<email>" passwordlesslogintemplate:@"" verificationurl:@"" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Passwordless Login By Username

This API is used to send a Passwordless Login Verification Link to a user by providing their UserName.

[[PasswordlessLoginAPI passwordlessInstance] passwordlessLoginWithUserName:@"<username>" passwordlesslogintemplate:@"" verificationurl:@"" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Passwordless Login Verification

This API is used to verify the Passwordless Login verification link.

[[PasswordlessLoginAPI passwordlessInstance] passwordlessLoginVerificationWithVerificationToken:@"verificationtoken" welcomeemailtemplate:@""  completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Phone Send OTP

This API can be used to send a One-time Passcode (OTP) provided that the account has a verified PhoneID.

[[PasswordlessLoginAPI passwordlessInstance] passwordlessLoginSendOtpWithPhone:@"<phone>" smstemplate:@""  completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Phone Login Using OTP

This API verifies an account by OTP and allows the user to login.

NSDictionary *securityquestionanswer = @{@"<Put Your Security Question ID>":@"<Put Your Answer>"};
NSDictionary *payload = @{ @"phone":@"",
@"otp":@"",
@"g-recaptcha-response":@"",
@"qq_captcha_ticket":@"",
@"qq_captcha_response":@"",
@"securityanswer":securityquestionanswer,
};

[[PasswordlessLoginAPI passwordlessInstance] passwordlessPhoneLoginWithPayload:payload smstemplate:@"" completionHandler:^(NSDictionary *data, NSError * error) {
if (!error) {
NSLog(@"Success");
} else {
NSLog(@"Error: %@", [error description]);
}
}];

Configuration API

This API is used to get information about the configuration on the LoginRadius site. Following is the method covered in this API:

ConfigurationAPI.configInstance().getConfigurationSchema { data, error in
if let err = error {
print(err.localizedDescription)
} else {
// To set LoginRadius Schema (The one that you configured in the LoginRadius Admin Console) through:

LoginRadiusSchema.sharedInstance().setSchema(data!)

// To get LoginRadius Social schema (The one that you configured in the LoginRadius Admin Console) through:

if let providersObj = data!["SocialSchema"]{

let fields:[LoginRadiusField] = LoginRadiusSchema.sharedInstance().providers!
let providersList: NSMutableArray = NSMutableArray()
for field in fields{
providersList.add(field.providerName)
}

print(providersList as![String])

// To get LoginRadius Registration schema (The one that you configured in the LoginRadius Admin Console) through:

let rFields:[LoginRadiusField] = LoginRadiusSchema.sharedInstance().fields!

print("Success",rFields);
}
}
}

You can access the LoginRadius Registration schema (The one that you configured in the LoginRadius Admin Console) through:

NSArray<LoginRadiusField *> *rFields = [LoginRadiusSchema sharedInstance].fields;

Demo

Link to Demo app

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

Steps to setup Demo apps.

  • Clone the SDK repo. Link
  • Run pod install
  • Create a plist file named LoginRadius.plist and add it to the demo project.
  • Add your Sitename and API key in LoginRadius.plist
  • For Native social login to work follow the Social Login guide above.