Alipay Login
Documentation
This document describes how to integrate Alipay authorized login on an iOS client.
When the user taps the Alipay login button in the client app, the IDaaS SDK invokes the authorization page in the Alipay app. After the user taps the "Authorize Login" button and authorization succeeds, the Alipay app redirects back to the client app. The IDaaS SDK automatically receives the temporary ticket, takes it to the IDaaS server for authentication, and returns the authentication result to the client app.
Login Flow

Integration flow description
- The user taps the Alipay login button in the app client.
- The app client calls the IDaaS SDK Alipay login method.
- The IDaaS SDK calls the Alipay SDK login method.
- The Alipay SDK opens the Alipay app on the phone and displays the authorization login page.
- The user taps the authorize login button.
- Alipay authorization succeeds, the client app is opened, and the Alipay authorization ticket is carried along. At this point, the IDaaS SDK automatically obtains the Alipay authorization ticket during the invocation.
- IDaaS uses the Alipay authorization ticket to request authentication from the IDaaS server.
- The IDaaS server checks whether a mobile number is bound. If a mobile number is already bound, the IDaaS server authentication succeeds and returns session_token and id_token to the IDaaS SDK.
- The IDaaS SDK returns session_token and id_token to the app client.
- If the IDaaS server finds that no mobile number is bound, it returns a flag indicating that binding or registration is required.
- The IDaaS server displays the binding or registration page.
- The user enters the mobile number, taps get verification code, and completes the slider verification.
- The IDaaS SDK takes the slider verification code to the IDaaS server to request slider verification.
- The IDaaS server verifies the slider successfully and returns a token to the IDaaS SDK.
- The IDaaS SDK uses the token and mobile number to request the IDaaS server to send an SMS verification code.
- The user receives the SMS verification code, fills it in the verification code input box, and taps the bind or register button.
- The IDaaS SDK submits the binding or login data to the IDaaS server.
- Binding or registration succeeds, and the IDaaS server returns session_token and id_token to the IDaaS SDK.
- The IDaaS SDK returns session_token and id_token to the client app.
- The client can use id_token to verify login validity and obtain basic user information.
- The client can use session_token to refresh id_token.
Prerequisites
Create an App on Alipay Open Platform
Log in to the Alipay Open Platform, create your own developer account, refer to the official documentation to create a new app, and wait for approval.
For the Alipay minimal iOS integration guide, please refer to https://opendocs.alipay.com/open/218/sxc60m.
Obtain the App clientID
Log in to the IDaaS Enterprise Center, click "Resources --> Applications", select the relevant application, and you can view it.

Configure the Authentication Source
Log in to the IDaaS Enterprise Center, click "Authentication --> Authentication Source Management --> Alipay".

Click Add Authentication Source, and enter the AppKey and AppSecret obtained after registering the app on the Alipay Open Platform. The channel selection box should be "Mobile Application". Enter a display name.

Click OK to get an authentication source. Switch to "Resources --> Applications", click the newly created app, enter "Login Configuration --> Mobile Application --> Configure", and click the enable button behind the Alipay record.

Select the authentication source you just configured and save.
Add Dependencies
Before integrating Alipay OAuth authorized login, you need to register a developer account on the Alipay Open Platform and have an approved mobile application with the corresponding AppID and AppSecret. After applying for Alipay login and passing the review, you can start the integration.
AFServiceSDK.framework // Alipay SDK packageAdd Main Libraries
AuthnCenter_common_2C.framework
AuthnCenter_Alipay_2C.framework
AuthnCenter_Alipay_2C.bundle // Resource bundleDrag the IDaaS SDK into the project and import it as follows:

Also introduce the Pod dependency:
pod 'JWT', '~> 3.0.0-beta.14'
Target Settings
- The IDaaS SDK minimum supported version is iOS 11.
- Introduce the following package in Framework, Library, and Embedded Content:
AFServiceSDK.frameworkSet the URL scheme in the Info tab under URL Types. Fill it in as shown below; the URL scheme must be concatenated from "alipay" and your Alipay appid (as shown in the figure).


In Xcode, select your project settings, choose the "TARGETS" column, and add alipay and alipayauth in "LSApplicationQueriesSchemes" under the "Info" tab (as shown in the figure).

Set bitcode to NO.

Set Allow Non-modular Includes In Framework Modules to Yes.

Development Integration
Built-in UI Page Integration
This section describes a one-time invocation of Alipay login by the app client. The app client only needs to integrate the IDaaS SDK initialization method and the Alipay registration method, and call the IDaaS SDK Alipay login method where Alipay login needs to be invoked. The remaining authentication, registration, and binding UI flows are fully provided by the IDaaS SDK. After successful login, session_token and id_token are returned in the callback function. Before this section, please complete all Xcode configuration and Alipay Open Platform configuration in the previous chapter.
SDK Initialization
The IDaaS SDK provides an initialization method where you can fill in the tenant, clientID, and whether to enable log printing.
Example of the initialization method:
//Reference the header files in AppDelegate as follows
#import <AuthnCenter_common_2C/BCIDACommonManager.h>
#import <AuthnCenter_Alipay_2C/BCLoginAlipayManager.h>
//Initialize in the didFinishLaunchingWithOptions method
[[[[[BCIDACommonManager sharedInstance] initWithDomain:@"https://your-backend-tenant.com"] initWithClientID:@"your-backend-tenant-clientID"] initWithSSLCerVerification:NO] setLogEnabled:YES] ;
[[BCLoginAlipayManager sharedInstance] registAlipayAppid:@"your-alipay-appid"];In AppDelegate, the following methods receive Alipay scheme callbacks.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
[[BCLoginAlipayManager sharedInstance] oauthHandleOpenURL:url];
return YES;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
[[BCLoginAlipayManager sharedInstance] oauthHandleOpenURL:url];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
[[BCLoginAlipayManager sharedInstance] oauthHandleOpenURL:url];
return YES;
}Brief introduction to the basic configuration initialization main class BCIDACommonManager methods:
/**
* Method name: sharedInstance
* @param none
* @return singleton instance class
*/
+ (instancetype )sharedInstance ;
/**
* Method name: initWithDomain
* @param domain, starting with https:// and ending with .com.
* @return instance class
*/
-(BCIDACommonManager)initWithDomain:(NSString)domain
/**
* Method name: initWithClientID
* @param client id.
* @return instance class
*/
-(BCIDACommonManager)initWithClientID:(NSString)clientID;
/**
* Method name: setLogEnabled
* @param boolean value indicating whether to enable log.
* @return instance class
*/
-(void)setLogEnabled:(BOOL)enable;
/**
* Method name: initWithSSLCerVerification
* @param boolean value setting whether SSL certificate verification is enabled.
* @return instance class
*/
-(BCIDACommonManager*)initWithSSLCerVerification:(bool)sslCerVerification;Brief introduction to the Alipay BCLoginAlipayManager class methods:
/**
* Method name: sharedInstance
* @param none
* @return singleton instance class
*/
+ (instancetype )sharedInstance ;
/**
* Method name: registAlipayAppid
* @param alipayAppid Alipay Open Platform appid
*@return singleton instance class
*/
-(BCLoginAlipayManager*)registAlipayAppid:(NSString*)alipayAppid;
/**
* Method name: oauthHandleOpenURL
* @param call this method when the scheme callback reaches the client app
* @param none
* @return YES/NO
*/
-(BOOL)oauthHandleOpenURL:(NSURL*)urlInitiate Alipay Login
When the user taps the Alipay login button, the app client calls the IDaaS SDK Alipay login method. The code example is as follows:
/**
* Method name: sharedInstance
* @param none
* @return singleton instance class
*/
+ (instancetype )sharedInstance ;
/**
* Method name: registAlipayAppid
* @param alipayAppid Alipay Open Platform appid
*@return singleton instance class
*/
-(BCLoginAlipayManager*)registAlipayAppid:(NSString*)alipayAppid;
/**
* Method name: oauthHandleOpenURL
* @param call this method when the scheme callback reaches the client app
* @param none
* @return YES/NO
*/
-(BOOL)oauthHandleOpenURL:(NSURL*)urlBrief introduction to the BCLoginAlipayManager login object methods:
/**
* Method name: loginWithAlipayWithScheme
* @param invoke Alipay login
* @param schemeStr is the input Alipay appid, format is "alipay" + Alipay appid, e.g. alipay2021002149616573
* @return BCAlipayCompletionHandler callback function.
1. code=0 means success, data returns session_token and id_token
2. code=other means failure, data returns reason description.
*/
-(void)loginWithAlipayWithScheme:(NSString*)schemeStr withCompleteCallBack:(BCAlipayCompletionHandler)callBackHandler;BCAlipayCompletionHandler callback function return codes:
| Code | Description |
|---|---|
| code=0 | Login successful. At this time, data returns NSDictionary: data=@{@"session_token":sessionTokenContent,@"id_token":idTokenContent}; |
| code=1 | Login failed, data returns string describing the error |
| code=error code (please refer to IDaaS return codes) | Login unsuccessful, data returns error description |
| Code=102 | User denied authorization on the Alipay authorization page |
| Code=103 | Alipay authorization returned unsuccessfully, see data description for details |
| Code=104 | After authorization succeeds, on the bind or register phone number page, the user tapped the back button, binding was not completed, and the user returned/cancelled. |
UI Customization

After Alipay authorization succeeds, the binding or quick registration flow is initiated depending on whether the user matches. In the IDaaS Enterprise Center authentication source configuration, set new Alipay users to register upon login. Then quick registration will be performed. (Whether the binding page or quick registration page is displayed depends on the backend authentication source configuration).

The figure above shows the default UI page.
In the didFinishLaunchingWithOptions method of AppDelegate, set the theme object.
Code example:
//Create a style object and set the style of each element; if an element is not set, the default style in the figure above is used
BCAlipayBindPhoneViewCustomSetting* settings=[[BCAlipayBindPhoneViewCustomSetting alloc] init];
settings.isNavHidden=YES;
settings.navHiddenBackButtonFrameBlock = ^CGRect(CGRect frame) {//When isNavHidden=YES, you can set the back button frame
CGRect rec=CGRectMake(5, 150, 70, 40);
return rec;
};
// settings.hideInternationalPhoneCodeArea=YES;
settings.navBindTitle=[[NSAttributedString alloc] initWithString:@"Bind xx"attributes:@{NSForegroundColorAttributeName : UIColor.orangeColor,NSFontAttributeName : [UIFont systemFontOfSize:18.0]}];
settings.navRegistTitle=[[NSAttributedString alloc] initWithString:@"Register xx"attributes:@{NSForegroundColorAttributeName : UIColor.greenColor,NSFontAttributeName : [UIFont systemFontOfSize:18.0]}];
settings.navBackImage=[UIImage imageNamed:@"fanhuianniu-2"];
settings.navColor=@"99FFCC";
UIButton* bttn=[UIButton buttonWithType:UIButtonTypeSystem];
[bttn setTitle:@"More" forState:UIControlStateNormal];
[bttn setTintColor:[UIColor blackColor]];
[bttn addTarget:self action:@selector(clickMore) forControlEvents:UIControlEventTouchUpInside];
settings.navRightView=bttn;
settings.tileDescriptionRegistText=[[NSAttributedString alloc] initWithString:@"Register xx with my mobile number"attributes:@{NSForegroundColorAttributeName : UIColor.orangeColor,NSFontAttributeName : [UIFont systemFontOfSize:25.0]}];
settings.tileDescriptionBindText=[[NSAttributedString alloc] initWithString:@"Bind my mobile number"attributes:@{NSForegroundColorAttributeName : UIColor.greenColor,NSFontAttributeName : [UIFont systemFontOfSize:25.0]}];
settings.descriptionRegistText=[[NSAttributedString alloc] initWithString:@"Enter the mobile number to register..."attributes:@{NSForegroundColorAttributeName : UIColor.grayColor,NSFontAttributeName : [UIFont systemFontOfSize:16.0]}];
settings.descriptionBindText=[[NSAttributedString alloc] initWithString:@"Enter the mobile number to bind..."attributes:@{NSForegroundColorAttributeName : UIColor.redColor,NSFontAttributeName : [UIFont systemFontOfSize:16.0]}];
settings.clickToSendSMSButtonText=[[NSAttributedString alloc] initWithString:@"Get Verxification Code"attributes:@{NSForegroundColorAttributeName : UIColor.greenColor,NSFontAttributeName : [UIFont systemFontOfSize:10.0]}];
// settings.clickToSendBorderColor=@"CCFF33";
settings.clickToSendSMSBackgroundImage=[UIImage imageNamed:@"wangluo"];
// settings.countDownTextColor=@"330000";
settings.countDownBtnBackgroundColor=@"CCCCFF";
settings.countDownBtnBackgroundImage=[UIImage imageNamed:@"lvhang"];
settings.confirmButtonRegistText=@"Register me";
settings.confirmButtonBindText=@"Bind";
settings.confirmButtonInactiveTextColor=@"FF99FF";
settings.confirmButtonActiveTextColor=@"FF9966";
settings.confirmButtonOnPressTextColor=@"FF66FF";
settings.confirmButtonInactiveBackgroundColor=@"999999";
settings.confirmButtonactiveBackgroundColor=@"CC00FF";
// settings.confirmButtonInactiveBackgroundImage=[UIImage imageNamed:@"24gf-stopCircle"];
// settings.confirmButtonActiveBackgroundImage=[UIImage imageNamed:@"24gf-stopCircle-2"];
//After setting these values, save them to memory using the following class.
[[BCAlipayBindPhoneThemeManager sharedInstance] setBindPhoneTheme:settings];Property list:
| Property | Description |
|---|---|
| isNavHidden | Yes: hide the navigation bar, the back button is a UIButton and an image can be passed; NO: do not hide the navigation bar, the back button needs an image. |
| navColor | //Navigation bar theme color NSString, hex, without 0x or #, e.g. FF4F4A |
| navHiddenBackButtonFrameBlock | When isNavHidden=YES, you can set the back button frame |
| navBindTitle | Bind navigation bar title |
| navRegistTitle | Register navigation bar title |
| navBackImage | Navigation bar back image. If isNavHidden=NO and the navigation bar is hidden, then it is a simple back button on the interface: 50x30 on navigation bar, 70x40 without navigation bar. |
| navRightView | Custom UIView on the right side of the navigation bar; a UIButton with events can be passed |
| tileDescriptionRegistText | First title (title of quick registration page), NSString |
| tileDescriptionBindText | First title (title of social login binding number page) |
| descriptionBindText | Description field below the title (title of social login binding number page), NSString |
| descriptionRegistText | Description field below the title (title of registration page) |
| clickToSendSMSButtonText | Send SMS button text |
| clickToSendBorderColor | Send SMS button border color NSString, hex, without 0x or #, e.g. FF4F4A |
| clickToSendSMSBackgroundColor | Send SMS button background color, NSString, hex, without 0x or #, e.g. FF4F4A |
| clickToSendSMSBackgroundImage | Set the background image of the send SMS button; image takes priority, otherwise use the background color above |
| countDownTextColor | Send SMS countdown text color, NSString, hex, without 0x or #, e.g. FF4F4A |
| countDownBtnBackgroundColor | Send SMS countdown background color. NSString, hex, without 0x or #, e.g. FF4F4A |
| countDownBtnBackgroundImage | Send SMS countdown background image; image takes priority, otherwise use the background color above |
| confirmButtonRegistText | Register/confirm button text |
| confirmButtonBindText | Bind/confirm button text |
| confirmButtonInactiveTextColor | Confirm button text color when not clickable, NSString, hex, without 0x or #, e.g. FF4F4A |
| confirmButtonActiveTextColor | Confirm button text color when clickable, NSString, hex, without 0x or #, e.g. FF4F4A |
| confirmButtonOnPressTextColor | Bind/confirm button text color just pressed, NSString, hex, without 0x or #, e.g. FF4F4A |
| confirmButtonInactiveBackgroundColor | Bind/confirm button background color when not clickable, NSString, hex, without 0x or #, e.g. FF4F4A |
| confirmButtonactiveBackgroundColor | Bind/confirm button background color when clickable, NSString, hex, without 0x or #, e.g. FF4F4A |
Each call overrides the theme. If no theme is set, the page uses the default style. If only part of the theme is set, the set parts are saved and unset attributes use the default color style.
API-based Integration Method
This section describes how to integrate Alipay login in API form; the client app needs to build the binding/registration interface.
Call Sequence Description
Project configuration.
Initialize in AppDelegate.
Integrate the Alipay SDK.
Obtain the Alipay authorization ticket code from the callback.
Call the IDaaS SDK Alipay login method.
Jump to the binding or registration page to complete binding or registration.
SDK Initialization
Example of the IDaaS SDK initialization method:
//Reference the header files in AppDelegate as follows
#import <AuthnCenter_common_2C/BCIDACommonManager.h>
//Initialize in the didFinishLaunchingWithOptions method
[[[[[BCIDACommonManager sharedInstance] initWithDomain:@"https://your-backend-tenant.com"] initWithClientID:@"your-backend-tenant-clientID"] initWithSSLCerVerification:NO] setLogEnabled:YES] ;Alipay Login Method
Example of using the Alipay authorization ticket to log in to the IDaaS SDK:
//Call after obtaining the Alipay authorization login ticket code
[[BCAlipayApiLoginManager sharedInstance] loginAlipayByCode:code andWithCallBack:^(NSString * _Nonnull code, id _Nonnull data) {
}];BCAlipayApiLoginManager:
/**
* Method name: sharedInstance
* @param no input parameters
* @return returns the singleton instance
*/
+ (instancetype )sharedInstance ;
/**
* Method name: loginAlipayByCode
* @param code: Alipay authorization login ticket, obtained from the Alipay app scheme callback.
* @return BCAlipayAPILoginCallBackHandler callback function NSString* code, id data.
*/
-(void) loginAlipayByCode:(NSString*)code andWithCallBack: (BCAlipayAPILoginCallBackHandler)callBack;BCAlipayAPILoginCallBackHandler callback function summary:
Success example 1 (successful match returns session_token):
code=0
data=
{
"session_token": "btsiBjx85prcZu6I6Ki057Tmw3nSF2VO",
"id_token": content,
"expire": 432000,//NSNumber type
"status": "SUCCESS"
}
Success example 2 (returns auto-registration and binding flow, refer to section 3.5.3.4):
code=101
data=
{
"state_token": "ey0zMDzKMMZtPBv2VPS8",
"data": "{\"socialBindOrRegisterFlow\":[\"VERIFY_PHONE\",\"VERIFY_EMAIL\"]}",
"status": "USER_REGISTER"
}
Success example 3 (returns binding flow, refer to section 3.5.3.3):
code=101
data=
{
"state_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ7XCJzb2NpYWxVaWRcIjpcIm8zRHVFNVNySXVodTlIZHFucHd0c3Y5a2dkSFFcIixcInN0YXR1c1wiOlwiVVNFUl9SRUdJU1RFUlwifSIsImV4cCI6MTY0NjcwNTcwNCwiaWF0IjoxNjQ2NzAzOTA0LCJqdGkiOiIxNjQ2NzAzOTA0NTEwMCJ9.tLEpS-9jrXwiJI3GlZw4RGg_z0zMDzKMMZtPBv2VPS8",
"data": "{\"socialBindOrRegisterFlow\":[\"VERIFY_PHONE\",\"VERIFY_EMAIL\"]}",
"status": " SOCIAL_BIND"
}
Error example:
code=1
data=
{
"error_code": "IDAAS.SDK.COMMON.1001",
"error_msg": "Parameter X-client-id cannot be left blank."
}Bind or Register Flow Methods
Mobile number regex validation and international area code retrieval
If international number support is enabled, please call the international area code acquisition API first. The API returns the configured list of international area codes with regular expressions for phone numbers. The figure below shows how to configure the list of international area codes.

Sample code to get the international area code list:
#import <AuthnCenter_common_2C/BCIDAInternationalPhoneCodeManager.h>
[BCIDAInternationalPhoneCodeManager getInternaltionalAreaCodeWithCompletionHandler:^(NSString * _Nonnull code, id _Nonnull data) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
NSDictionary* dic=(NSDictionary*)data;
//Check whether the phone number matches the regular expression
BOOL flag= [strongSelf parseDictionary:dic andWithMoile:mobile];
});
}];Main class method introduction:
/**
* Method name: getInternaltionalAreaCodeWithCompletionHandler
* @brief: get international area code method
* @param
*@param
* @param BCSMSGetInternationalAreaCodeHandlerBlock () result callback function code=0, data returns NSDictionary result
**/
+(void)getInternaltionalAreaCodeWithCompletionHandler:(BCSMSGetInternationalAreaCodeHandlerBlock)resultHander;Success example code=0, data value:
{
"phoneAreaCodeDefinitions": [
{
"areaCode": "86",
"displayMapping": {
"zh-TW": "Mainland China",
"en": "China",
"zh-CN": "Mainland China"
},
"countryCode": "CN",
"mobileRegex": "^(\\+86){0,1}\\-?1\\d{10}$",
"areaCodeSuffixes": []
},
{
"areaCode": "852",
"displayMapping": {
"zh-TW": "Hong Kong",
"en": "Hong Kong",
"zh-CN": "Hong Kong"
},
"countryCode": "HK",
"mobileRegex": "^(\\+852){1}\\-?0{0,1}[1,4,5,6,7,8,9](?:\\d{7}|\\d{8}|\\d{12})$",
"areaCodeSuffixes": []
},
{
"areaCode": "886",
"displayMapping": {
"zh-TW": "Taiwan",
"en": "Taiwan",
"zh-CN": "Taiwan"
},
"countryCode": "TW",
"mobileRegex": "^(\\+886){1}\\-?[6,7,9](?:\\d{7}|\\d{8})$",
"areaCodeSuffixes": []
},
{
"areaCode": "853",
"displayMapping": {
"zh-TW": "Macau",
"en": "Macau",
"zh-CN": "Macau"
},
"countryCode": "MO",
"mobileRegex": "^(\\+853){1}\\-?0{0,1}[1,4,5,6,7,8,9](?:\\d{7}|\\d{8}|\\d{12})$",
"areaCodeSuffixes": []
},
{
"areaCode": "93",
"displayMapping": {
"zh-TW": "Afghanistan",
"en": "Afghanistan",
"zh-CN": "Afghanistan"
},
"countryCode": "AF",
"mobileRegex": "^(\\+93){1}\\-\\d{6,11}",
"areaCodeSuffixes": []
}
],
"preferredAreaCode": "CN"
}Return parameters:
| Parameter Name | Chinese Name | Type | Description |
|---|---|---|---|
| preferredAreaCode | Preferred International Dialing Code | String | Preferred international dialing code configured in the current Enterprise Center |
| countryCode | Country/Region Code | String | Country/region code |
| areaCode | International Dialing Code | String | International dialing code |
| areaCodeSuffixes | International Dialing Code Suffix | String | International dialing code suffix |
| mobileRegex | Mobile Number Format Regex | String | Mobile number format regex |
| displayMapping | Multi-language Display Name Mapping | String | Multi-language display name mapping |
Slider Verification
Please check the mobile number format before calling this method.
Tap (trigger) the send verification code event; the app client calls the IDaaS SDK slider verification method as shown below:
//Import the request header
#import <AuthnCenter_Alipay_2C/BCAlipaySlideVerifyCodeManager.h>
//Tap (trigger) the send verification code event
[BCAlipaySlideVerifyCodeManager startSlidingVerifyCodePageWithMobileNumber:mobile andWithResultHandler:^(NSString * _Nonnull code, id _Nonnull data) {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Slider verification result==%@==%@",code,data);
});
}];BCAlipaySlideVerifyCodeManager object method introduction:
/**
* Method name: startSlidingVerifyCodePageWithMobileNumber
* @brief: tap to invoke slider verification
*@ param mobile mobile number: with area code "+86-13800000000" or without area code "13800000000" are both acceptable.
*@param complete: asynchronous result callback:
1. When slider verification succeeds, returns code=0 data=slider token
2. code=other means slider verification failed (refer to error codes)
3. code=105, data="User closed" means the close button of the slider box was tapped
**/
+(void)startSlidingVerifyCodePageWithMobileNumber:(NSString*)mobile andWithResultHandler:(BCAlipaySlideCodeHandlerBlock)resultHandler;When slider verification succeeds with code=0, sample code to send SMS:
alipaySlideSMSSendType type;
if([_status isEqualToString:@"USER_REGISTER"]){
type=alipaySlideSMSRegist;
}else if([_status isEqualToString:@"SOCIAL_BIND"]){
type=alipaySlideSMSBind;
}
[BCAlipaySlideVerifyCodeManager sendSMSWithSlideResultWithToken:token andMobile:mobile andWithType:type andWithCallBack:^(NSString * _Nonnull code, id _Nonnull data) {
if ([code isEqualToString:@"0"]) {
NSLog(@"SMS sent successfully--code=%@ data=%@",code,data);
}else{
NSLog(@"SMS sent failed--code=%@ data=%@",code,data);
}
}];SMS sending object BCAlipaySlideVerifyCodeManager method introduction:
/**
* Method name: sendSMSWithSlideResultWithToken
* @brief: call this method to send SMS,
*@ param token token obtained after slider verification succeeds in the previous method
*@ param mobile mobile number
*@ param mobile (alipaySlideSMSSendType enum) type, obtained from the status field in the Alipay login method,
status= SOCIAL_BIND means binding, here pass type=alipaySlideSMSBind
status= USER_REGISTER means registration, here pass type=alipaySlideSMSRegist
*@param complete: asynchronous result callback. SMS sent successfully returns code=0, code=other means SMS sending failed, please refer to IDaaS error codes and returned data (string error description)
**/
+(void)sendSMSWithSlideResultWithToken:(NSString*)token andMobile:(NSString*)mobile andWithType:(alipaySlideSMSSendType)type andWithCallBack:(BCAlipaySendSMSHandlerBlock)callBack;Bind Method
Alipay login method returns:
Success example 3 (returns binding flow):
code=101
data=
{
"state_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ7XCJzb2NpYWxVaWRcIjpcIm8zRHVFNVNySXVodTlIZHFucHd0c3Y5a2dkSFFcIixcInN0YXR1c1wiOlwiVVNFUl9SRUdJU1RFUlwifSIsImV4cCI6MTY0NjcwNTcwNCwiaWF0IjoxNjQ2NzAzOTA0LCJqdGkiOiIxNjQ2NzAzOTA0NTEwMCJ9.tLEpS-9jrXwiJI3GlZw4RGg_z0zMDzKMMZtPBv2VPS8",
"data": "{\"socialBindOrRegisterFlow\":[\"VERIFY_PHONE\",\"VERIFY_EMAIL\"]}",
"status": " SOCIAL_BIND"
}After the user receives the SMS verification code, fills it in the verification code box, and taps the bind button (or triggers the event), the app client calls the bind method as follows:
[[BCAlipayBindOrRegistManager sharedInstance] alipayBindWithMobile:mobile andWithVerifyCode:verifyCode andWithStateToken:_state_token andWithCompletionHandler:^(NSString * _Nonnull code, id _Nonnull data){
__strong __typeof(weakSelf)strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
});
}];Main class BCAlipayBindOrRegistManager method introduction:
/**
* Method name: sharedInstance
* @param no input parameters
* @return returns the singleton instance
*/
+ (instancetype )sharedInstance ;
/**
* Method name: alipayBindWithMobile
* @brief: binding method after Alipay login
* @param mobile mobile number
*@param StateToken state_token field obtained from the Alipay login method
*@param verifyCode SMS verification code
* @param BCAlipayBindCompleteHandler login result callback function
**/
-(void)alipayBindWithMobile:(NSString*)mobile andWithVerifyCode:(NSString*)verifyCode andWithStateToken: (NSString*)StateToken andWithCompletionHandler:(BCAlipayBindCompleteHandler)completeHandler;BCAlipayBindCompleteHandler callback function return codes:
| Code | Description |
|---|---|
| code=0 | Login successful, data= |
| code=1 | Login failed, data returns string describing error |
| code=error code (please refer to IDaaS return codes) | Login unsuccessful, data returns error description |
Register and Bind Method
When the Alipay login method returns:
Success example 2 (returns auto-registration and binding flow):
code=101
data=
{
"state_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ7XCJzb2NpYWxVaWRcIjpcIm8zRHVFNVNySXVodTlIZHFucHd0c3Y5a2dkSFFcIixcInN0YXR1c1wiOlwiVVNFUl9SRUdJU1RFUlwifSIsImV4cCI6MTY0NjcwNTcwNCwiaWF0IjoxNjQ2NzAzOTA0LCJqdGkiOiIxNjQ2NzAzOTA0NTEwMCJ9.tLEpS-9jrXwiJI3GlZw4RGg_z0zMDzKMMZtPBv2VPS8",
"data": "{\"socialBindOrRegisterFlow\":[\"VERIFY_PHONE\",\"VERIFY_EMAIL\"]}",
"status": "USER_REGISTER"
}After the user receives the SMS verification code, fills it in the verification code box, and taps the register button (or triggers the event), the app client calls the register and bind method as follows:
[[BCAlipayBindOrRegistManager sharedInstance] alipayRegistWithMobile:mobile andWithVerifyCode:verifyCode andWithStateToken:_state_token andWithCompletionHandler:^(NSString * _Nonnull code, id _Nonnull data) { __strong __typeof(weakSelf)strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
});
}];Main class BCAlipayBindOrRegistManager method introduction:
/**
* Method name: sharedInstance
* @param no input parameters
* @return returns the singleton instance
*/
+ (instancetype )sharedInstance ;
/**
* Method name: alipayRegistWithMobile
* @brief: auto-register and bind method after Alipay login
* @param mobile mobile number
*@param StateToken state_token field obtained from the Alipay login method
*@param verifyCode SMS verification code
* @param BCAlipayRegistCompleteHandler login result callback function
**/
-(void)alipayRegistWithMobile:(NSString*)mobile andWithVerifyCode:(NSString*)verifyCode andWithStateToken: (NSString*)StateToken andWithCompletionHandler:(BCAlipayRegistCompleteHandler)completeHandler;BCAlipayRegistCompleteHandler callback function return codes:
| Code | Description |
|---|---|
| code=0 | Login successful, login successful, data= |
| code=1 | Login failed, data returns string describing error |
| code=error code (please refer to IDaaS return codes) | Login unsuccessful, data returns error description |
ID Token Verification and User Info Retrieval
After successful login, session_token and id_token are returned. id_token can be used to obtain user information and verify login validity.
Flow:
- Verify idToken
- Get user info from idtoken (this method can be called directly without verification)
Verify id_token
Call example:
[[BCIDAIDTokenManager sharedInstance] verifySignWithIdToken:idToken andWithCallBack:^(NSString * _Nonnull code, id _Nonnull data) {
}];Main class BCIDAIDTokenManager introduction:
/**
* Method name: sharedInstance
* @param no input parameters
* @return returns the singleton instance
*/
+ (instancetype )sharedInstance;
/**
* Method name: verifySignWithIdToken
* @brief: method to verify whether idtoken is within login validity and consistent with the app
* @param idToken returned at login
* @param BCIDAIdTokenVerifyHandlerBlock callback function:
NSString code
id data
**/
-(void)verifySignWithIdToken:(NSString*)idToken andWithCallBack:(BCIDAIdTokenVerifyHandlerBlock)callback;Return values:
| code (NSString) | data | data Type and Description |
|---|---|---|
| 0 | success | [NSString] Signature verification successful |
| 1 | Error description | [NSString] Input parameter is empty, SDK initialization parameters domain and clientID are not set |
| 106 | Expired | [NSString] Expired idtoken |
| 107 | clientID mismatch | [NSString] Possibly used another app's clientID |
| 103 | Signature verification failed | [NSString] Signature verification process failed |
| 102 | Failed to obtain public key | [NSString] Error during signature verification process |
| See error code collection at end of document | See error code collection at end of document | May also return error codes at the end of the document |
Parse User Info from idToken
Call example:
[[BCIDAIDTokenManager sharedInstance] getUserInfoFromIdTokenWithIdToken:idToken andWithCallBack:^(NSString * _Nonnull code, id _Nonnull data) {
}];Main class BCIDAIDTokenManager introduction:
/**
* Method name: sharedInstance
* @param no input parameters
* @return returns the singleton instance
*/
+ (instancetype )sharedInstance;
/**
* Method name: getUserInfoFromIdTokenWithIdToken
* @brief: parse user info from idToken
* @param idToken returned at login
* @param BCIDAIdTokenGetInfoHandlerBlock callback function:
NSString code
id data
**/
-(void)getUserInfoFromIdTokenWithIdToken:(NSString*)idToken andWithCallBack:(BCIDAIdTokenGetInfoHandlerBlock)callback;User info parameter description:
| Parameter Name | Description |
|---|---|
| iss | Token issuer |
| aud | Token recipient, app's clientId |
| exp | Token expiration time |
| jti | Token id |
| iat | Token issue time |
| sub | Fixed as subject |
| name | User name |
| mobile | User mobile number |
| id | User id |
| userName | Username |
| User email |
Callback function return value:
Success example:
code=0
data=
{
"id": "20220729174957176-2C7F-A2C54C293",
"exp": 1659407592,
"nbf": 1659407172,
"mobile": "+86-13808603636",
"jti": "7iwCYPo8EYcmLAD18x-CAw",
"iss": "https:\/\/sdk2c.idaas-test-alpha.bccastle.com\/api\/v1\/oauth2",
"userName": "zhangrui1",
"sub": "20220729174957176-2C7F-A2C54C293",
"aud": "S1ScicdIVR1QUbNs8TBz6BYVd2Zt8Adc",
"iat": 1659407292,
"email": "",
"name": "zhangrui1"
}
Failure example
code=102Refresh IDToken
Call example:
[[BCIDAIDTokenRefreshManager sharedInstance] refreshIdTokenWithSessionToken:sessionToken andWithCallBack:^(NSString * _Nonnull code, id _Nonnull data) {
NSString* jsonS=(NSString*)data;
NSDictionary* dict= [self dictionaryWithJsonString:jsonS];//Parse jsonStr to NSDictionary
NSString* idTok= [dict objectForKey:@"id_token"];
NSString* session_tok=[dict objectForKey:@"session_token"];
NSString* expr=[dict objectForKey:@"expire"];
}];Main class BCIDAIDTokenManager introduction:
/**
* Method name: sharedInstance
* @param no input parameters
* @return returns the singleton instance
*/
+ (instancetype )sharedInstance;
/**
* Method name: refreshIdTokenWithSessionToken
* @brief: refresh idToken
* @param sessionToken returned at login
* @param BCIDAIdTokenRefreshIDTokenHandlerBlock callback function:
NSString code
id data
**/
-(void)refreshIdTokenWithSessionToken:(NSString*)sessionToken andWithCallBack:(BCIDAIdTokenRefreshIDTokenHandlerBlock)callBack;Callback function return value:
Success example:
code=0
data=
{
"id_token" : "eyJraWQiOiJhODJkzJjLmlkYWFzLXRllKp6w",
"session_token" : "apcOKuyry7kASh9h6mtf2G2GbettkyiU",
"expire" : 7200
}
Failure example (no data obtained)
code=1Return Codes
| Status Code | Error Code (error_code) | Chinese Error Message | Remediation |
|---|---|---|---|
| 400 | IDAAS.SDK.COMMON.1001 | Parameter {0} cannot be left blank | |
| 参数 {0} 不能为空 | |||
| 400 | IDAAS.SDK.COMMON.1002 | The {0} parameter format is incorrect | |
| 参数 {0} 格式错误 | |||
| 400 | IDAAS.SDK.COMMON.1003 | Device information is incomplete | |
| 设备信息不完整 | |||
| 400 | IDAAS.SDK.COMMON.1004 | Signature decryption error | |
| 签名解密错误 | |||
| 400 | IDAAS.SDK.COMMON.1005 | The {0} has failed | |
| {0} 已失效 | |||
| 400 | IDAAS.SDK.COMMON.1006 | The {0} parameter error | |
| {0} 参数错误 | |||
| 400 | IDAAS.SDK.COMMON.1007 | The {0} parameter type error | |
| {0}参数类型错误 | |||
| 500 | IDAAS.SDK.COMMON.1008 | The system is busy. Try again later | |
| 系统繁忙。稍后再试 | |||
| 400 | IDAAS.SDK.COMMON.1009 | Unknown authentication configuration | |
| 未知的认证配置 | |||
| 400 | IDAAS.SDK.COMMON.1010 | Failed to obtain the enterprise center global configuration | |
| 获取企业中心全局配置失败 | |||
| 400 | IDAAS.SDK.COMMON.1011 | Failed to obtain the international area code configuration | |
| 获取国际区号配置失败 | |||
| 400 | IDAAS.SDK.COMMON.1012 | The x-client-ID is incorrect and the corresponding application cannot be found | |
| X-client-id错误,找不到对应的应用 | |||
| 400 | IDAAS.SDK.COMMON.1013 | The corresponding user is not found | |
| 未找到对应的用户 | |||
| 400 | IDAAS.SDK.COMMON.1014 | Application private key not found | |
| 未找到应用私钥 | |||
| 400 | IDAAS.SDK.LOGIN.1001 | Error calling interface | |
| 调用 {0} 接口出错 | |||
| 400 | IDAAS.SDK.LOGIN.1002 | User not bound | |
| 用户未绑定 | |||
| 400 | IDAAS.SDK.LOGIN.1003 | The user has been locked due to too many unsuccessful login attempts. It will be unlocked in {0} minutes and {1} seconds | |
| 由于多次登录失败,用户已被锁定。 它将在 {0} 分钟和 {1} 秒内解锁 | |||
| 400 | IDAAS.SDK.LOGIN.1004 | Failed to obtain the password policy | |
| 获取密码策略错误 | |||
| 400 | IDAAS.SDK.LOGIN.1005 | Invalid username or password. Remaining login attempts: | |
| 无效的用户名或密码。 其余登录尝试次数: | |||
| 400 | IDAAS.SDK.LOGIN.1006 | Configuration error, unable to find wechat authentication source | |
| 配置错误,找不到微信认证源 | |||
| 400 | IDAAS.SDK.LOGIN.1007 | Configuration error, unable to find alipay authentication source | |
| 配置错误,找不到支付宝认证源 | |||
| 400 | IDAAS.SDK.LOGIN.1008 | The configuration is incorrect. The one-click login authentication source cannot be found | |
| 配置错误,无法找到一键登录认证源 | |||
| 400 | IDAAS.SDK.SMS.1001 | {0} slide base map is not initialized successfully, please check the path | |
| {0} 滑动底图未初始化成功,请检查路径 | |||
| 400 | IDAAS.SDK.SMS.1002 | {0} verification code coordinate resolution failed | |
| {0} 验证码坐标解析失败 | |||
| 400 | IDAAS.SDK.SMS.1003 | {0} verification code coordinate verification fails | |
| {0} 验证码坐标校验失败 | |||
| 400 | IDAAS.SDK.SMS.1004 | The graphic verification code is incorrect | |
| 图形验证码校验错误 | |||
| 400 | IDAAS.SDK.SMS.1005 | SMS verification code verification is incorrect | |
| 短信验证码验证错误 | |||
| 400 | IDAAS.SDK.SMS.1006 | The email verification code is incorrect | |
| 邮件验证码验证错误 | |||
| 400 | IDAAS.SDK.SMS.1007 | Sending scenario does not exist | |
| 发送场景不存在 | |||
| 400 | IDAAS.SDK.SMS.1008 | Failed to send the verification code | |
| 发送验证码失败 | |||
| 400 | IDAAS.SDK.SOCIAL.1001 | The social account is unbound incorrectly | |
| 社交账号解绑错误 | |||
| 400 | IDAAS.SDK.SOCIAL.1002 | The social account has been bound, please unbind it first | |
| 社交账号已绑定,请先解绑 | |||
| 400 | IDAAS.SDK.PWD.1001 | The password length is incorrect | |
| 密码长度错误 | |||
| 400 | IDAAS.SDK.PWD.1002 | The password cannot be the username | |
| 密码不能为用户名 | |||
| 400 | IDAAS.SDK.PWD.1003 | Your password complexity is low | |
| 你的密码复杂度过低 | |||
| 400 | IDAAS.SDK.PWD.1004 | The password is weak | |
| 密码很弱 | |||
| 400 | IDAAS.SDK.PWD.1005 | The password is used before, cannot be used again | |
| 该密码已被使用过,不能再次使用 | |||
| 400 | IDAAS.SDK.PWD.1006 | Password cannot username in reverse order | |
| 密码不能是用户名的倒序 | |||
| 400 | IDAAS.SDK.PWD.1007 | The number of repeated password characters exceeded the upper limit | |
| 密码重复字符数超过限制 | |||
| 400 | IDAAS.SDK.PWD.1008 | Password cannot contain :username, phone number, email prefix, name in PinYing | |
| 密码不能包含:用户名、电话号码、邮件前缀、拼音名 | |||
| 400 | IDAAS.SDK.MFA.1001 | The mobile doesn't match the user | |
| 手机号和用户不匹配 | |||
| 400 | IDAAS.SDK.MFA.1002 | The access control policy is incorrect | |
| 访问控制策略配置错误 | |||
| 400 | IDAAS.SDK.MFA.1003 | Access control authentication source type conversion error | |
| 访问控制身份验证源类型转换错误 |