Customer Identity (CIAM)

WeChat Login

# Documentation Description

This document explains how to integrate the WeChat authorization login function in an iOS client. In the WeChat login usage scenario, the user has the WeChat APP installed on their phone. The user clicks the WeChat login button in the client APP, the IDaaS SDK launches the authorization page within the WeChat APP. After the user clicks the "Authorize Login" button and authorization is successful, the WeChat APP redirects back to the client APP. At this point, the IDaaS SDK automatically receives a temporary ticket and uses this ticket to request authentication from the IDaaS server. The final authentication result is returned to the client APP.

# Process Description

# Login Flow

Integration Flow Description

  1. The user clicks the WeChat login button in the client APP.

  2. The client APP calls the IDaaS SDK's WeChat login method.

  3. The IDaaS SDK sends a login authorization request to the WeChat SDK.

  4. The WeChat SDK launches the WeChat APP on the phone and displays the authorization login page.

  5. The user clicks the "Authorize Login" button.

  6. WeChat authorization is successful, and the client APP is launched with the WeChat authorization ticket. At this point, the IDaaS SDK automatically obtains the WeChat authorization ticket during the launch.

  7. IDaaS uses the WeChat authorization ticket to request authentication from the IDaaS server.

  8. The IDaaS server checks if a mobile phone 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.

  9. The IDaaS SDK returns session_token and id_token to the client APP.

  10. If the IDaaS server finds that no mobile phone number is bound, it returns an identifier indicating that binding or registration is required.

  11. The IDaaS server displays the binding or registration page.

  12. The user enters a mobile phone number, clicks to get the verification code, and completes the slider verification.

  13. The IDaaS SDK sends the slider verification code to the IDaaS server to request slider verification.

  14. The IDaaS server successfully validates the slider and returns a token to the IDaaS SDK.

  15. The IDaaS SDK uses the token and mobile phone number to request the IDaaS server to send an SMS verification code.

  16. The user receives the SMS verification code, enters it into the verification code input box, and clicks the bind or register button.

  17. The IDaaS SDK submits the binding or registration data to the IDaaS server.

  18. Binding or registration is successful, and the IDaaS server returns session_token and id_token to the IDaaS SDK.

  19. The IDaaS SDK returns session_token and id_token to the client APP.

  20. The client can use id_token to verify login validity and obtain basic user information.

  21. The client can use session_token to refresh id_token.

# Preparation

# Create an Application on the WeChat Open Platform

Developers log in to the WeChat Open Platform (opens new window), create their own development account, and create a new application. After approval, obtain the app's AppID and App Secret.

# Obtain clientID

Log in to the IDaaS Enterprise Center platform, click "Resources --> Applications", select the relevant application, and click to view it.

# Configure Authentication Source

  1. Log in to the IDaaS Enterprise Center platform, click "Authentication --> Authentication Source Management --> WeChat".

  1. Click "Add Authentication Source", fill in the AppKey and AppSecret obtained after registering the application on the WeChat Open Platform. Select 'Mobile Application' in the channel selection box. Enter a name in the display name field.

  1. Click OK, and you will get an authentication source as shown in the figure below. Switch to "Resources --> Applications", enter the newly created application, and go to "Login Configuration --> Mobile Application --> Configuration".

  1. Enable the WeChat authentication source for the application.

  1. A window as shown below will pop up. Select the authentication source you just configured and save it.

# Introducing Dependencies {/introducing-dependencies/}

Before integrating WeChat OAuth authorization login, you need to register a developer account on the WeChat Open Platform (opens new window), have an approved mobile application, and obtain the corresponding AppID and AppSecret. After applying for WeChat login and passing the review, you can start the integration process.

libWeChatSDK.a // WeChat SDK package
WXApi.h
WXApiObject.h
1
2
3

# Adding Main Libraries {/adding-main-libraries/}

AuthnCenter_common_2C.framework
AuthnCenter_Wechat_2C.framework
AuthnCenter_Wechat_2C.bundle // Resource bundle
1
2
3

Drag the IDaaSSDK into the project and import it as follows:

Also, introduce the Pod dependency.

pod 'JWT', '~> 3.0.0-beta.14'

# Targets Configuration {/targets-configuration/}

  • The IDaaS SMS login SDK has a minimum compatible version of iOS 12.

  • Include the following packages in "Frameworks, Libraries, and Embedded Content".

Security.framework,
CoreGraphics.framework,
CoreMedia.framework,
UIKit.framework,
WebKit.framework,
libc++.tbd
1
2
3
4
5
6
  • Set Other Linker Flags: In your project file, select Build Settings, add "-ObjC -all_load" in "Other Linker Flags", and add libWeChatSDK.a, WXApi.h, WXApiObject.h in Search Paths.

  • Set URL Scheme: In Xcode, select your project settings, choose the "TARGETS" tab, and add a "URL scheme" under the "URL type" section in the "info" tab, using your registered application id (as shown below).

  • In Xcode, select your project settings, choose the "TARGETS" tab, and add "weixin" and "weixinULAPI" under "LSApplicationQueriesSchemes" in the "info" tab (as shown below).

  • Set Enable Bitcode to NO.

  • After successful WeChat authorization, the App client needs to be launched, which requires configuring Universal Link. Please refer to online tutorials for configuring Universal Link.

First, ensure WeChat's Universal Links are working. Open the Safari browser and enter https://help.wechat.com/app/. Scroll down to see if there is an "Open in WeChat" entry (as shown below). If there is no entry, it might be because the system failed to fetch WeChat's Universal Links. Please check if the phone's network status is normal, or update/reinstall WeChat.

  • After successfully configuring Universal Link, it needs to be entered in the App client. Follow the steps below to add Associated Domains and enter the Universal Link in the format shown.

    The format for Universal Link is: applinks:your_universallink

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

# Development Integration

# Development Integration Method with Built-in UI Pages

This chapter describes the process for an APP client to initiate WeChat login with a single call. The APP client only needs to integrate the IDaaS SDK, the initialization method, and the WeChat registration method. Then, call the IDaaS SDK WeChat login method where login needs to be initiated. All other UI flows for authentication, registration, and binding are fully provided by the IDaaS SDK. After successful login, the sessionToken is returned in the callback function.

Before proceeding with this chapter, please complete all Xcode configurations and WeChat Open Platform configurations from the previous chapter.

# SDK Initialization

The IDaaS SDK provides an initialization method where you can input 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_wechat_2C/BCWechatManager.h>

// In the didFinishLaunchingWithOptions method of AppDelegate
//1. Basic configuration initialization
[[[[[BCIDACommonManager sharedInstance] initWithDomain:@"https://your-backend-tenant.com"] initWithClientID:@"backend-tenant-clientID"] initWithSSLCerVerification:NO] setLogEnabled:YES];
//2. WeChat initialization
    [[BCWechatManager sharedInstance] registWechatAppid:@"WeChat Open Platform APPID" andUniversalLink:@"configured-universalLink"];
1
2
3
4
5
6
7
8
9

In AppDelegate, the following methods receive callbacks from WeChat. These callbacks are based on the universalLink configured on the WeChat platform. Please configure the universalLink first.

-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    [[BCWechatManager sharedInstance] oauthHandleOpenURL:url];
     return YES;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
    [[BCWechatManager sharedInstance] oauthHandleOpenURL:url];
  return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{

    [[BCWechatManager sharedInstance] oauthHandleOpenURL:url];
  
    return YES;
}
-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{
   
    [[BCWechatManager sharedInstance] handleUniversalLink:userActivity];
    

    return YES;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Introduction to the main class BCIDACommonManager methods for basic configuration initialization:

/**
  * Function name: sharedInstance
   * @param None
   * @return Singleton object instance class
 */
+ (instancetype )sharedInstance ;

/**
  * Function name: initWithDomain
   * @param domain, starting with https:// and ending with .com.
   * @return Instance class
 */
-(BCIDACommonManager)initWithDomain:(NSString)domain

/**
  * Function name: initWithClientID
   * @param client id.
   * @return Instance class
 */
-(BCIDACommonManager)initWithClientID:(NSString)clientID;

/**
  * Function name: setLogEnabled
   * @param Boolean value to enable or disable logs.
   * @return Instance class
 */
-(void)setLogEnabled:(BOOL)enable;

/**
  * Function name: initWithSSLCerVerification
   * @param Boolean value to enable or disable SSL certificate verification.
   * @return Instance class
 */
-(BCIDACommonManager*)initWithSSLCerVerification:(bool)sslCerVerification;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

Introduction to BCWechatManager Class Methods:

/**
  * Function name: sharedInstance
   * @param None
   * @return Singleton object instance class
 */
+ (instancetype )sharedInstance ;
/**
  * Function name: registWechatAppid
   * @param wechatAppID The appid from the WeChat Open Platform
   * @param universallink The callback identifier configured in the previous step
   * @param Returns a BCWechatManager entity object
   * @return Registers the WeChat AppID and initializes parameters
 */

-(BCWechatManager*)registWechatAppid:(NSString*)wechatAppID andUniversalLink: (NSString*)universallink;


/**
   * Function name: oauthHandleOpenURL
* @param When the app client receives a callback via openurl
   * @param None
 * @return YES/NO
 */
-(BOOL)oauthHandleOpenURL:(NSURL*)url;

/**
   * Function name: handleUniversalLink
* @param When the app client receives a callback via universallink
   * @param None
   * @return YES/NO
 */

-(BOOL)handleUniversalLink:(NSUserActivity *)userActivity;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

# Initiating WeChat Login

When the user clicks the WeChat login button, the app client calls the IDaaS SDK's WeChat login method. A code example is as follows:

// Import the header file
#import <AuthnCenter_wechat_2C/BCWechatManager.h>

// Click (trigger) event
 [[BCWechatManager sharedInstance] loginByWechatWithSuccessHandler:^(NSString * _Nonnull code, id  _Nonnull data) {
        dispatch_async(dispatch_get_main_queue(), ^{
       
        });
    }];
1
2
3
4
5
6
7
8
9

Introduction to BCWechatManager Object Methods:

/**
   * Function name: loginByWechatWithSuccessHandler
* @param Triggers WeChat login
   * @param No input parameters
   * @return BCWechatCompletionHandler callback, returns NSString * code, id data. 1. code=0 indicates success, data returns session_token and id_token
                   2. code=others indicates failure, data returns a description of the reason.
 */

-(void)loginByWechatWithSuccessHandler:(BCWechatCompletionHandler)completionHandler;
1
2
3
4
5
6
7
8
9

BCWechatCompletionHandler Callback Function Return Codes:

Code Description
code=0 Login successful. At this time, data returns NSDictionary: data=@{@"session_token":sessionToken content,@"id_token":idToken content};
code=1 Login failed, data returns a string describing the error
code=Error code (please refer to IDaaS return codes) Login unsuccessful, data returns an error description
code=102 User clicked cancel or denied authorization on the WeChat authorization page
code=103 WeChat login authorization failed (when the WeChat SDK returns an error)
Code=104 After successful authorization, the user clicked the back button on the binding or registration page, user returned and canceled

# UI Customization

After successful WeChat authorization, based on whether a user is matched, the binding or quick registration process will be initiated. If "Login as registration for new WeChat users" is configured in the IDaaS Enterprise Center authentication source settings, then quick registration will be performed. (Whether the binding page or the quick registration page is displayed depends on the backend authentication source configuration).

The image above shows the default UI page.

In the didFinishLaunchingWithOptions method within appdelegate, set the theme object. Code example:

//Create a new style object and set styles for each element. If an individual element is not set, the default style from the image above will be used.
BCWechatBindPhoneViewCustomSetting* settings=[[BCWechatBindPhoneViewCustomSetting alloc] init];
settings.isNavHidden=NO;
  settings.navHiddenBackButtonFrameBlock = ^CGRect(CGRect frame) {//When isNavHidden=YES, you can set the frame for the back button
            CGRect rec=CGRectMake(5, 150, 70, 40);
            return rec;
        };

    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 My Phone Number"attributes:@{NSForegroundColorAttributeName : UIColor.orangeColor,NSFontAttributeName : [UIFont systemFontOfSize:25.0]}];
    settings.tileDescriptionBindText=[[NSAttributedString alloc] initWithString:@"Bind My Phone Number"attributes:@{NSForegroundColorAttributeName : UIColor.greenColor,NSFontAttributeName : [UIFont systemFontOfSize:25.0]}];
    settings.descriptionRegistText=[[NSAttributedString alloc] initWithString:@"Enter the phone number for registration。。。。。。"attributes:@{NSForegroundColorAttributeName : UIColor.grayColor,NSFontAttributeName : [UIFont systemFontOfSize:16.0]}];
    
    settings.descriptionBindText=[[NSAttributedString alloc] initWithString:@"Enter the phone number for binding"attributes:@{NSForegroundColorAttributeName : UIColor.redColor,NSFontAttributeName : [UIFont systemFontOfSize:16.0]}];
    settings.clickToSendSMSButtonText=[[NSAttributedString alloc] initWithString:@"Get Verificatxion 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";
//After setting these values, use the following class to save them to memory.
[[BCIDABindPhoneThemeManager sharedInstance] setBindPhoneTheme:settings];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

Property List:

Property Description
isNavHidden YES: Hide the navigation bar. The back button is a UIButton, and a button image can be passed in. NO: Do not hide the navigation bar. The back button requires an image to be passed in.
navColor // Navigation bar theme color NSString, hexadecimal, without ox, without #, e.g., FF4F4A
navHiddenBackButtonFrameBlock When isNavHidden=YES, the frame of the back button can be set
navBindTitle Bind navigation bar title
navRegistTitle Register navigation bar title
navBackImage Navigation bar back button image. If isNavHidden=NO and the navigation bar is hidden, then it is simply a back button on the interface. On navigation bar (50x30), without navigation bar (70x40)
navRightView Custom UIView on the right side of the navigation bar, can pass in a UIButton with events
tileDescriptionRegistText First title (title of the quick registration page), NSString
tileDescriptionBindText First title (title of the social login bind number page)
descriptionBindText Description field below the title (title of the social login bind number page), NSString
descriptionRegistText Description field below the title (title of the registration page)
clickToSendSMSButtonText Send SMS button text
clickToSendBorderColor Send SMS button border color NSString, hexadecimal, without ox, without #, e.g., FF4F4A
clickToSendSMSBackgroundColor Send SMS button background color, NSString, hexadecimal, without ox, without #, e.g., FF4F4A
clickToSendSMSBackgroundImage Send SMS button background image setting. Background image takes priority. If no image is set, use the background color above
countDownTextColor Send SMS countdown text color, NSString, hexadecimal, without ox, without #, e.g., FF4F4A
countDownBtnBackgroundColor Send SMS countdown background color. NSString, hexadecimal, without ox, without #, e.g., FF4F4A
countDownBtnBackgroundImage Send SMS countdown background image. Background image takes priority. If no image is set, use the background color above
confirmButtonRegistText Register, confirm button text
confirmButtonBindText Bind, confirm button text
confirmButtonInactiveTextColor Confirm button text color when not clickable, NSString, hexadecimal, without ox, without #, e.g., FF4F4A
confirmButtonActiveTextColor Confirm button text color when clickable, NSString, hexadecimal, without ox, without #, e.g., FF4F4A
confirmButtonOnPressTextColor Bind, confirm button text color when just pressed, NSString, hexadecimal, without ox, without #, e.g., FF4F4A
confirmButtonInactiveBackgroundColor Bind, confirm button background color when not clickable, NSString, hexadecimal, without ox, without #, e.g., FF4F4A
confirmButtonactiveBackgroundColor Bind, confirm button background color when clickable, NSString, hexadecimal, without ox, without #, e.g., FF4F4A

Each time it is called, the theme will be overwritten. If no theme is set, the page will adopt the default style. If only a part of the theme is set, the set parts will be saved, and the unset properties will use the default color styles.

# Integration Method via API Calls

This section introduces how to integrate WeChat login in the form of an API. The client APP needs to build a binding/registration interface.

# Call Sequence Description

  1. Project configuration.
  2. Initialize in Appdelegate.
  3. Integrate the WeChat SDK.
  4. Obtain the callback WeChat authorization ticket code.
  5. Call the IDaaS SDK WeChat login method.
  6. Redirect to the binding or registration page to complete binding or registration.

# SDK Initialization

Example of the IDaaS SDK initialization method:

Include the header file in appdelegate as follows
#import <AuthnCenter_common_2C/BCIDACommonManager.h>

// In the didFinishLaunchingWithOptions method of appdelegate
// 1. Basic configuration initialization
[[[[[BCIDACommonManager sharedInstance] initWithDomain:@"https://your-backend-tenant.com"] initWithClientID:@"backend-tenant-clientID"] initWithSSLCerVerification:NO] setLogEnabled:YES];
1
2
3
4
5
6

# WeChat Login Method

Example of the method to log in to the IDaaS SDK using the WeChat authorization ticket:

// Call after obtaining the WeChat authorization login ticket code
[[BCWechatApiLoginManager sharedInstance] loginWechatByCode:code andWithCallBack:^(NSString * _Nonnull code, id  _Nonnull data) {

}];
1
2
3
4

BCWechatApiLoginManager:

/**
   * Function name: sharedInstance
   * @param No input parameters
   * @return Returns the singleton instance of the object
 */
+ (instancetype )sharedInstance ;

/**
   * Function name: loginWechatByCode
   * @param code: The WeChat authorization login ticket, carried when the WeChat App callback triggers the universal link.
   * @return BCWechatAPILoginCallBackHandler callback function NSString* code, id data.
           
 */

-(void)loginWechatByCode:(NSString*)code andWithCallBack:(BCWechatAPILoginCallBackHandler)callBack;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Summary of the BCWechatAPILoginCallBackHandler callback function:

Success example 1 (Successfully matched user returns session_token):
code=0
data=
{
    "session_token": "btsiBjx85prcZu6I6Ki057Tmw3nSF2VO",
    "id_token": content,
    "expire": 432000, // NSNumber type
    "status": "SUCCESS"
}

Success example 2 (Returns automatic registration and binding flow, please refer to section 3.5.3.4):
code=101
data=
{
    "state_token": "eyJhbGciDzKMMZtPBv2VPS8",
    "data": "{\"socialBindOrRegisterFlow\":[\"VERIFY_PHONE\",\"VERIFY_EMAIL\"]}",
    "status": "USER_REGISTER"
}

Success example 3 (Returns binding flow, please refer to section 3.5.3.3):
code=101
data=
{
    "state_token": "eyzKMMZtPBv2VPS8",
    "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."
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

If you encounter a program runtime error:

Please go to build-settings and set Allow Non-modular Includes In Framework Modules to YES.

# Binding or Registration Process Methods

Mobile Number Regex Validation to Obtain International Area Code

If international number support is enabled, please first call the international area code acquisition interface. The international area code acquisition interface returns a configured list of international area codes, along with regular expressions for phone numbers. The image below shows how to configure the international area code list.

Example code for obtaining 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 if the phone number matches the regular expression
 BOOL flag=  [strongSelf parseDictionary:dic andWithMoile:mobile];
            
        });
    }];
1
2
3
4
5
6
7
8
9
10
11
12

Introduction to the main class method:

/**
* Function name: getInternaltionalAreaCodeWithCompletionHandler
* @brief: Method to obtain international area codes
* @param
*@param
* @param BCSMSGetInternationalAreaCodeHandlerBlock () Result callback function code=0, data returns the result as NSDictionary
**/
+(void)getInternaltionalAreaCodeWithCompletionHandler:(BCSMSGetInternationalAreaCodeHandlerBlock)resultHander;
1
2
3
4
5
6
7
8

Successful example code=0, value of data:

{
	"phoneAreaCodeDefinitions": [
		{
			"areaCode": "86",
			"displayMapping": {
				"zh-TW": "中國大陸",
				"en": "China",
				"zh-CN": "中国大陆"
			},
			"countryCode": "CN",
			"mobileRegex": "^(\\+86){0,1}\\-?1\\d{10}$",
			"areaCodeSuffixes": []
		},
		{
			"areaCode": "852",
			"displayMapping": {
				"zh-TW": "中國香港",
				"en": "Hong Kong",
				"zh-CN": "中国香港"
			},
			"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": "中國臺灣",
				"en": "Taiwan",
				"zh-CN": "中国台湾"
			},
			"countryCode": "TW",
			"mobileRegex": "^(\\+886){1}\\-?[6,7,9](?:\\d{7}|\\d{8})$",
			"areaCodeSuffixes": []
		},
		{
			"areaCode": "853",
			"displayMapping": {
				"zh-TW": "中國澳門",
				"en": "Macau",
				"zh-CN": "中国澳门"
			},
			"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": "阿富汗",
				"en": "Afghanistan",
				"zh-CN": "阿富汗"
			},
			"countryCode": "AF",
			"mobileRegex": "^(\\+93){1}\\-\\d{6,11}",
			"areaCodeSuffixes": []
		}
	],
	"preferredAreaCode": "CN"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

Return Parameters:

Parameter Name Chinese Name Type Description
preferredAreaCode Preferred International Dialing Code String The preferred international dialing code configured for 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

  1. Mobile number format check.

  2. Click (trigger) the send verification code event. The App client calls the IDaaS SDK's slider verification method, as shown in the example below.

// Import the request header
#import <AuthnCenter_Wechat_2C/BCWechatSlideVerifyCodeManager.h>

// Click (trigger) the send verification code event
 [BCWechatSlideVerifyCodeManager startSlidingVerifyCodePageWithMobileNumber:mobile andWithResultHandler:^(NSString * _Nonnull code, id  _Nonnull data) {            
            dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"Slider verification result==%@==%@",code,data);
            
            });
        }];
1
2
3
4
5
6
7
8
9
10

Introduction to BCWechatSlideVerifyCodeManager Object Methods:

/**
* Function Name: startSlidingVerifyCodePageWithMobileNumber
* @brief: Click to launch the slide verification
* @param mobile phone number: With area code "+86-13800000000" or without area code "13800000000" are both acceptable.
* @param complete: Asynchronous result callback:
1. When slide verification is successful, returns code=0 data=slide token
2. code=other indicates slide verification failure (refer to error codes)
3. code=105, data="User closed" indicates the close button of the slide verification box was clicked
**/
+(void)startSlidingVerifyCodePageWithMobileNumber:(NSString*)mobile andWithResultHandler:(BCWechatSlideCodeHandlerBlock)resultHandler;
1
2
3
4
5
6
7
8
9
10

Example code for sending SMS when slide verification code=0 is successful:

if([_status isEqualToString:@"USER_REGISTER"]){
        type=wechatSlideSMSRegist;//enum type
    }else if([_status isEqualToString:@"SOCIAL_BIND"]){

        type=wechatSlideSMSBind; //enum type
        
    }
    [BCWechatSlideVerifyCodeManager 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 sending failed--code=%@   data=%@",code,data);

        }
        
    }];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Introduction to BCWechatSlideVerifyCodeManager method for sending SMS:

/**
* Function Name: sendSMSWithSlideResultWithToken
* @brief: Call this method to send SMS,
* @param token the token obtained after successful slide verification from the previous method
* @param mobile phone number
* @param type (wechatSlideSMSSendType enum type), obtained from the WeChat login method's status field,
status= SOCIAL_BIND is for binding, here the input parameter type=wechatSlideSMSBind
status= USER_REGISTER is for registration, here the input parameter type=wechatSlideSMSRegist
* @param complete: Asynchronous result callback, returns code=0 when SMS is sent successfully, code=other indicates SMS sending failure, please refer to IDaaS error codes and the returned data (string error description)
**/
+(void)sendSMSWithSlideResultWithToken:(NSString*)token andMobile:(NSString*)mobile andWithType:(wechatSlideSMSSendType)type andWithCallBack:(BCWechatSendSMSHandlerBlock)callBack;
1
2
3
4
5
6
7
8
9
10
11

Binding Method

WeChat login method returns:

Success Example 3 (returns binding flow):
code=101
data=
{
    "state_token": "eyJhbGciOiJIUzI1NiMZtPBv2VPS8",
    "data": "{\"socialBindOrRegisterFlow\":[\"VERIFY_PHONE\",\"VERIFY_EMAIL\"]}",
    "status": " SOCIAL_BIND"
}
1
2
3
4
5
6
7
8

After the user receives the SMS verification code, enters it into the verification code box, and clicks the bind button (or triggers the event), the APP client calls the binding method as follows:

[[BCWechatBindOrRegistManager sharedInstance] wechatBindWithMobile:phone number andWithVerifyCode:verification code andWithStateToken: state_token andWithCompletionHandler:^(NSString * _Nonnull code, id  _Nonnull data) {
        __strong __typeof(weakSelf)strongSelf = weakSelf;

        dispatch_async(dispatch_get_main_queue(), ^{
   //Handling after login success/failure
        });
  }];

1
2
3
4
5
6
7
8

Introduction to the main class BCWechatBindOrRegistManager methods:

/**
   * Method name: sharedInstance
   * @param No input parameters
   * @return Returns the singleton instance of the object
 */
+ (instancetype )sharedInstance ;

/**
* Method name: wechatBindWithMobile
* @brief: WeChat login binding method
* @param mobile Phone number
* @param StateToken The state_token field obtained from the WeChat login method
* @param BCWechatBindCompleteHandler Login result callback function
**/
-(void) wechatBindWithMobile:(NSString*)mobile andWithVerifyCode:(NSString*)verifyCode andWithStateToken: (NSString*)StateToken andWithCompletionHandler:(BCWechatBindCompleteHandler)completeHandler;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

BCWechatBindCompleteHandler callback function return codes:

Code Description
code=0 Login successful, data= { "session_token": "btsiBjx85prcZu6I6Ki057Tmw3nSF2VO", "id_token": content, "expire": 432000, //NSNumber type "status": "SUCCESS" }
code=1 Login failed, data returns a string describing the error
code=Error code (please refer to IDaaS return codes) Login unsuccessful, data returns error description

Register and Bind Method

When the WeChat login method returns:

Successful example 2 (returns automatic registration and binding flow):
code=101
data=
{
    "state_token": "eyJhbGciOiJIUzI1NiIsDzKMMZtPBv2VPS8",
    "data": "{\"socialBindOrRegisterFlow\":[\"VERIFY_PHONE\",\"VERIFY_EMAIL\"]}",
    "status": "USER_REGISTER"
}
1
2
3
4
5
6
7
8

After the user receives the SMS verification code, enters it into the verification code field, and clicks the register button (or triggers the event), the APP client calls the register and bind method as follows:

[[BCWechatBindOrRegistManager sharedInstance] wechatRegistWithMobile:phone number andWithVerifyCode:verification code andWithStateToken: state_token andWithCompletionHandler:^(NSString * _Nonnull code, id  _Nonnull data) {
        __strong __typeof(weakSelf)strongSelf = weakSelf;

        dispatch_async(dispatch_get_main_queue(), ^{
   //Handling after login success/failure
        });
  }];

1
2
3
4
5
6
7
8

Introduction to the main class BCWechatBindOrRegistManager methods:

/**
   * Function name: sharedInstance
   * @param No parameters
   * @return Returns the singleton instance of the object
 */
+ (instancetype )sharedInstance ;

/**
* Function name: wechatRegistWithMobile
* @brief: Method for automatic registration and binding after WeChat login
* @param mobile Phone number
*@param StateToken The state_token field obtained from the WeChat login method
* @param BCWechatRegistCompleteHandler Login result callback function
**/
-(void) wechatRegistWithMobile:(NSString*)mobile andWithVerifyCode:(NSString*)verifyCode andWithStateToken: (NSString*)StateToken andWithCompletionHandler:(BCWechatRegistCompleteHandler)completeHandler;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

BCWechatRegistCompleteHandler callback function return codes:

Code Description
code=0 Login successful, login successful, data= { "session_token": "btsiBjx85prcZu6I6Ki057Tmw3nSF2VO", "id_token": content, "expire": 432000, // NSNumber type "status": "SUCCESS" }
code=1 Login failed, data returns string describing the error
code=Error code (please refer to IDaaS return codes) Login not successful, data returns error description

# IDToken Verification and User Information Retrieval

After successful login, session_token and id_token will be returned. id_token can be used to retrieve user information and verify login validity.

Process:

  1. Verify idToken
  2. Retrieve user information 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) {
          }];
1
2

Introduction to the main class BCIDAIDTokenManager:

/**
   * Function name: sharedInstance
   * @param No parameters
   * @return Returns the singleton instance of the object
*/
+ (instancetype )sharedInstance;

/**
* Function name: verifySignWithIdToken
* @brief: Method to verify if the idtoken is within the login validity period and matches the application
* @param idToken returned during login
* @param BCIDAIdTokenVerifyHandlerBlock callback function:
NSString code
id       data
**/
-(void)verifySignWithIdToken:(NSString*)idToken andWithCallBack:(BCIDAIdTokenVerifyHandlerBlock)callback;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

Return Value:

code(NSString) data Data Type and Description
0 success [NSString] Signature verification successful
1 Error description [NSString] Input parameters are empty, SDK initialization parameters domain and clientID are not set
106 Time expired [NSString] Expired idtoken
107 clientID mismatch [NSString] Possibly used clientID from another application
103 Signature verification failed [NSString] Failure during the signature verification process
102 Public key retrieval is empty [NSString] Error during the signature verification process
See error code collection at the end See error code collection at the end May also return error codes listed at the end

# Parse User Information from idToken

Call Example:

[[BCIDAIDTokenManager sharedInstance] getUserInfoFromIdTokenWithIdToken:idToken andWithCallBack:^(NSString * _Nonnull code, id  _Nonnull data) {
            
}];
1
2
3

Introduction to Main Class BCIDAIDTokenManager:

/**
   * Function name: sharedInstance
   * @param No input parameters
   * @return Returns the singleton instance of the object
*/
+ (instancetype )sharedInstance;

/**
* Function name: getUserInfoFromIdTokenWithIdToken
* @brief: Parse user information from idToken
* @param idToken returned from login
* @param BCIDAIdTokenGetInfoHandlerBlock callback function:
NSString code
id       data

**/
-(void)getUserInfoFromIdTokenWithIdToken:(NSString*)idToken andWithCallBack:(BCIDAIdTokenGetInfoHandlerBlock)callback;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

User Information Parameter Description:

Parameter Name Description
iss Token Issuer
aud Token Audience, the application's clientId
exp Token Expiration Time
jti Token ID
iat Token Issuance Time
sub Fixed as subject
name User's Full Name
mobile User's Mobile Number
id User ID
userName Username
email 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=102
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

# Refresh 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"];
                  }];
1
2
3
4
5
6
7

Introduction to the main class BCIDAIDTokenManager:

/**
   * Function name: sharedInstance
   * @param No input parameters
   * @return Returns the singleton instance of the object
*/
+ (instancetype )sharedInstance;

/**
* Function name: refreshIdTokenWithSessionToken
* @brief: Refresh idToken
* @param sessionToken returned from login
* @param BCIDAIdTokenRefreshIDTokenHandlerBlock callback function:
NSString code
id       data

**/
-(void)refreshIdTokenWithSessionToken:(NSString*)sessionToken andWithCallBack:(BCIDAIdTokenRefreshIDTokenHandlerBlock)callBack;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

Callback function return values:

Success example:
code=0
data=
{
  "id_token" : "eyJraWQiOiJhODJkzJjLmlkYWFzLXRllKp6w",
  "session_token" : "apcOKuyry7kASh9h6mtf2G2GbettkyiU",
  "expire" : 7200
}
1
2
3
4
5
6
7
8

# Return Codes

Status Code Error Code (error_code) Error Description (error_msg) Handling Measures
400 IDAAS.SDK.COMMON.1001 Parameter {0} cannot be left blank
Parameter {0} cannot be empty
400 IDAAS.SDK.COMMON.1002 The {0} parameter format is incorrect
Parameter {0} format error
400 IDAAS.SDK.COMMON.1003 Device information is incomplete
Device information incomplete
400 IDAAS.SDK.COMMON.1004 Signature decryption error
Signature decryption error
400 IDAAS.SDK.COMMON.1005 The {0} has failed
{0} has expired
400 IDAAS.SDK.COMMON.1006 The {0} parameter error
{0} parameter error
400 IDAAS.SDK.COMMON.1007 The {0} parameter type error
{0} parameter type error
500 IDAAS.SDK.COMMON.1008 The system is busy. Try again later
System busy. Please try again later
400 IDAAS.SDK.COMMON.1009 Unknown authentication configuration
Unknown authentication configuration
400 IDAAS.SDK.COMMON.1010 Failed to obtain the enterprise center global configuration
Failed to obtain enterprise center global configuration
400 IDAAS.SDK.COMMON.1011 Failed to obtain the international area code configuration
Failed to obtain 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 error, cannot find corresponding application
400 IDAAS.SDK.COMMON.1013 The corresponding user is not found
Corresponding user not found
400 IDAAS.SDK.COMMON.1014 Application private key not found
Application private key not found
400 IDAAS.SDK.LOGIN.1001 Error calling interface {0}
Error calling interface {0}
400 IDAAS.SDK.LOGIN.1002 User not bound
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
User locked due to multiple failed login attempts. It will be unlocked in {0} minutes and {1} seconds
400 IDAAS.SDK.LOGIN.1004 Failed to obtain the password policy
Failed to obtain password policy
400 IDAAS.SDK.LOGIN.1005 Invalid username or password. Remaining login attempts: {0}
Invalid username or password. Remaining login attempts: {0}
400 IDAAS.SDK.LOGIN.1006 Configuration error, unable to find wechat authentication source
Configuration error, unable to find WeChat authentication source
400 IDAAS.SDK.LOGIN.1007 Configuration error, unable to find alipay authentication source
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
Configuration error, unable to find one-click login authentication source
400 IDAAS.SDK.SMS.1001 {0} slide base map is not initialized successfully, please check the path
{0} slide base map initialization failed, please check path
400 IDAAS.SDK.SMS.1002 {0} verification code coordinate resolution failed
{0} verification code coordinate parsing failed
400 IDAAS.SDK.SMS.1003 {0} verification code coordinate verification fails
{0} verification code coordinate verification failed
400 IDAAS.SDK.SMS.1004 The graphic verification code is incorrect
Graphic verification code verification error
400 IDAAS.SDK.SMS.1005 SMS verification code verification is incorrect
SMS verification code verification error
400 IDAAS.SDK.SMS.1006 The email verification code is incorrect
Email verification code verification error
400 IDAAS.SDK.SMS.1007 Sending scenario does not exist
Sending scenario does not exist
400 IDAAS.SDK.SMS.1008 Failed to send the verification code
Failed to send verification code
400 IDAAS.SDK.SOCIAL.1001 The social account is unbound incorrectly
Social account unbinding error
400 IDAAS.SDK.SOCIAL.1002 The social account has been bound, please unbind it first
Social account already bound, please unbind first
400 IDAAS.SDK.PWD.1001 The password length is incorrect
Password length error
400 IDAAS.SDK.PWD.1002 The password cannot be the username
Password cannot be username
400 IDAAS.SDK.PWD.1003 Your password complexity is low
Your password complexity is low
400 IDAAS.SDK.PWD.1004 The password is weak
Password is weak
400 IDAAS.SDK.PWD.1005 The password is used before, cannot be used again
Password has been used before, cannot be used again
400 IDAAS.SDK.PWD.1006 Password cannot username in reverse order
Password cannot be username in reverse order
400 IDAAS.SDK.PWD.1007 The number of repeated password characters exceeded the upper limit
Number of repeated password characters exceeds limit
400 IDAAS.SDK.PWD.1008 Password cannot contain :username, phone number, email prefix, name in PinYing
Password cannot contain: username, phone number, email prefix, name in Pinyin
400 IDAAS.SDK.MFA.1001 The mobile doesn't match the user
Mobile number does not match user
400 IDAAS.SDK.MFA.1002 The access control policy is incorrect
Access control policy configuration error
400 IDAAS.SDK.MFA.1003 Access control authentication source type conversion error
Access control authentication source type conversion error

I am ready. Please provide the Markdown content you need translated.