Zum Hauptinhalt springen

So konfigurieren Sie die WeChat-OAuth-Authentifizierung für Captive Portals

Dieser technische Leitfaden erklärt, wie Sie die WeChat-OAuth-Authentifizierung für Captive Portals konfigurieren. Er beschreibt detailliert die erforderlichen Plattformregistrierungen, den OAuth 2.0-Ablauf, die Scope-Auswahl und die Mechanismen zur Netzwerkdurchsetzung, die erforderlich sind, um First-Party-Daten von chinesischen Besuchern sicher zu erfassen.

📖 4 Min. Lesezeit📝 815 Wörter🔧 2 ausgearbeitete Beispiele3 Übungsfragen📚 8 Schlüsseldefinitionen

Diesen Leitfaden anhören

Podcast-Transkript ansehen
HOW TO CONFIGURE WECHAT OAUTH AUTHENTICATION FOR CAPTIVE PORTALS A Purple Technical Briefing - Approximately 10 Minutes --- INTRODUCTION AND CONTEXT (approximately 1 minute) Welcome. If you are responsible for guest WiFi at a hotel, retail chain, stadium, or conference centre that serves Chinese visitors, this briefing is for you. WeChat has 1.38 billion monthly active users, according to Tencent's 2024 data. The overwhelming majority are in China, but the platform has a meaningful international footprint too - four million users in the United States, 12 million in Malaysia, and growing numbers across Southeast Asia, Europe, and the Middle East. When a Chinese guest connects to your WiFi and sees a login page with only email, Facebook, or a voucher code, they face immediate friction. They may not have a local email address set up on that device. They almost certainly have WeChat. So the question is not whether you should offer WeChat login - it is how you configure it correctly, securely, and in a way that generates first-party data you can actually use. That is what we are going to cover today. We will walk through the OAuth 2.0 flow, the two platform registrations you need, the scope decision that determines what data you collect, the network-side enforcement mechanism, and the compliance considerations that matter in 2026. --- TECHNICAL DEEP-DIVE (approximately 5 minutes) Let us start with the architecture. A captive portal intercepts HTTP traffic from an unauthenticated device and redirects it to a login page. That login page is hosted on a portal server - either on-premises or in the cloud. When you add WeChat OAuth, you are inserting a third-party identity provider into that flow. Here is the sequence. The guest connects to your SSID. The access point or wireless controller detects that the device has no authenticated session and redirects all HTTP traffic to your captive portal URL. The portal page loads and presents login options - including WeChat. The guest taps WeChat login. Your portal server redirects the browser to WeChat's authorisation endpoint at open.weixin.qq.com, passing your AppID, the redirect URI, the response type of code, and the scope. WeChat handles the authentication entirely on its own servers. If the guest is already logged into WeChat in their browser, they see a consent screen. If they are using the WeChat in-app browser, the experience can be silent with snsapi_base scope - no consent prompt at all. WeChat then redirects back to your portal's redirect URI with a temporary authorisation code. Your portal server exchanges that code for an access token by calling api.weixin.qq.com/sns/oauth2/access_token, passing your AppID, AppSecret, the code, and grant type of authorization_code. WeChat returns an access token, a refresh token, the user's OpenID, and the scope granted. If you requested snsapi_userinfo scope, you can then make a second API call to retrieve the user's nickname, avatar, gender, and city. Now, the two platform registrations. This is where most implementations go wrong. WeChat has two separate developer platforms. The WeChat Open Platform at open.weixin.qq.com handles website applications and mobile apps. The WeChat Official Accounts Platform at mp.weixin.qq.com handles public accounts - what most venues actually need. For a captive portal serving guests inside the WeChat in-app browser, you need a Service Account on the Official Accounts Platform. A Subscription Account will not work - it does not have OAuth web page authorisation permissions. A Service Account does, and it supports both snsapi_base and snsapi_userinfo scopes. For a captive portal accessed from a standard mobile browser outside WeChat - Chrome on Android, Safari on iOS - you need a Website Application registered on the Open Platform. This uses snsapi_login scope and presents a QR code that the user scans with their WeChat app. In practice, most venue deployments use both. A guest on a hotel's WiFi might open the portal in Chrome, see a QR code, scan it with WeChat, and authenticate. Or they might follow a link in WeChat itself, land in the in-app browser, and authenticate silently with snsapi_base. Let us talk about scope selection, because this is a genuine decision point. snsapi_base returns only the OpenID - a unique identifier for that user within your Official Account. It requires no user consent prompt. The authentication is invisible to the user. This is ideal for returning guests you have already profiled, or for venues where you want zero friction at the cost of zero new data. snsapi_userinfo returns the OpenID plus the user's WeChat nickname, profile picture, gender, language setting, and city. It requires an explicit consent screen. The user sees a prompt asking whether they allow your Official Account to access their information. Most users accept, but there is friction. The right choice depends on your use case. For a first-time guest registration where you want to build a profile, use snsapi_userinfo and pair it with a GDPR-compliant consent layer on your portal page. For a returning guest who has already consented and whose profile you already hold, use snsapi_base for silent re-authentication. Now, the network enforcement side. Getting an OAuth token proves identity, but it does not automatically open the network. You need a mechanism to translate a successful authentication into network access. The two standard approaches are RADIUS Change of Authorisation, defined in RFC 3576, and MAC address bypass. With RADIUS CoA, your portal server sends a CoA request to the network controller after successful OAuth, and the controller moves the device from the unauthenticated VLAN to the guest VLAN. This works with Cisco Meraki, HPE Aruba, Ruckus, Juniper Mist, and most enterprise-grade controllers. With MAC bypass, the portal server registers the device's MAC address as an authorised client, and the controller allows it. MAC bypass is simpler to implement but less secure, because MAC addresses can be spoofed. Purple's Guest WiFi platform handles both mechanisms. After WeChat OAuth completes, Purple's cloud overlay sends the appropriate signal to the underlying hardware - whether that is Cisco Meraki, HPE Aruba, Ruckus, Juniper Mist, Ubiquiti UniFi, Cambium, Extreme, or Fortinet. The venue operator does not need to manage that translation manually. --- IMPLEMENTATION RECOMMENDATIONS AND PITFALLS (approximately 2 minutes) Let me give you the five things that cause WeChat OAuth captive portal implementations to fail. First: the redirect URI mismatch. WeChat validates the redirect URI against the authorised domain you registered on the platform. If your portal server uses a different subdomain, a different path, or HTTP instead of HTTPS, the OAuth flow fails with error 40029 - invalid code. Register every domain variant you use, including staging environments. Second: the AppSecret on the client side. Your AppSecret must never appear in client-side JavaScript or in a mobile app binary. It belongs on your server. If it is exposed, anyone can impersonate your application and call WeChat's APIs on your behalf. Third: missing CSRF protection. The state parameter in the OAuth request exists specifically to prevent cross-site request forgery. Generate a cryptographically random state value, store it in the user's session, and validate it when WeChat redirects back. Skip this and you have a real vulnerability. Fourth: the in-app browser detection gap. WeChat's in-app browser sets a specific user agent string containing "MicroMessenger". If your portal does not detect this and serve the correct OAuth flow - Official Account flow for in-app browser, Open Platform QR flow for standard browsers - users get a broken experience or an error. Fifth: GDPR and PIPL alignment. If you serve European visitors, GDPR applies to the data you collect via WeChat OAuth. If you serve Chinese visitors, China's Personal Information Protection Law - PIPL - applies to how you process their data. Both require a lawful basis for processing, clear purpose limitation, and data minimisation. snsapi_base is easier to justify under data minimisation principles than snsapi_userinfo. Whatever you collect, document your legal basis and your retention period. --- RAPID-FIRE Q AND A (approximately 1 minute) Question: Can I use WeChat login on a portal that also offers email and SMS login? Yes. Most enterprise portal platforms, including Purple, support multiple authentication methods on the same portal page. WeChat appears as one option alongside others. Question: Does WeChat OAuth work on iOS? Yes, but with a nuance. Apple's App Tracking Transparency framework does not affect server-side OAuth flows. WeChat login in Safari on iOS works via the QR code flow or redirect flow. The WeChat app itself handles the authentication. Question: What happens if WeChat's API is unavailable? Your portal should implement a fallback. If the WeChat API call times out or returns an error, redirect the user to an alternative login method. Do not leave them with a blank screen. Question: Can I use the OpenID as a persistent customer identifier? Within your Official Account, yes. The OpenID is stable for a given user and a given Official Account. If you have multiple Official Accounts, the same user will have different OpenIDs across them. For cross-account identity resolution, WeChat provides a UnionID, which requires your accounts to be linked on the Open Platform. --- SUMMARY AND NEXT STEPS (approximately 1 minute) To summarise. WeChat OAuth authentication for captive portals is a two-platform registration exercise, a scope decision, a network enforcement integration, and a compliance review. Get those four things right and you have a login method that serves over a billion potential visitors with zero password friction. The practical next steps are these. First, determine whether your visitors encounter the portal inside the WeChat in-app browser or in a standard mobile browser - that determines which platform registration you need. Second, decide on scope - snsapi_base for returning guests, snsapi_userinfo for first-time registration with consent. Third, confirm your network hardware supports RADIUS CoA or configure MAC bypass as an alternative. Fourth, review your privacy notice and consent flow against GDPR and PIPL requirements. Fifth, test the redirect URI, the state parameter validation, and the in-app browser detection before you go live. If you want to see how Purple handles WeChat OAuth as part of a broader Guest WiFi and analytics platform - across 80,000 venues and 440 million logins in 2024 - visit purple.ai or speak to your account team. Thanks for listening. --- END OF SCRIPT

header_image.png

Executive Summary

Wenn sich chinesische Besucher mit Ihrem WiFi verbinden, führt eine Anmeldeseite, die nur E-Mail oder Facebook anbietet, zu unmittelbaren Hürden. WeChat hat 1,38 Milliarden monatlich aktive Nutzer. Die Konfiguration als Identity Provider beseitigt diese Barriere. Dieser Leitfaden erklärt, wie Sie die WeChat-OAuth 2.0-Authentifizierung für Captive Portals implementieren, und beschreibt die erforderlichen Plattformregistrierungen, den OAuth-Ablauf sowie die Mechanismen zur Netzwerkdurchsetzung, die für die Umwandlung eines erfolgreichen Logins in einen Netzwerkzugriff erforderlich sind. Wir behandeln die technische Implementierung auf Enterprise-Hardware sowie die Compliance-Anforderungen unter GDPR und PIPL.

Technical Architecture

Ein Captive Portal fängt den HTTP-Traffic von einem nicht authentifizierten Gerät ab und leitet ihn auf eine Anmeldeseite weiter, die auf einem Portalserver gehostet wird. Wenn Sie WeChat-OAuth integrieren, binden Sie einen Drittanbieter-Identity-Provider in diesen Ablauf ein.

architecture_overview.png

Der Ablauf gestaltet sich wie folgt:

  1. Der Besucher verbindet sich mit der SSID.
  2. Der Access Point oder Wireless Controller erkennt das Fehlen einer authentifizierten Sitzung und leitet den HTTP-Traffic an die Captive Portal-URL weiter.
  3. Der Besucher wählt den WeChat-Login.
  4. Der Portalserver leitet den Browser an den Autorisierungsendpunkt von WeChat (open.weixin.qq.com) weiter und übergibt dabei die AppID, redirect_uri, response_type=code und den scope.
  5. WeChat übernimmt die Authentifizierung. Wenn der Besucher den In-App-Browser von WeChat mit dem Scope snsapi_base verwendet, geschieht dies im Hintergrund (silent).
  6. WeChat leitet mit einem temporären Autorisierungscode zurück zur redirect_uri des Portals.
  7. Der Portalserver tauscht diesen Code durch den Aufruf von api.weixin.qq.com/sns/oauth2/access_token gegen ein Access Token aus.
  8. WeChat gibt ein access_token, ein refresh_token und die openid des Nutzers zurück.

Platform Registration Requirements

Die Implementierung des WeChat-Logins erfordert die Registrierung auf der korrekten Entwicklerplattform. WeChat betreibt zwei verschiedene Plattformen; die Auswahl der falschen Plattform führt zum Fehlschlagen der Integration.

WeChat Official Accounts-Plattform

Für ein Captive Portal, das Besucher innerhalb des WeChat-In-App-Browsers bedient, benötigen Sie einen Service Account auf der Official Accounts-Plattform (mp.weixin.qq.com). Einem Subscription Account fehlen die erforderlichen Berechtigungen für die OAuth-Webseitenautorisierung. Ein Service Account unterstützt sowohl den Scope snsapi_base als auch snsapi_userinfo.

WeChat Open-Plattform

Für ein Captive Portal, auf das über einen Standard-Mobilbrowser außerhalb von WeChat zugegriffen wird (wie Chrome unter Android oder Safari unter iOS), benötigen Sie eine auf der Open-Plattform (open.weixin.qq.com) registrierte Website-Anwendung. Diese verwendet den Scope snsapi_login und zeigt einen QR-Code an, den der Nutzer mit seiner WeChat-App scannt.

Die meisten Enterprise-Bereitstellungen erfordern beide Registrierungen, um alle Zugriffsmethoden abzudecken.

Scope-Auswahl und Datenerfassung

Der Scope-Parameter bestimmt, welche Daten WeChat an Ihren Portalserver zurückgibt. Diese Entscheidung beeinflusst sowohl die Nutzerhürden als auch die Einhaltung des Datenschutzes.

scope_comparison_chart.png

snsapi_base

Dieser Scope gibt nur die OpenID zurück, eine eindeutige Kennung für den Nutzer innerhalb Ihres Official Accounts. Er erfordert keine Zustimmung des Nutzers, wodurch die Authentifizierung für den Nutzer unsichtbar bleibt. Dies ist optimal für wiederkehrende Besucher, von denen Sie bereits ein Profil besitzen, oder für Standorte, die minimale Hürden einer neuen Datenerfassung vorziehen.

snsapi_userinfo

Dieser Scope gibt die OpenID sowie den WeChat-Spitznamen, das Profilbild, das Geschlecht, die Spracheinstellung und die Stadt des Nutzers zurück. Er erfordert einen expliziten Zustimmungsbildschirm, was eine zusätzliche Hürde darstellt. Verwenden Sie dies für die Registrierung von Erstbesuchern, wenn die Erstellung eines Profils erforderlich ist, kombiniert mit einer GDPR-konformen Einwilligungsebene.

Integration der Netzwerkdurchsetzung

Der Erhalt eines OAuth-Tokens beweist die Identität, öffnet jedoch nicht das Netzwerk. Sie müssen eine erfolgreiche Authentifizierung mithilfe von Standardprotokollen in einen Netzwerkzugriff umwandeln.

RADIUS Change of Authorisation (CoA)

Definiert in IEEE 802.1X und RFC 3576 ermöglicht RADIUS CoA dem Portalserver, nach erfolgreichem OAuth eine Anfrage an den Netzwerk-Controller zu senden. Der Controller verschiebt das Gerät dann aus dem nicht authentifizierten VLAN in das Gäste-VLAN. Dies ist der Standard für Enterprise-Hardware wie Cisco Meraki, HPE Aruba, Ruckus und Juniper Mist.

MAC-Adressen-Bypass

Alternativ registriert der Portalserver die MAC-Adresse des Geräts als autorisierten Client, und der Controller lässt sie zu. Dies ist zwar einfacher zu implementieren, aber weniger sicher, da MAC-Adressen gefälscht (gespooft) werden können.

Das Cloud-Overlay von Purple automatisiert diese Übersetzung und sendet das entsprechende Signal an die zugrunde liegende Hardware (einschließlich Ubiquiti UniFi, Cambium, Extreme und Fortinet), sobald das WeChat-OAuth abgeschlossen ist.

Compliance- und Sicherheitsüberlegungen

GDPR- und PIPL-Konformität

Wenn Sie europäische Besucher bedienen, gilt die GDPR für die über WeChat-OAuth erfassten Daten. Wenn Sie chinesische Besucher bedienen, gilt das chinesische Gesetz zum Schutz persönlicher Daten (PIPL). Beide Rahmenwerke erfordern eine rechtmäßige Grundlage für die Verarbeitung, eine klare Zweckbindung und Datenminimierung. Der Scope snsapi_base lässt sich leichter mit den Grundsätzen der Datenminimierung vereinbaren als snsapi_userinfo.

CSRF-Schutz

Der state-Parameter in der OAuth-Anfrage verhinverhindert Cross-Site-Request-Forgery. Sie müssen einen kryptografisch zufälligen State-Wert generieren, diesen in der Benutzersitzung speichern und validieren, wenn WeChat zurückleitet.

Redirect-URI-Validierung

WeChat validiert die redirect_uri gegen die auf der Plattform registrierte autorisierte Domain. Wenn Ihr Portal-Server eine andere Subdomain, einen anderen Pfad oder HTTP anstelle von HTTPS verwendet, schlägt der OAuth-Flow mit dem Fehler 40029 fehl.

Weitere Informationen zur Sicherung Ihres Netzwerks finden Sie in unserem Leitfaden Enterprise WiFi Security: Ein vollständiger Leitfaden für 2026 .

Schlüsseldefinitionen

snsapi_base

A WeChat OAuth scope that returns only the user's OpenID without displaying a consent prompt.

Used when IT teams need to authenticate returning visitors silently without causing login friction.

snsapi_userinfo

A WeChat OAuth scope that returns the OpenID along with demographic data (nickname, gender, city) and requires explicit user consent.

Used during first-time registration when marketing teams need to build a visitor profile.

OpenID

A unique identifier for a specific user within a specific WeChat Official Account.

Used as the primary key in the portal database to track visitor behaviour and return visits.

RADIUS CoA

Change of Authorisation. A mechanism defined in RFC 3576 that allows a server to modify the authorisation state of an active session.

Used by the portal server to tell the wireless controller to grant network access after successful WeChat authentication.

PIPL

Personal Information Protection Law. China's comprehensive data privacy regulation.

Must be considered alongside GDPR when designing the consent flow for Chinese visitors using WeChat login.

AppID and AppSecret

The credentials provided by WeChat to identify and authenticate your application.

The AppSecret must remain securely on the portal server and never be exposed in client-side code.

State Parameter

A cryptographically random string passed in the OAuth request and validated upon return.

Essential for preventing Cross-Site Request Forgery (CSRF) attacks on the captive portal.

MAC Address Bypass

A method of granting network access by authorising the device's hardware address rather than requiring 802.1X authentication.

An alternative to RADIUS CoA for simpler network setups, though less secure.

Ausgearbeitete Beispiele

A luxury retail brand in London wants to offer WeChat login for Chinese shoppers. They want to collect demographic data to understand their customer base, but they are concerned about GDPR compliance and high drop-off rates at the portal.

The retailer should register a Service Account on the WeChat Official Accounts Platform. They must configure the portal to use the snsapi_userinfo scope for first-time connections to gather demographic data (nickname, gender, city). To ensure GDPR compliance, the portal page must display a clear, conscious-choice opt-in before the WeChat redirect, explaining exactly what data is collected and why. For returning shoppers, the portal should detect the MAC address and use snsapi_base for silent re-authentication, minimising friction.

Kommentar des Prüfers: This approach balances data collection with user experience. By limiting the high-friction `snsapi_userinfo` flow to the first visit and using `snsapi_base` subsequently, the retailer maximises conversion while remaining compliant with data minimisation principles.

A stadium deploys a new WiFi network using HPE Aruba controllers. They have configured WeChat OAuth, and the portal successfully receives the access token, but the visitor's device remains on the captive portal page and cannot access the internet.

The integration lacks a network enforcement mechanism. The portal server has verified the user's identity with WeChat, but it has not instructed the HPE Aruba controller to grant access. The portal server must be configured to send a RADIUS Change of Authorisation (CoA) message to the controller, instructing it to transition the user's MAC address from the pre-authentication role to the authenticated guest role.

Kommentar des Prüfers: This highlights the distinction between identity verification and network access control. Enterprise networks require a protocol like RADIUS CoA to bridge the gap between the web application (portal) and the network infrastructure.

Übungsfragen

Q1. You are deploying a captive portal across a retail chain. Testing shows that users opening the portal in Safari on iOS receive an error when selecting WeChat login, but users opening the portal from within a WeChat message link authenticate successfully. What is the likely cause?

Hinweis: Consider the difference between the WeChat in-app browser and standard mobile browsers.

Musterlösung anzeigen

The implementation is likely relying solely on a Service Account registered on the Official Accounts Platform, which only supports OAuth within the WeChat in-app browser. To support Safari on iOS, you must also register a Website Application on the WeChat Open Platform and implement user agent detection to route Safari users to the QR code flow.

Q2. Your portal server logs show frequent 40029 'invalid code' errors returning from the WeChat API during the access token exchange. What configuration should you check first?

Hinweis: Think about how WeChat validates the source of the authentication request.

Musterlösung anzeigen

You should verify the redirect_uri configuration. WeChat strictly validates the redirect URI against the authorised domain registered in the developer console. If the portal is using a different subdomain, or if it drops HTTPS, WeChat will reject the code exchange.

Q3. A venue operator wants to collect visitor data but insists on zero friction during the login process. They request that you configure WeChat login to collect the visitor's nickname and city without showing a consent prompt. How do you respond?

Hinweis: Review the capabilities of the different OAuth scopes.

Musterlösung anzeigen

You must inform the operator that this is technically impossible. Collecting demographic data like nickname and city requires the snsapi_userinfo scope, which mandatorily triggers a WeChat consent prompt. To achieve zero friction, you must use snsapi_base, which operates silently but only returns the OpenID.