Weibo Login
# Documentation Description
This document explains how to integrate the Weibo authorization login function into an iOS client. Weibo login usage scenario: The Weibo app is already installed on the user's phone. The user clicks the Weibo login button on the client app. The IDaaS SDK launches the authorization page within the Weibo app. The user clicks the "Authorize Login" button. After successful authorization, the Weibo app redirects back to the client app. At this point, the IDaaS SDK automatically receives a temporary credential and uses it to request authentication from the IDaaS server. The final authentication result is returned to the client app.
# Login Process Description
# Login Process

Integration Process Description
- The user clicks the Weibo login button in the app client.
- The app client invokes the IDaaS SDK's Weibo login method.
- The IDaaS SDK sends a login authorization request to the Weibo SDK.
- The Weibo SDK launches the Weibo app on the phone and displays the authorization login page.
- The user clicks the authorize login button.
- Weibo authorization is successful, launching the client app and carrying the Weibo authorization credentials (access token and uid). At this point, the IDaaS SDK automatically obtains the Weibo authorization credentials during the launch.
- IDaaS uses the Weibo authorization credentials to request authentication from the IDaaS server.
- The IDaaS server checks if a mobile phone number is bound. If a mobile phone number is already bound, the IDaaS server authentication is successful, returning 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 no bound mobile phone number, it returns an identifier indicating that binding or registration is required.
- The IDaaS server displays the binding or registration page.
- The user enters a mobile phone number, clicks to get a verification code, and completes the slider verification.
- The IDaaS SDK sends the slider verification code to the IDaaS server to request slider verification.
- The IDaaS server successfully validates the slider and returns a token to the IDaaS SDK.
- The IDaaS SDK uses the token and mobile phone number to request the IDaaS server to send an SMS verification code.
- The user receives the SMS verification code, enters it in the input box, and clicks the bind or register button.
- The IDaaS SDK submits the binding or login data to the IDaaS server.
- Binding or registration is successful. 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.
# Preparations
# Create an Application on the Weibo Open Platform
Developers log in to the Weibo Open Platform (opens new window) to create their own developer account, create a new application, and pass the review. Obtain the app's appID and app Secret.
# Obtain the Application clientID
Log in to the IDaaS Enterprise Center platform, click "Resources -> Applications", select the relevant application, and click to view it.

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

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

The callback address here should be filled in the advanced information configuration of the application on the Weibo Open Platform. The authorization callback page is as follows, and is also used as the redirectURI parameter required by the SDK: https://tenant.bccastle.com/api/v1/login/weibo
The cancel authorization callback page is: https://tenant.bccastle.com/CancelRedirectUri

Switch to "Resources -> Applications", enter the newly created application, go to "Login Configuration -> Mobile Application -> Configuration".

Find Weibo and enable the button.

# Import Dependencies
Before integrating Weibo OAuth login, you need to register a developer account on the Weibo Open Platform (opens new window), have a mobile application, and obtain the corresponding AppID and AppSecret to start the integration process.
libWeiboSDK.a // Weibo SDK package
WBHttpRequest.h
WeiboSDK.bundle
WeiboSDK.h
2
3
4
# Add Main Libraries
AuthnCenter_common_2C.framework
AuthnCenter_WeiBo_2C.framework
AuthnCenter_WeiBo_2C.bundle // Resource bundle
2
3
Drag the IDaaSSDK into your project and import it as shown below:

Also, add the Pod dependency.
pod 'JWT', '~> 3.0.0-beta.14'
# Target Settings
The minimum version compatible with the IDaaS Weibo login SDK is iOS 12, and the minimum system version for the Weibo SDK is iOS 12.
In Framework, Libraries, and Embedded Content, add the following packages.

Set Other Linker Flags. In your project file, select Build Settings, and add "-ObjC -all_load" under "Other Linker Flags".

In Xcode, select your project settings, choose the "TARGETS" tab, and under the "info" tab, add a "URL scheme" in "URL Types" with your registered application ID. This setting ensures your app can be opened after successful Weibo authorization. The URL schemes should be the SSO callback address after your app is authorized, in the format "WB + your application's Appkey", for example, wb20454V4V6852 (as shown below).

In Xcode, select your project settings, choose the "TARGETS" tab, and under the "info" tab, add sinaweibo, weibosdk, weibosdk2.5, and weibosdk3.3 to "LSApplicationQueriesSchemes" (as shown below).

Set bitcode to NO.

# UniversalLink Settings
After successful Weibo authorization, the App client needs to be launched, which requires configuring Universal Links. Please refer to online tutorials for configuring Universal Links.
After successfully configuring Universal Links, they need 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 of the Universal Link is: applinks:your_universal_link
Set "Allow Non-modular Includes In Framework Modules" to Yes.

# Development Integration
# Development Integration Method for Built-in UI Pages
This chapter describes the one-time initiation of Weibo login by the APP client. The APP client only needs to integrate the IDaaS SDK initialization method and the Weibo registration method, and call the IDaaS SDK Weibo login method where Weibo login needs to be initiated. All other authentication, registration, and binding UI processes are fully provided by the IDaaS SDK. After successful login, the session_token and id_token are returned in the callback function.
Before proceeding with this chapter, please complete all Xcode configurations and Weibo Open Platform configurations from the previous chapter.
# SDK Initialization
The IDaaS SDK provides an initialization method. You can fill in the tenant, clientID, and whether to enable log printing in the initialization method.
Example of the initialization method:
In the appdelegate, reference the header files as follows:
#import <AuthnCenter_common_2C/BCIDACommonManager.h>
#import <AuthnCenter_WeiBo_2C/BCWeiboLoginManager.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. Weibo initialization
[[BCWeiboLoginManager sharedInstance] registWeiBoWithAppKey:@"Weibo Open Platform appkey" andWithUniversalLink:@"configured universallink" enableDebugMode:YES];
2
3
4
5
6
7
8
9
In the appdelegate, the following methods receive callbacks from Weibo. These callbacks are based on the universalLink configured on the Weibo platform. Please configure the universalLink first.
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
[[BCWeiboLoginManager sharedInstance] oauthHandleOpenURL:url];
return YES;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
[[BCWeiboLoginManager sharedInstance] oauthHandleOpenURL:url];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
[[BCWeiboLoginManager sharedInstance] oauthHandleOpenURL:url];
return YES;
}
-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{
[[BCWeiboLoginManager sharedInstance] handleOpenUniversalActivity:userActivity];
return YES;
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Brief introduction to the main class BCIDACommonManager methods:
/**
* 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 indicating whether to enable log.
* @return Instance class
*/
-(void)setLogEnabled:(BOOL)enable;
/**
* Function name: initWithSSLCerVerification
* @param Boolean value setting whether to enable SSL certificate verification.
* @return Instance class
*/
-(BCIDACommonManager*)initWithSSLCerVerification:(bool)sslCerVerification;
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 BCWeiboLoginManager Class Methods:
/**
* Function name: sharedInstance
* @param None
* @return Singleton object instance class
*/
+ (instancetype )sharedInstance ;
/**
* Function name: registWeiBoWithAppKey
* @param appKey The appkey from Weibo Open Platform
* @param universallink The callback identifier configured in the previous step
* @param isEnable YES=Debug mode enabled for printing Weibo logs, NO=Debug mode disabled
* @param Returns BCWeiboLoginManager entity object
* @return Weibo AppID and initialization parameters
*/
-(BCWeiboLoginManager*)registWeiBoWithAppKey:(NSString*)appKey andWithUniversalLink:(NSString*)universalLink enableDebugMode:(BOOL)isEnable;
/**
* Function name: oauthHandleOpenURL
* @param When using openurl callback to the client app
* @param None
* @return YES/NO
*/
-(BOOL)oauthHandleOpenURL:(NSURL*)url;
/**
* Function name: handleOpenUniversalActivity
* @param When using universallink callback to the client app
* @param None
* @return YES/NO
*/
-(BOOL)handleOpenUniversalActivity:(NSUserActivity *)userActivity;
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
# Initiating Weibo Login
When the user clicks the Weibo login button, the APP client calls the IDaaS SDK's Weibo login method. The code example is as follows:
// Import header
#import <AuthnCenter_WeiBo_2C/BCWeiboLoginManager.h>
// Click (trigger) event
[[BCWeiboLoginManager sharedInstance] loginWeiboWithRedirectURI:@"https://tenant.bccastle.com/api/v1/login/weibo" andWithCompletionCallBack:^(NSString * _Nonnull code, id _Nonnull data) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
});
}];
2
3
4
5
6
7
8
9
10
11
Introduction to BCWeiboLoginManager Object Methods:
/**
* Function name: loginWeiboWithRedirectURI
* @param Weibo login launch
* @param No input parameters
* @return BCWeiBoLoginCompletionHandler callback, returns NSString * code, id data.
1. code=0 indicates success, data returns session_token and id_token
2. code=other indicates failure, data returns the reason description.
*/
-(void)loginWeiboWithRedirectURI:(NSString*)redirectUri andWithCompletionCallBack:(BCWeiBoLoginCompletionHandler)callBack;
2
3
4
5
6
7
8
9
10
BCWeiBoLoginCompletionHandler Callback Function Return Codes:
| code | Description |
|---|---|
| code=0 | Login successful, data returns NSDictionary: data=@{@"session_token":sessionToken content,@"id_token":idToken content}; |
| code=1 | Login failed, data returns a string describing the error, usually non-network request errors, such as missing parameters |
| code=error code (please refer to IDaaS return codes) | Login unsuccessful, data returns error description |
| code=102 | User clicked cancel or denied authorization on the Weibo authorization page |
| code=103 | Weibo login authorization failed (when Weibo SDK returns an error) |
| Code=104 | After authorization succeeded, the user clicked the back button on the binding or registration page, user canceled |
# UI Customization

After successful Weibo authorization, the system will initiate either a binding or a quick registration process based on whether a matching user is found. If "Login equals registration for new Weibo 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 the AppDelegate, set the theme object.
Code Example:
Default style
BCWeiboBindPhoneViewCustomSetting* settings=[[BCWeiboBindPhoneViewCustomSetting 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 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 verification 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, save them to memory using the class below.
[[BCIDABindPhoneThemeManager sharedInstance] setBindPhoneTheme:settings];
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, 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, no ox, no #, e.g., FF4F4A |
| navHiddenBackButtonFrameBlock | When isNavHidden=YES, the frame of the back button can be set. |
| navBindTitle | Bind the navigation bar title. |
| navRegistTitle | Register the navigation bar title. |
| navBackImage | The image for the navigation bar back button. If isNavHidden=NO, the navigation bar is hidden, then it's 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 in. |
| tileDescriptionRegistText | First title (title of the quick registration page), NSString. |
| tileDescriptionBindText | First title (title of the social login bind phone number page). |
| descriptionBindText | Description field below the title (title of the social login bind phone 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, no ox, no #, e.g., FF4F4A. |
| clickToSendSMSBackgroundColor | Send SMS button background color, NSString, hexadecimal, no ox, no #, e.g., FF4F4A. |
| clickToSendSMSBackgroundImage | Set the background image for the click-to-send SMS button. Background image takes priority; if no image is set, use the background color above. |
| countDownTextColor | Text color for the SMS countdown, NSString, hexadecimal, no ox, no #, e.g., FF4F4A. |
| countDownBtnBackgroundColor | Background color for the SMS countdown button. NSString, hexadecimal, no ox, no #, e.g., FF4F4A. |
| countDownBtnBackgroundImage | Background image for the SMS countdown button. Background image takes priority; if no image is set, use the background color above. |
| confirmButtonRegistText | Registration, confirmation button text. |
| confirmButtonBindText | Binding, confirmation button text. |
| confirmButtonInactiveTextColor | Color of the confirmation button text when it cannot be clicked, NSString, hexadecimal, no ox, no #, e.g., FF4F4A. |
| confirmButtonActiveTextColor | Color of the confirmation button text when it can be clicked, NSString, hexadecimal, no ox, no #, e.g., FF4F4A. |
| confirmButtonOnPressTextColor | Color of the binding/confirmation button text when it is first pressed, NSString, hexadecimal, no ox, no #, e.g., FF4F4A. |
| confirmButtonInactiveBackgroundColor | Background of the binding/confirmation button, color when it cannot be clicked, NSString, hexadecimal, no ox, no #, e.g., FF4F4A. |
| confirmButtonactiveBackgroundColor | Background of the binding/confirmation button, color when it can be clicked, NSString, hexadecimal, no ox, no #, 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 configured part will be saved, and the unset properties will use the default color style.
# Integration Method via API Calls
This section introduces how to integrate Weibo login in the form of an API. The client APP needs to build a binding/registration interface.
# Call Sequence Explanation
- Project configuration.
- Initialize in the AppDelegate.
- Integrate the Weibo SDK.
- Obtain the callback Weibo authorization ticket code.
- Call the IDaaS SDK Weibo login method.
- Navigate 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 the AppDelegate as follows
#import <AuthnCenter_common_2C/BCIDACommonManager.h>
// In the didFinishLaunchingWithOptions method of the AppDelegate
// 1. Basic configuration initialization
[[[[[BCIDACommonManager sharedInstance] initWithDomain:@"https://your-backend-tenant.com"] initWithClientID:@"backend-tenant-clientID"] initWithSSLCerVerification:NO] setLogEnabled:YES] ;
2
3
4
5
6
# Weibo Login Method
Example of the method to log in to the IDaaS SDK using the Weibo authorization ticket:
// Call after obtaining the Weibo authorization login ticket code
[[BCWeiboAPILoginManager sharedInstance] loginWeiboWithAccessToken:access_token andWithUid:uid andWithCompletionHandler:^(NSString * _Nonnull code, id _Nonnull data) {
}];
2
3
BCWeiboApiLoginManager:
/**
* Function name: sharedInstance
* @param No input parameters
* @return Returns the singleton instance of the object
*/
+ (instancetype )sharedInstance ;
/**
* Function name: loginWeiboWithAccessToken
* @param access_token: The Weibo authorization login ticket, brought when the Weibo App calls back to the client APP.
* @param uid: The Weibo authorization login ticket, brought when the Weibo App calls back to the client APP.
* @return BCWeiBoAPILoginCompletionHandler callback function NSString* code ,id data.
*/
-(void)loginWeiboWithAccessToken:(NSString*)access_token andWithUid:(NSString*)uid andWithCompletionHandler:(BCWeiBoAPILoginCompletionHandler)callBack;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Summary of the BCWeiBoAPILoginCompletionHandler 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 auto-register and bind flow, please refer to section 3.5.3.4):
code=101
data=
{
"state_token": "eyJhbGDzKMMZtPBv2VPS8",
"data": "{\"socialBindOrRegisterFlow\":[\"VERIFY_PHONE\",\"VERIFY_EMAIL\"]}",
"status": "USER_REGISTER"
}
Success Example 3 (Returns bind flow, please refer to section 3.5.3.3):
code=101
data=
{
"state_token": "eyJhbG0zMDzKMMZtPBv2VPS8",
"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."
}
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
# Binding or Registration Process Methods {/examples/}
Mobile Number Regular Expression Validation for Obtaining International Area Codes {/examples/}
If international number support is enabled, you must first call the international area code retrieval API. This API returns a configured list of international area codes, along with regular expressions for phone numbers. The following image illustrates 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];
});
}];
2
3
4
5
6
7
8
9
10
11
12
Main class method description:
/**
* Function name: getInternaltionalAreaCodeWithCompletionHandler
* @brief: Method to obtain international area codes
* @param
*@param
* @param BCSMSGetInternationalAreaCodeHandlerBlock () Result callback function, code=0, data returns an NSDictionary result
**/
+(void)getInternaltionalAreaCodeWithCompletionHandler:(BCSMSGetInternationalAreaCodeHandlerBlock)resultHander;
2
3
4
5
6
7
8
Success example, code=0, data value:
{
"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"
}
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 Suffixes | String | International Dialing Code Suffixes |
| mobileRegex | Mobile Number Format Regular Expression | String | Mobile Number Format Regular Expression |
| displayMapping | Multi-language Display Name Mapping | String | Multi-language Display Name Mapping |
Slider Verification
Mobile number format check.
Click (trigger) the send verification code event. The App client calls the IDaaS SDK's slider verification method, as shown in the following example:
// Import header file
#import <AuthnCenter_WeiBo_2C/BCWeiboSlideVerifyCodeManager.h>
// Click (trigger) the send verification code event
[BCWeiboSlideVerifyCodeManager startSlidingVerifyCodePageWithMobileNumber:mobile andWithResultHandler:^(NSString * _Nonnull code, id _Nonnull data) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
});
}];
2
3
4
5
6
7
8
9
10
Introduction to BCWeiboSlideVerifyCodeManager Object Methods:
/**
* Function name: startSlidingVerifyCodePageWithMobileNumber
* @brief: Click to trigger the slide verification
* @param mobile phone number: Can be with area code "+86-13800000000" or without area code "13800000000".
* @param complete: Asynchronous result callback:
1. When slide verification succeeds, 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 on the slide verification box was clicked
**/
+(void)startSlidingVerifyCodePageWithMobileNumber:(NSString*)mobile andWithResultHandler:(BCWeiboSlideCodeHandlerBlock)resultHandler;
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=weiboSlideSMSRegist;
}else if([_status isEqualToString:@"SOCIAL_BIND"]){
type=weiboSlideSMSBind;
}
[BCWeiboSlideVerifyCodeManager sendSMSWithSlideResultWithToken:token andMobile:mobile andWithType:type andWithCallBack:^(NSString * _Nonnull code, id _Nonnull data) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
});
}];
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Introduction to BCWeiboSlideVerifyCodeManager method for sending SMS:
/**
* Function name: sendSMSWithSlideResultWithToken
* @brief: Call this method to send SMS,
* @param token obtained from the previous method after successful slide verification
* @param mobile phone number
* @param mobile (weiboSlideSMSSendType enum) type, obtained from the Weibo login method's status field,
status= SOCIAL_BIND is binding, here the input parameter type= weiboSlideSMSBind
status= USER_REGISTER is registration, here the input parameter type= weiboSlideSMSRegist
* @param complete: Asynchronous result callback, returns code=0 when SMS sending is successful, code=other indicates SMS sending failure, please refer to IDaaS error codes and returned data (string error description)
**/
+(void)sendSMSWithSlideResultWithToken:(NSString*)token andMobile:(NSString*)mobile andWithType:(weiboSlideSMSSendType)type andWithCallBack:(BCWeiboSendSMSHandlerBlock)callBack;
2
3
4
5
6
7
8
9
10
11
Binding Method
Weibo login method returns:
Successful example 3 (returns binding flow):
code=101
data=
{
"state_token": "eyJhbGciOiJIDzKMMZtPBv2VPS8",
"data": "{\"socialBindOrRegisterFlow\":[\"VERIFY_PHONE\",\"VERIFY_EMAIL\"]}",
"status": " SOCIAL_BIND"
}
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:
Example code:
[[BCWeiboBindOrRegistManager sharedInstance] weiboBindWithMobile:phone number andWithVerifyCode:SMS verification code andWithStateToken:state_token obtained from the login method andWithCompletionHandler:^(NSString * _Nonnull code, id _Nonnull data) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
//Handle success or failure
});
}];
2
3
4
5
6
7
Introduction to the Main Class BCWeiboBindOrRegistManager Methods:
/**
* Method name: sharedInstance
* @param No parameters
* @return Returns the singleton instance of the object
*/
+ (instancetype )sharedInstance ;
/**
* Method name: weiboBindWithMobile
* @brief: Weibo login binding method
* @param mobile Phone number
*@param StateToken The state_token field obtained from the Weibo login method
* @param BCWeiboBindCompleteHandler Login result callback function
**/
-(void)weiboBindWithMobile:(NSString*)mobile andWithVerifyCode:(NSString*)verifyCode andWithStateToken: (NSString*)StateToken andWithCompletionHandler:(BCWeiboBindCompleteHandler)completeHandler;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
BCWeiboBindCompleteHandler 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 Weibo login method returns:
Successful example 2 (Returning auto-register and bind flow):
code=101
data=
{
"state_token": "eyJhbGciOMMZtPBv2VPS8",
"data": "{\"socialBindOrRegisterFlow\":[\"VERIFY_PHONE\",\"VERIFY_EMAIL\"]}",
"status": "USER_REGISTER"
}
2
3
4
5
6
7
8
After the user receives the SMS verification code, enters it in the verification code field, and clicks the register button (or triggers the event), the APP client calls the register and bind method as follows:
Example code:
[[BCWeiboBindOrRegistManager sharedInstance] weiboRegistWithMobile:phone number andWithVerifyCode:SMS verification code andWithStateToken:state_token obtained from the login method andWithCompletionHandler:^(NSString * _Nonnull code, id _Nonnull data) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
dispatch_async(dispatch_get_main_queue(), ^{
// Handle success/failure
});
}];
2
3
4
5
6
7
8
Introduction to the Main Class BCWeiboBindOrRegistManager Methods:
/**
* Method name: sharedInstance
* @param No parameters
* @return Returns the singleton instance of the object
*/
+ (instancetype )sharedInstance ;
/**
* Method name: weiboRegistWithMobile
* @brief: Weibo login auto-register and bind method
* @param mobile Phone number
*@param StateToken The state_token field obtained from the Weibo login method
* @param BCWeiboRegistCompleteHandler Login result callback function
**/
-(void)weiboRegistWithMobile:(NSString*)mobile andWithVerifyCode:(NSString*)verifyCode andWithStateToken: (NSString*)StateToken andWithCompletionHandler:(BCWeiboRegistCompleteHandler)completeHandler;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
BCWeiboRegistCompleteHandler 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 description error. |
| code=Error code (please refer to IDaaS return codes) | Login unsuccessful, data returns error description. |
# IDToken Verification and Obtaining User Information
After a successful login, session_token and id_token are returned. The id_token can be used to obtain user information and verify login validity.
Process:
Verify the idToken
Obtain user information from the 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) {
}];
2
Main Class BCIDAIDTokenManager Introduction:
/**
* Function name: sharedInstance
* @param No input 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;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Return Values:
| code(NSString) | data | data type and description |
|---|---|---|
| 0 | success | [NSString] Verification successful |
| 1 | Error description | [NSString] Input parameter is empty, SDK initialization parameters domain and clientID are not set |
| 106 | Time expired | [NSString] Expired idtoken |
| 107 | clientID does not match | [NSString] Possibly used clientID from another application |
| 103 | Verification failed | [NSString] Verification process failed |
| 102 | Public key obtained is empty | [NSString] Error during 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 |
# Parsing User Information from idToken
Calling Example:
[[BCIDAIDTokenManager sharedInstance] getUserInfoFromIdTokenWithIdToken:idToken andWithCallBack:^(NSString * _Nonnull code, id _Nonnull data) {
}];
2
3
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: 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;
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 clientId of the application |
| exp | Token Expiration Time |
| jti | Token ID |
| iat | Token Issuance Time |
| sub | Fixed as subject |
| name | User's Name |
| mobile | User's Mobile Number |
| id | User's ID |
| userName | Username |
| User's 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"
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Refresh IDToken {/刷新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"];
}];
2
3
4
5
6
7
Introduction to 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;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Callback Function Return Value:
Success Example:
code=0
data=
{
"id_token" : "eyJraWQiOiJhODJkzJjLmlkYWFzLXRllKp6w",
"session_token" : "apcOKuyry7kASh9h6mtf2G2GbettkyiU",
"expire" : 7200
}
Failure Example (Unable to retrieve data)
code=1
2
3
4
5
6
7
8
9
10
11
# 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 left blank | |||
| 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 is 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 | |
| The system is 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, unable to find the 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 | |
| The user has been 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 failed to initialize successfully, please check the 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 is 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 the 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 | |
| The password is weak | |||
| 400 | IDAAS.SDK.PWD.1005 | The password is used before, cannot be used again | |
| This password has been used before and cannot be used again | |||
| 400 | IDAAS.SDK.PWD.1006 | Password cannot username in reverse order | |
| Password cannot be the reverse order of the username | |||
| 400 | IDAAS.SDK.PWD.1007 | The number of repeated password characters exceeded the upper limit | |
| Number of repeated password characters exceeds the 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 phone number does not match the 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'm ready. Please provide the Markdown content you need translated.
