APISIX
Casdoor can use the OIDC protocol to link to APISIX, and this document will show you how to do it.
The following are some of the names in the configuration:
CASDOOR_HOSTNAME
: Domain name or IP where Casdoor server is deployed.
APISIX_HOSTNAME
: Domain name or IP where APISIX is deployed.
Step1. Deploy Casdoor and APISIX
Firstly, the Casdoor and APISIX should be deployed.
After a successful deployment, you need to ensure:
- Casdoor can be logged in and used normally.
- Set Casdoor’s
origin
value (conf/app.conf) toCASDOOR_HOSTNAME
.
Step2. Configure Casdoor application
- Create or use an existing Casdoor application.
- Add a redirect url:
http://APISIX_HOSTNAME/REDIRECTWHATYOUWANT
,and changeREDIRECTWHATYOUWANT
to the redirect url you need. - Select “JWT-Empty” for the Token format option
- Add provider you want and supplement other settings.
Not surprisingly, you can get two values on the application settings page: Client ID
and Client secret
like the picture above, we will use them in next step.
Open your favorite browser and visit: http://`CASDOOR_HOSTNAME`/.well-known/openid-configuration, you will see the OIDC configure of Casdoor.
Step3. Configure APISIX
APISIX has official OIDC support, which is implemented using lua-resty-openidc.
You can customize the settings according to the APISIX OIDC documentation, in which the following routing settings will be used:
#Use your own X-Api-Key
$ curl -XPOST APISIX_HOSTNAME/apisix/admin/routes -H "X-Api-Key: edd1c9f034335f136f87ad84b625c8f1" -d '{
"uri": "/get",
"name": "apisix_casdoor_test",
"plugins": {
"openid-connect": {
"client_id": "Client ID",
"client_secret": "Client secret",
"discovery": "http://CASDOOR_HOSTNAME/.well-known/openid-configuration",
"introspection_endpoint_auth_method": "client_secret_basic",
"logout_path": "/logout",
"realm": "master",
"redirect_uri": "http://APISIX_HOSTNAME/REDIRECTWHATYOUWANT",
"bearer_only": false,
"set_id_token_header": false,
"access_token_in_authorization_header": true,
"set_access_token_header": true,
"set_userinfo_header": false,
"realm": "master"
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org:80": 1
}
}
}'
Now, visit http://APISIX_HOSTNAME/get
, the browser will redirect you to the casdoor login page, and after successfully logging in, you will, not surprisingly, see that we have sent a request to httpbin.org.