Skip to content

Library to implement InfoBip 2 Factor Authentication API. NOTE: This library is neither associated with nor supported by Infobip. API changes may occur at anytime, so I give no guarantees if something breaks or doesn't work. I will do my best to update this library. Bugfixes, improvements, and pull requests are welcome!

License

Notifications You must be signed in to change notification settings

kakashysen/JKInfoBip2FAKit

Repository files navigation

JKInfoBip2FAKit

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Before to run the example project, your should configure a couple of parameters:

  • InfoBipAppToken key In the JKInfoBip2FAKit-Info.plist file, you need to replace your-app-token value for your own API key generated in the infobip platform

  • APPLICATION_ID Add your application id generated in the infobip platform

  • MESSAGE_ID Addd your message id generated in the infobop platform

Requirements

You need to have an account in infobip site platform and generate an API key

Installation and Configuration

JKInfoBip2FAKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "JKInfoBip2FAKit"
  • Configure in the NSAppTransportSecurity the domain infobip.com in your application
<key>NSAppTransportSecurity</key>
<dict>
	<key>NSExceptionDomains</key>
	<dict>
		<key>infobip.com</key>
	<dict>
		<key>NSIncludesSubdomains</key>
		<true/>
		<key>NSExceptionAllowsInsecureHTTPLoads</key>
		<true/>
		<key>NSExceptionRequiresForwardSecrecy</key>
		<true/>
		<key>NSExceptionMinimumTLSVersion</key>
		<string>TLSv1.2</string>
		<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
		<false/>
		<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
		<true/>
		<key>NSThirdPartyExceptionMinimumTLSVersion</key>
		<string>TLSv1.2</string>
		<key>NSRequiresCertificateTransparency</key>
		<false/>
	</dict>
</dict>
  • In the application plist file AppName-Info.plist add the key InfoBipAppToken and the value should be your API Key e.g. App xxxxxxxxxxxxxxxxxxxxxx

  • Create an Application in infobip platform.

  • Create an Message in infobop platform.

After than, use these ids in your application to send request to infobip

Usage

Import JKIB2FARequest.h in your controller header file

#import <JKInfoBip2FAKit/JKIB2FARequest.h>

Add the delegate JKIB2FARequestDelegate

Functions

To use every function you need to create an instance of JKIB2FARequest and asign the delegate to get the results.

JKIB2FARequest *request = [JKIB2FARequest new];
request.delegate = self;

Send SMS

JKIB2FAPinBody *body = [JKIB2FAPinBody new];
#warning change for your test application ID configured in InfoBip
body.applicationId = APPLICATION_ID;//@"your-config-applicationID";
  
#warning change for your test message ID configured in InfoBip
body.messageId = MESSAGE_ID;//@"your-config-messageID";
  
// This parameter should contains the country calling code + phone number
// remember to NOT include the sign (+), this parameter only can contains numbers
#warning change for your test phone number
body.to = _textFieldPhoneNumber.text;
  
[request sendSmsWithPinBody:body];

To get the result implement the follow delegate methods

-(void)sendSmsWithPinBodyDidFinishSuccessful:(JKIB2FAPinResult *)pinResult
{
	if (pinResult.smsStatus == SmsStatusMessageSent)
  {
    NSLog(@"message send successful");
    pinId = pinResult.pinId;
  }
  else
  {
    // You can use pinResult.ncStatus to know the reason why the message was not sent
    NSLog(@"message not send becouse ncStatus");
  }
}
-(void)sendSmsWithPinBodyDidFinishFailure:(JKIB2FAResponseError *)responseError statusCode:(NSInteger)statusCode
{
	// You can use the responseError.text to see message information about the problem
  // and use the statusCode to know the http status code
}

Resend SMS

// the parameter is the pinID generated when your send a sms code
// whith methods sendSmsWithPinBody:
[request resendSmsCodeWithPinId:pinId];

To get the result implement the follow delegate methods

-(void)resendSmsCodeWithPinIdDidFinishSuccessful:(JKIB2FAPinResult *)pinResult
{
  if (pinResult.smsStatus == SmsStatusMessageSent)
  {
    NSLog(@"message resend successful");
    pinId = pinResult.pinId;
  }
  else
  {
    // You can use pinResult.ncStatus to know the reason why the message was not sent
    NSLog(@"message not resend becouse ncStatus");
  }
}
-(void)resendSmsCodeWithPinIdDidFinishFailure:(JKIB2FAResponseError *)responseError statusCode:(NSInteger)statusCode
{
  // You can use the responseError.text to see message information about the problem
  // and use the statusCode to know the http status code
}

Verify Pin Code

// this method need two parameters, the first is the PinID generated when your send a sms code
// whith methods sendSmsWithPinBody:
// The second parameter is the pin code that user receive in the sms message.
[request verifySmsCodeWithPinId:pinId andCode:_textFieldPinCode.text];
-(void)verifySmsCodeWithPinIdDidFinishSuccessful:(JKIB2FAPinVerifyResult *)pinVerifyResult
{
  if (pinVerifyResult.verified)
  {
    // The pin code is valid and the phone number was verified
  }
  else
  {
    // You can use pinVerifyResult.pinError to know the problem
  }
}
-(void)verifySmsCodeWithPinIdDidFinishFailure:(JKIB2FAResponseError *)responseError statusCode:(NSInteger)statusCode
{
  // You can use the responseError.text to see message information about the problem
  // and use the statusCode to know the http status code
}

Author

Jose Aponte

License

JKInfoBip2FAKit is available under the MIT license. See the LICENSE file for more info.

About

Library to implement InfoBip 2 Factor Authentication API. NOTE: This library is neither associated with nor supported by Infobip. API changes may occur at anytime, so I give no guarantees if something breaks or doesn't work. I will do my best to update this library. Bugfixes, improvements, and pull requests are welcome!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published