Generic API plugin
Summary
Sometimes the Perl language can be a foil for people who want to write plugins.
Design proposition
A new list in manager for remote plugins. When portal starts, it contacts external API to ask for its entry-points:
// POST /remote/api HTTP/1.0
{
"action":"register",
"portal":"https://auth.example.com",
"auth": "LDAP",
"userDB": "LDAP",
}
// Response
{
"action":"register",
"entryPoints": {
"afterData": {
"endpoint": "https://remote/api/afterdata",
"requestKeys": ["sessionInfo","ENV"]
}
},
"authRoutes": {
"/myapi/": {
"requestKeys": ["path","sessionInfo"]
}
}
}
Then during authentication, portal launch this request:
// POST /remote/api HTTP/1.0
{
"action": "entryPoint",
"entryPoint": "afterData",
"requestKeys": {
"sessionInfo": {
"_session_id": "aabbcc",
"_user": "dwho"
//...
},
"ENV": {
"REQUEST_URI": "/"
//...
}
}
}
// Response
{
"action": [
"setKeysInSession": {
"_myapi_id": "zzkkvv"
}
],
"code": 0 // a portal code
}
If an authenticated user calls https://auth.example.com/myapi/something
:
// POST /api/afterdata HTTP/1.1
{
"action": "authRoute",
"requestKeys": {
"path": "/myapi/something",
"sessionInfo": {
"_session_id": "aabbcc",
"_user": "dwho"
//...
}
}
}
// Response: a PSGI response
[
200,
["Content-Type", "application/json"],
["{\"result\":true}"]
]