wecom_auth_plus
A Flutter plugin for WeCom (Enterprise WeChat) auth/login flows.
Features
configure(scheme, corpId, agentId)isAppInstalled()register()auth(state)resetAuth()authLoginAuto(...)
Installation
dependencies:
wecom_auth_plus: ^0.0.7
Quick Start
final plugin = WecomAuthPlus();
final result = await plugin.authLoginAuto(
scheme: 'wwauth_your_corpid_agentid',
corpId: 'wwxxxxxxxxxxxxxxxx',
agentId: '1000004',
state: 'tenant_a',
);
if (result.success) {
final authCode = result.authCode;
// Send authCode to your backend for WeCom user binding/login.
} else {
debugPrint('WeCom auth failed: ${result.code} ${result.message}');
}
API
configure(scheme, corpId, agentId)isAppInstalled()register({scheme, corpId, agentId})auth({state})resetAuth()authLoginAuto({scheme, corpId, agentId, state})
Returned Fields
WeComAuthResult includes:
success: whether current step succeedscode: plugin-level result codemessage: user-facing messageerrCode: native WeCom err code when availableauthCode: authorization code when successfulstate: state returned by callbackraw: original map from native side
Android Setup Notes
- Ensure WeCom app is installed on test device.
- Ensure your package name and app signature SHA1 are configured in WeCom open platform.
- Ensure
scheme / corpId / agentIdexactly match WeCom platform settings. - Ensure callback is routed back to your app (scheme-based intent).
Plugin itself already declares:
<queries><package android:name="com.tencent.wework"/></queries>
iOS Setup Notes
In your iOS app Info.plist:
- Add your callback URL scheme (same as
schemepassed to plugin). - Add
LSApplicationQueriesSchemescontainingwxworkandwxworklocal. - Ensure WeCom platform config matches your bundle id and scheme exactly.
Troubleshooting
last auth request is still pending
If the previous WeCom auth flow was interrupted or returned abnormally, call:
await plugin.resetAuth();
authLoginAuto(...) already does this automatically in 0.0.7+.
sendMessage returned false (Android)
Usually means request cannot be accepted by WeCom SDK environment. Check:
- WeCom installed on device.
- Open-platform whitelist/signature/package config matched.
scheme / corpId / agentIdmatched.
errCode = 5 / auth_failed
Usually an authorization rejection or environment mismatch:
- Check tenant app permissions in WeCom admin console.
- Verify callback scheme and app signature.
- Confirm account is allowed to use current WeCom app/agent.
Notes
- This plugin focuses on auth-chain integration and callback parsing.
- Final account binding/login should be completed by your backend using
authCode.