Saltar al contenido principal

Add WeChat as an OAuth provider

This guide explains how to let users sign in to Casdoor with WeChat: on a PC by scanning a QR code with the WeChat app, and on a phone inside the WeChat built-in browser.


Learning outcomes​

  • Get the credentials from the WeChat Open Platform and the WeChat Media Platform.
  • Add WeChat providers for PC and for mobile.
  • Show the WeChat tab on the sign-in page.

What you need​

  • An approved application on the WeChat Open Platform, for sign-in on a PC
  • For sign-in inside WeChat: an official account on the WeChat Media Platform
  • Administrator access to the Casdoor admin console

About sign-in with WeChat​

Sub typeWhere users sign inCredentials
Web (default)In a PC browser, by scanning a QR code with the WeChat appClient ID and Client secret from the WeChat Open Platform
MóvilIn the built-in browser of the WeChat appClient ID 2 and Client secret 2 from the WeChat Media Platform, and the Access token that you set in the server configuration of the official account

WeChat doesn't allow sign-in from other apps or from mobile browsers outside WeChat. To support both PC and WeChat, create two WeChat providers, one with each sub type.

consejo

Link your WeChat Open Platform account and your WeChat Media Platform account in the Open Platform. WeChat then gives the same user the same identity on PC and inside WeChat.

Add the provider in Casdoor​

  1. On the WeChat Open Platform, get the App ID and App Secret of your approved application.

    WeChat Open Platform application

  2. In the Casdoor admin console, go to Identity > Providers and add a provider.

  3. Set Category to OAuth, Type to WeChat, and Sub type to Web or Mobile.

  4. Enter the credentials of the sub type, as in the table above.

  5. If you set both credential pairs and the access token, you can turn on Use WeChat Media Platform in PC. Users on a PC can then also be prompted to follow the official account before they scan the QR code. This works on a PC only, because a phone can't scan its own QR code.

  6. Save the provider.

Show WeChat on the sign-in page​

  1. Open the edit page of the application.

  2. Add the WeChat provider on the Providers tab.

  3. Add WeChat to the Signin methods.

  4. Save the application.

    WeChat in the Signin methods

The sign-in page now has a WeChat tab:

  1. The user selects the WeChat tab. The page shows a QR code.
  2. The user scans the QR code with the WeChat app and authorizes the sign-in.
  3. If the QR code expires, the user clicks the refresh button below it.

WeChat tab on the sign-in page

See also​