WeChat Login
Document Overview
This document describes how to integrate WeChat authorized login into an iOS client. In the WeChat login scenario, the WeChat App is already installed on the user's phone. When the user taps the WeChat login button in the client App, the BambooCloud IDaaS SDK launches the authorization page in the WeChat App. After the user taps the Authorize Login button and authorization succeeds, the WeChat App redirects back to the client App. The BambooCloud IDaaS SDK then automatically receives the temporary authorization code, takes it to the BambooCloud IDaaS server for authentication, and returns the final authentication result to the client App.
Process Overview
Login Flow

Integration Flow
The user taps the WeChat login button in the App client.
The App client launches the BambooCloud IDaaS SDK WeChat login method.
The BambooCloud IDaaS SDK sends a login authorization request to the WeChat SDK.
The WeChat SDK launches the WeChat App on the phone and displays the authorization login page.
The user taps the Authorize Login button.
WeChat authorization succeeds. The WeChat App returns to the client App with the WeChat authorization code. The BambooCloud IDaaS SDK automatically obtains the WeChat authorization code during the launch.
BambooCloud IDaaS requests authentication from the BambooCloud IDaaS server using the WeChat authorization code.
The BambooCloud IDaaS server checks whether a mobile number is bound. If a mobile number is already bound, the BambooCloud IDaaS server authentication succeeds and returns
session_tokenandid_tokento the BambooCloud IDaaS SDK.The BambooCloud IDaaS SDK returns
session_tokenandid_tokento the App client.If the BambooCloud IDaaS server finds that no mobile number is bound, it returns a flag indicating that binding or registration is required.
The BambooCloud IDaaS server displays the binding or registration page.
The user enters a mobile number, taps Get Verification Code, and completes the slider captcha.
The BambooCloud IDaaS SDK takes the slider captcha code to the BambooCloud IDaaS server to request slider verification.
The BambooCloud IDaaS server validates the slider successfully and returns a token to the BambooCloud IDaaS SDK.
The BambooCloud IDaaS SDK uses the token and mobile number to request that the BambooCloud IDaaS server send an SMS verification code.
The user receives the SMS verification code, enters it in the input box, and taps the Bind or Register button.
The BambooCloud IDaaS SDK submits the binding or login data to the BambooCloud IDaaS server.
After binding or registration succeeds, the BambooCloud IDaaS server returns
session_tokenandid_tokento the BambooCloud IDaaS SDK.The BambooCloud IDaaS SDK returns
session_tokenandid_tokento the client App.The client can use
id_tokento verify login validity and obtain basic user information.The client can use
session_tokento refreshid_token.
Prerequisites
Create an Application on WeChat Open Platform
Developers log in to WeChat Open Platform, create their own developer account, create a new application, and wait for approval. Obtain the application's appID and appSecret.
Obtain clientID
Log in to the BambooCloud IDaaS Enterprise Center, choose Resources > Applications, and click the application that belongs to you to view the clientID.

Configure the Authentication Source
Log in to the BambooCloud IDaaS Enterprise Center, choose Authentication > Authentication Source Management > WeChat.

Click Add Authentication Source, enter the AppKey and AppSecret obtained after registering the application on the WeChat development platform, set the channel to Mobile Application, and enter a display name.

Click OK to obtain the authentication source shown below. Switch to Resources > Applications, enter the newly created application, and go to Login Configuration > Mobile Application > Configure.

Enable the WeChat authentication source for the application.

In the pop-up window shown below, select the authentication source configured above and save.

Add Dependencies
Before integrating WeChat OAuth authorized login, register a developer account on WeChat Open Platform, own a mobile application that has passed review, and obtain the corresponding AppID and AppSecret. After applying for WeChat login and passing review, you can start the integration process.
libWeChatSDK.a //WeChat SDK package
WXApi.h
WXApiObject.hAdd Main Libraries
AuthnCenter_common_2C.framework
AuthnCenter_Wechat_2C.framework
AuthnCenter_Wechat_2C.bundle // Resource bundleDrag the BambooCloud IDaaS SDK into your project and import it as shown below:

Also add the following Pod dependency:
pod 'JWT', '~> 3.0.0-beta.14'Targets Configuration
The BambooCloud IDaaS SMS login SDK supports iOS 12 and later.
In Frameworks, Libraries, and Embedded Content, add the following libraries:
Security.framework,
CoreGraphics.framework,
CoreMedia.framework,
UIKit.framework,
WebKit.framework,
libc++.tbdSet Other Linker Flags. In your project file, select Build Settings, add
-ObjC -all_loadto Other Linker Flags, and addlibWeChatSDK.a,WXApi.h, andWXApiObject.hto Search Paths.
Set the URL scheme. In Xcode, select your project settings, choose the TARGETS section, and in the Info tab under URL Types, add a URL scheme with your registered application ID (as shown below).

In Xcode, select your project settings, choose the TARGETS section, and in the Info tab under LSApplicationQueriesSchemes, add
weixinandweixinULAPI(as shown below).
Set bitcode to NO.

UniversalLink Configuration
- After WeChat authorization succeeds, the App client needs to be launched. Configure
universallinkby referring to online tutorials.
First confirm that WeChat's Universal Links are working. Open Safari and enter https://help.wechat.com/app/. Scroll down to see if there is an Open WeChat entry (as shown below). If there is no entry, WeChat's Universal Links may have failed to load. Check whether the phone's network is normal, or update/reinstall WeChat.

After
universallinkis configured successfully, enter it in the App client. Add Associated Domains as shown below and enter theuniversallinkin the format shown below.

The universal link format is:
applinks:your-universallink.Set Allow Non-modular Includes In Framework Modules to Yes.

Development Integration
Built-in UI Integration
This section describes one-time WeChat login launch in the App client. The App client only needs to integrate the BambooCloud IDaaS SDK, initialization method, and WeChat registration method, and call the BambooCloud IDaaS SDK WeChat login method where WeChat login needs to be launched. The remaining authentication, registration, and binding UI flows are fully provided by the BambooCloud IDaaS SDK. After successful login, sessionToken is returned in the callback.
Before this section, complete all Xcode configurations and WeChat Open Platform configurations in the previous chapter.
SDK Initialization
The BambooCloud IDaaS SDK provides an initialization method in which you can specify the tenant, clientID, and whether to enable log output.
Initialization example:
Reference the following headers in AppDelegate:
#import <AuthnCenter_common_2C/BCIDACommonManager.h>
#import <AuthnCenter_wechat_2C/BCWechatManager.h>
//In didFinishLaunchingWithOptions of AppDelegate
//1. Basic configuration initialization
[[[[[BCIDACommonManager sharedInstance] initWithDomain:@"https://your-backend-tenant.com"] initWithClientID:@"your-tenant-clientID"] initWithSSLCerVerification:NO] setLogEnabled:YES] ;
//2. WeChat initialization
[[BCWechatManager sharedInstance] registWechatAppid:@"WeChat Open Platform APPID" andUniversalLink:@"configured-universalLink"];In AppDelegate, the following methods receive the WeChat callback. This callback is based on the universalLink configured on the WeChat platform; please configure 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;
}Main methods of the basic configuration initialization class BCIDACommonManager:
/**
* Method name: sharedInstance
* @param none
* @return singleton instance
*/
+ (instancetype )sharedInstance ;
/**
* Method name: initWithDomain
* @param domain, starts with https:// and ends with .com.
* @return instance
*/
-(BCIDACommonManager)initWithDomain:(NSString)domain
/**
* Method name: initWithClientID
* @param client id.
* @return instance
*/
-(BCIDACommonManager)initWithClientID:(NSString)clientID;
/**
* Method name: setLogEnabled
* @param boolean indicating whether to enable logs.
* @return instance
*/
-(void)setLogEnabled:(BOOL)enable;
/**
* Method name: initWithSSLCerVerification
* @param boolean indicating whether SSL certificate verification is enabled.
* @return instance
*/
-(BCIDACommonManager*)initWithSSLCerVerification:(bool)sslCerVerification;BCWechatManager method overview:
/**
* Method name: sharedInstance
* @param none
* @return singleton instance
*/
+ (instancetype )sharedInstance ;
/**
* Method name: registWechatAppid
* @param wechatAppID WeChat Open Platform appid
* @param universallink callback identifier configured in the previous step
* @param returns BCWechatManager entity object
* @return register WeChat AppID and initialization parameters
*/
-(BCWechatManager*)registWechatAppid:(NSString*)wechatAppID andUniversalLink: (NSString*)universallink;
/**
* Method name: oauthHandleOpenURL
* @param call this method when using openURL to callback to the client app
* @param none
* @return YES/NO
*/
-(BOOL)oauthHandleOpenURL:(NSURL*)url;
/**
* Method name: handleUniversalLink
* @param call this method when using universalLink to callback to the client app
* @param none
* @return YES/NO
*/
-(BOOL)handleUniversalLink:(NSUserActivity *)userActivity;Launch WeChat Login
When the user taps the WeChat login button, the App client calls the BambooCloud IDaaS SDK WeChat login method as shown below:
//Import header
#import <AuthnCenter_wechat_2C/BCWechatManager.h>
//Triggered event
[[BCWechatManager sharedInstance] loginByWechatWithSuccessHandler:^(NSString * _Nonnull code, id _Nonnull data) {
dispatch_async(dispatch_get_main_queue(), ^{
});
}];BCWechatManager method overview:
/**
* Method name: loginByWechatWithSuccessHandler
* @param launch WeChat login
* @param none
* @return BCWechatCompletionHandler callback, returns `NSString * code, id data`. 1. code=0 means success, data returns session_token and id_token
2.code=other means failure, data returns reason description.
*/
-(void)loginByWechatWithSuccessHandler:(BCWechatCompletionHandler)completionHandler;BCWechatCompletionHandler callback codes:
| Code | Description |
|---|---|
| code=0 | Login succeeded. data returns an NSDictionary: data=@{@"session_token":sessionTokenValue,@"id_token":idTokenValue}; |
| code=1 | Login failed. data returns a string describing the error. |
| code=error code (refer to BambooCloud IDaaS return codes) | Login unsuccessful. data returns an error description. |
| code=102 | The user canceled or denied authorization on the WeChat authorization page. |
| code=103 | WeChat login authorization failed (when the WeChat SDK returns an error). |
| Code=104 | After authorization succeeded, the user tapped the back button on the binding or registration page and canceled. |
UI Customization

After WeChat authorization succeeds, depending on whether the user is matched, the binding or quick registration flow is started. In the BambooCloud IDaaS Enterprise Center authentication source configuration, set new WeChat users to register automatically on login, and quick registration will be performed. (Whether the binding page or the quick registration page is displayed depends on the backend authentication source configuration.)

The above figure shows the default UI page.
In AppDelegate, in the didFinishLaunchingWithOptions method, set the theme object. Example code:
//Create a style object and set the style of each element. If an individual element is not set, the default style shown above is used.
BCWechatBindPhoneViewCustomSetting* settings=[[BCWechatBindPhoneViewCustomSetting alloc] init];
settings.isNavHidden=NO;
settings.navHiddenBackButtonFrameBlock = ^CGRect(CGRect frame) {//When isNavHidden=YES, you can set the frame of 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 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 verification code"attributes:@{NSForegroundColorAttributeName : UIColor.greenColor,NSFontAttributeName : [UIFont systemFontOfSize:10.0]}];
// settings.clickToSendBorderColor=@"CCFF33";
settings.clickToSendSMSBackgroundImage=[UIImage imageNamed:@"network"];
// settings.countDownTextColor=@"330000";
settings.countDownBtnBackgroundColor=@"CCCCFF";
settings.countDownBtnBackgroundImage=[UIImage imageNamed:@"greenbank"];
settings.confirmButtonRegistText=@"Register me";
settings.confirmButtonBindText=@"Bind";
settings.confirmButtonInactiveTextColor=@"FF99FF";
settings.confirmButtonActiveTextColor=@"FF9966";
settings.confirmButtonOnPressTextColor=@"FF66FF";
settings.confirmButtonInactiveBackgroundColor=@"999999";
settings.confirmButtonactiveBackgroundColor=@"CC00FF";
//When setting these values, save them to memory using the following class.
[[BCIDABindPhoneThemeManager sharedInstance] setBindPhoneTheme:settings];Property list:
| Property | Description |
|---|---|
| isNavHidden | YES: hides the navigation bar; the back button is a UIButton and an image can be passed. NO: does not hide the navigation bar; an image must be passed for the back button. |
| navColor | Navigation bar theme color, NSString, hex format, without 0x or #, e.g. FF4F4A |
| navHiddenBackButtonFrameBlock | When isNavHidden=YES, you can set the frame of the back button. |
| navBindTitle | Navigation bar title for binding |
| navRegistTitle | Navigation bar title for registration |
| navBackImage | Navigation bar back image. If isNavHidden=NO, the navigation bar is not hidden, and it is a simple back button on the interface. On the navigation bar (50x30), without navigation bar (70x40). |
| navRightView | Custom UIView on the right side of the navigation bar; a UIButton with events can be passed. |
| 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 | Text of the send SMS button |
| clickToSendBorderColor | Border color of the send SMS button, NSString, hex format, without 0x or #, e.g. FF4F4A. |
| clickToSendSMSBackgroundColor | Background color of the send SMS button, NSString, hex format, without 0x or #, e.g. FF4F4A. |
| clickToSendSMSBackgroundImage | Background image of the send SMS button; image takes precedence, otherwise the background color above is used. |
| countDownTextColor | Text color of the SMS countdown, NSString, hex format, without 0x or #, e.g. FF4F4A. |
| countDownBtnBackgroundColor | Background color of the SMS countdown button, NSString, hex format, without 0x or #, e.g. FF4F4A. |
| countDownBtnBackgroundImage | Background image of the SMS countdown button; image takes precedence, otherwise the background color above is used. |
| confirmButtonRegistText | Text of the registration confirm button |
| confirmButtonBindText | Text of the binding confirm button |
| confirmButtonInactiveTextColor | Text color of the confirm button when it cannot be tapped, NSString, hex format, without 0x or #, e.g. FF4F4A. |
| confirmButtonActiveTextColor | Text color of the confirm button when it can be tapped, NSString, hex format, without 0x or #, e.g. FF4F4A. |
| confirmButtonOnPressTextColor | Text color of the confirm button when just pressed, NSString, hex format, without 0x or #, e.g. FF4F4A. |
| confirmButtonInactiveBackgroundColor | Background color of the confirm button when it cannot be tapped, NSString, hex format, without 0x or #, e.g. FF4F4A. |
| confirmButtonactiveBackgroundColor | Background color of the confirm button when it can be tapped, NSString, hex format, without 0x or #, e.g. FF4F4A. |
Each call overwrites 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 properties use the default colors and styles.
API-based Integration
This section describes how to integrate WeChat login in API form. The client App needs to build its own binding/registration UI.
Call Sequence
Project configuration.
Initialize in
AppDelegate.Integrate the WeChat SDK.
Obtain the WeChat authorization code from the callback.
Call the BambooCloud IDaaS SDK WeChat login method.
Navigate to the binding or registration page and complete binding or registration.
SDK Initialization
BambooCloud IDaaS SDK initialization example:
Reference the following headers in AppDelegate:
#import <AuthnCenter_common_2C/BCIDACommonManager.h>
//In didFinishLaunchingWithOptions of AppDelegate
//1. Basic configuration initialization
[[[[[BCIDACommonManager sharedInstance] initWithDomain:@"https://your-backend-tenant.com"] initWithClientID:@"your-tenant-clientID"] initWithSSLCerVerification:NO] setLogEnabled:YES] ;WeChat Login Method
Example of logging in to the BambooCloud IDaaS SDK with the WeChat authorization code:
//Call after obtaining the WeChat authorization login code
[[BCWechatApiLoginManager sharedInstance] loginWechatByCode:code andWithCallBack:^(NSString * _Nonnull code, id _Nonnull data) {
}];BCWechatApiLoginManager:
/**
* Method name: sharedInstance
* @param none
* @return singleton instance
*/
+ (instancetype )sharedInstance ;
/**
* Method name: loginWechatByCode
* @param code: WeChat authorization login code, carried by the WeChat App callback universalLink.
* @return BCWechatAPILoginCallBackHandler callback `NSString* code, id data`.
*/
-(void)loginWechatByCode:(NSString*)code andWithCallBack:(BCWechatAPILoginCallBackHandler)callBack;BCWechatAPILoginCallBackHandler callback summary:
Success example 1 (user matched, returns session_token):
code=0
data=
{
"session_token": "btsiBjx85prcZu6I6Ki057Tmw3nSF2VO",
"id_token": value,
"expire": 432000,//NSNumber
"status": "SUCCESS"
}
Success example 2 (returns auto-registration and binding flow, 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, 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."
}If the following runtime error occurs:

Go to Build Settings and set Allow Non-modular Includes In Framework Modules to YES.

Binding or Registration Flow
Mobile number regular expression and international area codes
If international number support is enabled, call the international area code API first. The API returns the configured list of international area codes along with regular expressions for phone numbers. The figure 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 whether the number matches the regular expression
BOOL flag= [strongSelf parseDictionary:dic andWithMoile:mobile];
});
}];Main methods overview:
/**
* Method name: getInternaltionalAreaCodeWithCompletionHandler
* @brief: Get international area codes
* @param
*@param
* @param BCSMSGetInternationalAreaCodeHandlerBlock () result callback. code=0, data returns an NSDictionary
**/
+(void)getInternaltionalAreaCodeWithCompletionHandler:(BCSMSGetInternationalAreaCodeHandlerBlock)resultHander;Success example when code=0, value of data:
{
"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"
}Returned parameters:
| Parameter | Name | Type | Description |
|---|---|---|---|
| preferredAreaCode | Preferred area code | String | Preferred international area code configured in the Enterprise Center |
| countryCode | Country/region code | String | Country/region code |
| areaCode | International dialing code | String | International dialing code |
| areaCodeSuffixes | International dialing code suffixes | String | International dialing code suffixes |
| mobileRegex | Mobile number format regular expression | String | Mobile number format regular expression |
| displayMapping | Multilingual display name mapping | String | Multilingual display name mapping |
Slider Verification
Mobile number format check.
When the send verification code event is triggered, the App client calls the BambooCloud IDaaS SDK slider verification method as shown below:
//Import header
#import <AuthnCenter_Wechat_2C/BCWechatSlideVerifyCodeManager.h>
//Triggered event
[BCWechatSlideVerifyCodeManager startSlidingVerifyCodePageWithMobileNumber:mobile andWithResultHandler:^(NSString * _Nonnull code, id _Nonnull data) {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"Slider verification result==%@==%@",code,data);
});
}];BCWechatSlideVerifyCodeManager method overview:
/**
* Method name: startSlidingVerifyCodePageWithMobileNumber
* @brief: Launch the slider captcha
*@ param mobile: mobile number with area code, e.g. "+86-13800000000", or without area code, e.g. "13800000000".
*@param complete: asynchronous result callback:
1. When slider verification succeeds, returns code=0 and data=slider token.
2. code=other means slider verification failed (refer to error codes).
3. code=105 and data="User closed" means the close button of the slider box was tapped.
**/
+(void)startSlidingVerifyCodePageWithMobileNumber:(NSString*)mobile andWithResultHandler:(BCWechatSlideCodeHandlerBlock)resultHandler;When slider verification succeeds with code=0, example code for sending an SMS:
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 failed to send--code=%@ data=%@",code,data);
}
}];BCWechatSlideVerifyCodeManager SMS sending method overview:
/**
* Method name: sendSMSWithSlideResultWithToken
* @brief: Call this method to send an SMS.
*@ param token: token obtained after slider verification succeeds in the previous method.
*@ param mobile: mobile number.
*@ param type: `wechatSlideSMSSendType` enum, obtained from the `status` field of the WeChat login method.
status= SOCIAL_BIND means binding, so pass type=wechatSlideSMSBind.
status= USER_REGISTER means registration, so pass type=wechatSlideSMSRegist.
*@param complete: asynchronous result callback. SMS sent successfully returns code=0; other codes mean SMS sending failed. Refer to BambooCloud IDaaS error codes and the returned data (string error description).
**/
+(void)sendSMSWithSlideResultWithToken:(NSString*)token andMobile:(NSString*)mobile andWithType:(wechatSlideSMSSendType)type andWithCallBack:(BCWechatSendSMSHandlerBlock)callBack;Binding Method
The 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"
}After the user receives the SMS verification code, enters it in the input box, and taps the Bind button (or triggers the event), the App client calls the binding method as shown below:
[[BCWechatBindOrRegistManager sharedInstance] wechatBindWithMobile:mobileNumber andWithVerifyCode:verificationCode andWithStateToken: stateToken andWithCompletionHandler:^(NSString * _Nonnull code, id _Nonnull data) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
//Handle login success or failure
});
}];Main methods of BCWechatBindOrRegistManager:
/**
* Method name: sharedInstance
* @param none
* @return singleton instance
*/
+ (instancetype )sharedInstance ;
/**
* Method name: wechatBindWithMobile
* @brief: Binding method after WeChat login
* @param mobile mobile number
*@param StateToken `state_token` field obtained from the WeChat login method
* @param BCWechatBindCompleteHandler login result callback
**/
-(void) wechatBindWithMobile:(NSString*)mobile andWithVerifyCode:(NSString*)verifyCode andWithStateToken: (NSString*)StateToken andWithCompletionHandler:(BCWechatBindCompleteHandler)completeHandler;BCWechatBindCompleteHandler callback codes:
| Code | Description |
|---|---|
| code=0 | Login succeeded. data= { "session_token": "btsiBjx85prcZu6I6Ki057Tmw3nSF2VO", "id_token": value, "expire": 432000,//NSNumber "status": "SUCCESS" } |
| code=1 | Login failed. data returns a string describing the error. |
| code=error code (refer to BambooCloud IDaaS return codes) | Login unsuccessful. data returns an error description. |
Registration and Binding Method
When the WeChat login method returns:
Success example 2 (returns auto-registration and binding flow):
code=101
data=
{
"state_token": "eyJhbGciOiJIUzI1NiIsDzKMMZtPBv2VPS8",
"data": "{\"socialBindOrRegisterFlow\":[\"VERIFY_PHONE\",\"VERIFY_EMAIL\"]}",
"status": "USER_REGISTER"
}After the user receives the SMS verification code, enters it in the input box, and taps the Register button (or triggers the event), the App client calls the registration and binding method as shown below:
[[BCWechatBindOrRegistManager sharedInstance] wechatRegistWithMobile:mobileNumber andWithVerifyCode:verificationCode andWithStateToken: stateToken andWithCompletionHandler:^(NSString * _Nonnull code, id _Nonnull data) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
//Handle login success or failure
});
}];Main methods of BCWechatBindOrRegistManager:
/**
* Method name: sharedInstance
* @param none
* @return singleton instance
*/
+ (instancetype )sharedInstance ;
/**
* Method name: wechatRegistWithMobile
* @brief: Auto-registration and binding method after WeChat login
* @param mobile mobile number
*@param StateToken `state_token` field obtained from the WeChat login method
* @param BCWechatRegistCompleteHandler login result callback
**/
-(void) wechatRegistWithMobile:(NSString*)mobile andWithVerifyCode:(NSString*)verifyCode andWithStateToken: (NSString*)StateToken andWithCompletionHandler:(BCWechatRegistCompleteHandler)completeHandler;BCWechatRegistCompleteHandler callback codes:
| Code | Description |
|---|---|
| code=0 | Login succeeded. data= { "session_token": "btsiBjx85prcZu6I6Ki057Tmw3nSF2VO", "id_token": value, "expire": 432000,//NSNumber "status": "SUCCESS" } |
| code=1 | Login failed. data returns a string describing the error. |
| code=error code (refer to BambooCloud IDaaS return codes) | Login unsuccessful. data returns an error description. |
IDToken Verification and User Info Retrieval
After a successful login, session_token and id_token are returned. id_token can be used to obtain user information and verify login validity.
- Verify
idToken. - Get user information from
id_token(you can call this method without verifying first).
Verify id_token
Example call:
[[BCIDAIDTokenManager sharedInstance] verifySignWithIdToken:idToken andWithCallBack:^(NSString * _Nonnull code, id _Nonnull data) {
}];BCIDAIDTokenManager overview:
/**
* Method name: sharedInstance
* @param none
* @return singleton instance
*/
+ (instancetype )sharedInstance;
/**
* Method name: verifySignWithIdToken
* @brief: Verify whether id_token is within the login validity period and matches the application
* @param idToken returned at login
* @param BCIDAIdTokenVerifyHandlerBlock callback:
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 succeeded |
| 1 | Error description | [NSString] Input parameter is empty, or SDK initialization parameters domain and clientID are not set |
| 106 | Expired | [NSString] Expired id_token |
| 107 | clientID mismatch | [NSString] Possibly used a clientID from another application |
| 103 | Signature verification failed | [NSString] Signature verification process failed |
| 102 | Public key empty | [NSString] Error during signature verification |
| See error code list at the end | See error code list at the end | Other error codes at the end of this document may also be returned |
Parse User Info from idToken
Example call:
[[BCIDAIDTokenManager sharedInstance] getUserInfoFromIdTokenWithIdToken:idToken andWithCallBack:^(NSString * _Nonnull code, id _Nonnull data) {
}];BCIDAIDTokenManager overview:
/**
* Method name: sharedInstance
* @param none
* @return singleton instance
*/
+ (instancetype )sharedInstance;
/**
* Method name: getUserInfoFromIdTokenWithIdToken
* @brief: Parse user information from id_token
* @param idToken returned at login
* @param BCIDAIdTokenGetInfoHandlerBlock callback:
NSString code
id data
**/
-(void)getUserInfoFromIdTokenWithIdToken:(NSString*)idToken andWithCallBack:(BCIDAIdTokenGetInfoHandlerBlock)callback;User information parameters:
| Parameter | Description |
|---|---|
| iss | Token issuer |
| aud | Token recipient, the application's clientId |
| exp | Token expiration time |
| jti | Token ID |
| iat | Token issuance time |
| sub | Fixed as subject |
| name | User name |
| mobile | User mobile number |
| id | User ID |
| userName | Username |
| User email |
Callback 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
Example call:
[[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"];
}];BCIDAIDTokenManager overview:
/**
* Method name: sharedInstance
* @param none
* @return singleton instance
*/
+ (instancetype )sharedInstance;
/**
* Method name: refreshIdTokenWithSessionToken
* @brief: Refresh id_token
* @param sessionToken returned at login
* @param BCIDAIdTokenRefreshIDTokenHandlerBlock callback:
NSString code
id data
**/
-(void)refreshIdTokenWithSessionToken:(NSString*)sessionToken andWithCallBack:(BCIDAIdTokenRefreshIDTokenHandlerBlock)callBack;Callback return value:
Success example:
code=0
data=
{
"id_token" : "eyJraWQiOiJhODJkzJjLmlkYWFzLXRllKp6w",
"session_token" : "apcOKuyry7kASh9h6mtf2G2GbettkyiU",
"expire" : 7200
}Return Codes
| Status Code | Error Code | Error Message | 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 | 访问控制身份验证源类型转换错误 |