Add Alipay as an OAuth provider
This guide explains how to let users sign in to Casdoor with their Alipay account. The Alipay provider signs its requests with certificates.
Learning outcomes
- Get the APPID and the certificates of an Alipay application.
- Store the certificates in Casdoor.
- Add Alipay as an OAuth provider in Casdoor.
What you need
- A developer account on the Alipay Open Platform. See Preparation before access.
- Administrator access to the Casdoor admin console
Get the APPID and the certificates
- Create an application in the console of the Alipay Open Platform and note its APPID. See Find the APPID.
- Generate an RSA2 key pair as the Alipay documentation describes. You get
appPrivateKey.txtandappPublicKey.txt. - Upload the application certificate in the Alipay application and download three files:
alipayRootCert.crt,appCertPublicKey.crt, andalipayCertPublicKey.crt. - Set the callback URL of the Alipay application to the callback URL of Casdoor,
https://<your-casdoor-host>/callback. See Redirect URL and callback URL.
Store the certificates in Casdoor
In the Casdoor admin console, open the Certs page and add two certificates.
The application certificate:
| Casdoor field | Value |
|---|---|
| Type | x509 |
| Certificate | content of appCertPublicKey.crt |
| Private key | content of appPrivateKey.txt |
The root certificate:
| Casdoor field | Valeur |
|---|---|
| Type d'entrée | x509 |
| Certificat | content of alipayCertPublicKey.crt |
| Clé privée | content of alipayRootCert.crt |
Add the provider in Casdoor
- Go to Identity > Providers and add a provider.
- Set Category to
OAuthand Type toAlipay. - Enter the APPID as the Client ID, and select the application certificate and the root certificate that you created.
- Save the provider.
Dépannage
If the sign-in fails, for example with asn1: syntax error: sequence truncated, check the following:
- In the application certificate, Certificate is
appCertPublicKey.crtand Private key isappPrivateKey.txt. - In the root certificate, Certificate is
alipayCertPublicKey.crtand Private key isalipayRootCert.crt. - The APPID belongs to the Alipay application.
- The callback URL is set correctly in Alipay and in Casdoor.