¶ Wecom login
¶ Preparation
For configuration in the Wecom management background and Authing management console, please refer to Wecom mobile terminal (generation development mode) (opens new window).
¶ Integrated Wecom login steps
¶ Step 1: Add dependencies
Enter: https://github.com/Authing/authing-binary in the swift package search bar.
Authing-binary (opens new window) depends on Guard-iOS SDK (opens new window).
Select Up to Next Major Version 1.0.0 for the dependency rule.
Check WeCom after Add Package.
¶ Step 2: Modify project configuration
Configure jump Scheme: add wxwork and wxworklocal under LSApplicationQueriesSchemes Key
Configure the corporate WeChat bounce URL: add the Schema applied for in the corporate WeChat management background under URL types Key (for example: wwauth803c38cb89ac1d57000002)
¶ Step 3: Initialize WeCom
Add import Guard and import WeCom to AppDelegate or SceneDelegate.
WeCom.registerApp needs to pass in the Scheme, AgentID, CorpID issued by WeChat Enterprise, isProxyDevelopment to select whether it is the agent development mode.
import Guard
import WeCom
Authing.start(<#AUTHING_APP_ID#>)
WeCom.registerApp(appId: <#Scheme#>, corpId: <#CorpID#>, agentId: <#AgentID#>, isProxyDevelopment: <#Bool#>)
¶ Step 4: Add callbacks
After Wecom returns to the application, if SceneDelegate is used, the following functions need to be overloaded in SceneDelegate.swift:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url {
_ = WeCom. handleOpenURL(url: url)
}
}
If SceneDelegate is not used, it needs to be overloaded in AppDelegate
func application(_ app: UIApplication, open url: URL, options: [UIApplication. OpenURLOptionsKey : Any] = [:]) -> Bool {
return WeCom. handleOpenURL(url: url)
}
¶ Step 5: Initiate Wecom authorization
The SDK provides three authorization methods:
- The developer calls the API when login is required:
WeCom.login { code, message, userInfo in
if (code == 200) {
// userInfo: user information
}
}
- With the semantic Hyper Component we provide, you only need to place one in the xib:
WeComLoginButton
Set the Module to WeCom, click the button after Build success to log in.
- If you want to access the whole process of Wecom authorization by yourself, after getting the authorization code, you can call the following API in exchange for Authing user information:
func loginbyWeComAgency(_ code: String, completion: @escaping(Int, String?, UserInfo?) -> Void)
parameter
- authCode Wecom authorization code
example
AuthClient().loginbyWeComAgency(authCode) { code, message, userInfo in
if (code == 200) {
// userInfo: user information
}
}