Authing DocsDocuments
Concept
workflow
Guides
Development Integration
Application integration
Concept
workflow
Guides
Development Integration
Application integration
Old Version
Development Integration
  • Single Sign-On (SSO)
  • Login component

  • JavaScript/Node.js

  • Java / Kotlin

  • Python

  • C#

  • PHP

  • Go

  • Ruby
  • Android

  • iOS

    • Quick start
    • Auth Flow
    • APIs

    • Third-party identity source

      • Wechat
      • Apple
      • Google
      • Facebook
      • Wechat Miniprogram
      • Tencent
      • Sina Weibo
      • Baidu
      • LinkedIn
      • Github
      • Gitee
      • GitLab
      • Xiaomi
      • WeCom
      • Lark
      • DingTalk
      • Line
      • Slack
    • Typical scene

    • On-premise
    • WebAuthn
    • Error Code List
  • Flutter

  • React Native
  • WeChat Mini Program
  • WeChat webpage authorization
  • Framework Integration
  • Error code
  1. Development Integration
  2. /
  3. iOS
  4. /
  5. Third-party identity source
  6. /
  7. Wechat Miniprogram

¶ APP Pull up the WeChat Mini Program Login

Update Time: 2025-05-14 08:32:28
Edit

¶ Preparation

In WeChat Open Platform (opens new window) and Authing Console (opens new window) For configuration.


¶ Integrate APP Pull up the WeChat Mini Program login steps

¶ Step 1: Add dependencies

  1. Enter: https://github.com/Authing/authing-binary in the swift package search bar.

  2. Select Authing-binary (opens new window).

Authing-binary (opens new window) depends on Guard-iOS SDK (opens new window).

  1. Select Up to Next Major Version 1.0.0 for the dependency rule.

  2. Check Wechat after Add Package.


¶ Step 2: Modify project configuration

  1. Add the WeChat whitelist in Info.plist

key: LSApplicationQueriesSchemes

value: weixin, weixinULAPI

Pay attention to capitalization

You can also open Info.plist via Source Code, and then copy and paste the following code:

<plist version="1.0">
<dict>
     ...
     <key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
<string>weixinULAPI</string>
</array>
     ...
</dict>
</plist>
  1. Configure the applet bounce URL Click the plus sign in Targets -> Info -> URL Types, URL Schemes add the AppID of the application in the WeChat development platform.

¶ Step 3: Initialize the Mini Program

import Guard
import Facebook

class AppDelegate: UIResponder, UIApplicationDelegate {
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
         Authing.start(<#AUTHING_APP_ID#>)
         Facebook.register(application, didFinishLaunchingWithOptions: launchOptions)
     }

     func application(_ app: UIApplication, open url: URL, options: [UIApplication. OpenURLOptionsKey : Any] = [:]) -> Bool {
         if "\(url)". contains(Facebook. getAppId()) {
             return Facebook. application(app, open: url, options: options)
         }
     }
}

¶ Step 3: Initialize the Miniprogram login

import Guard
import WechatLogin

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
     Authing.start(<#AUTHING_APP_ID#>)
     WechatLogin.registerApp(appId: <#your_wechat_appid#>, universalLink: <#your_deep_link#>)
}

¶ Step 4: Handle wechat login callback

After wechat returns to the application, if SceneDelegate is used, you need to reload the following function in Scenedelegate. swift:

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "wechatLoginOK"), object: userActivity)
    _ =  WechatLogin.handleOpenURL(url: url)
}

If SceneDelegate is not used, reload the AppDelegate:

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "wechatLoginOK"), object: userActivity)
    return WechatLogin.handleOpenURL(url: url)
}

¶ Step 5: Initiate Mini Program Login Authorization

¶ Mini Program authorization login

func loginByMiniProgram(_ launchMiniProgramReq: WXLaunchMiniProgramReq? = nil, completion: @escaping Authing.AuthCompletion) -> Void

parameter

  • launchMiniProgramReq The request sent to WeChat, which includes parameters such as Mini Program originalID, page path, Mini Program version, etc. If this parameter is not passed, the original ID configured by the Authing Console App to launch the Mini Program will be used by default.

example

WechatLogin.loginByMiniProgram(launchMiniProgramReq: launchMiniProgramReq) { code, message, userInfo in
     if (code == 200) {
         // login successful
         // userInfo
     }
}

If the developer integrates a small program to log in to the SDK, after getting the authorization code, he can call the following API in exchange for the Authing user information:

¶ Login via the Mini Program authorization code

func loginByMiniprogram(code: String, phoneInfoCode: String?, completion: @escaping(Int, String?, UserInfo?) -> Void)

parameter

  • code The code returned by the applet wx.login()
  • phoneInfoCode The code returned by the applet to get the phone number

example

AuthClient().loginByMiniprogram(code: "code", phoneInfoCode: "phoneInfoCode") { code, message, userInfo in
     // userInfo
}
Prev: Facebook Next: Tencent
  • Preparation
  • Integrate APP Pull up the WeChat Mini Program login steps

User identity management

Integrated third-party login
Mobile phone number flash check (opens new window)
Universal login form component
Custom authentication process

Enterprise internal management

Single Sign On
Multi-factor Authentication
Authority Management

Developers

Development Document
Framework Integration
Blog (opens new window)
GitHub (opens new window)
Community User Center (opens new window)

Company

400 888 2106
sales@authing.cn
16 / F, Block B, NORTH STAR CENTURY CENTER, Beijing(Total)
room 406, 4th floor, zone B, building 1, No. 200, Tianfu Fifth Street, Chengdu(branch)

Beijing ICP No.19051205-1

© Beijing Steamory Technology Co.