API Authentifizierung per Benutzeranmeldung
Gleich vorweg, die API Keys sind dieser Art der Authentifizierung per Benutzername und Passwort zu bevorzugen.
|
Diese Art kann nicht verwendet werden, wenn ein OIDC basierter Identity Provider zum Einsatz kommt. In diesem Fall sind auf jeden Fall die API Keys zu verwenden. |
Es wird trotzdem an einem exemplarischen Beispiel gezeigt, wie es abläuft.
Anmeldung als Benutzer 'bpcadmin'
Aufruf per CURL
curl -X POST \
-c cookies.txt \
-H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
"http://localhost:8181/cxf/bpc-core/authentication" \
--data-urlencode "tenantname=DEFAULT" \
--data-urlencode "username=bpcadmin" \
--data-urlencode "password=bpcadmin"
Antwort
{
"loginName": "bpcadmin",
"email": "",
"firstName": "",
"lastName": "",
"organisations": [ "DEFAULT" ],
"inactiveOrganisations": [],
"roles": [ "bpcadmin", "bpcuser" ],
"rights": [ "loadModule_dashboard", "loadModule_account", "loadModule_blank" ],
"principals": {
"X-Csrf-Token": [ "_4rpjBU5_dEFBVVAVkF6LUKV1AjvdRWJSC0QLrOoZtagdFfILQoOgtGhu4X8ppd2X2kbowjl8UEp1j_tKEPaIw1c2FbcQNJfaAX-AgoiI8Cse9_FHPO9omcm8z-UE3F-_ScFZfqIL9ZRPAWWpfkM48G20OU3nu8_E5sPdIqF8EY" ],
"org.apache.karaf.jaas.boot.principal.UserPrincipal": [ "bpcadmin" ]
},
"customData": {},
"expirationDate": 1648067566204
}
Sie müssen die Cookies speichern und den X-Csrf-Token aus der JSON-Antwort behalten. Er wird im nächsten Schritt verwendet.
Überprüfung ob die Session gültig ist
Aufruf per CURL
curl -X GET \
-b cookies.txt \
"http://localhost:8181/cxf/bpc-core/authentication"
Antwort wenn erfolgreich
{
"loginName": "bpcadmin",
"email": "",
"firstName": "",
"lastName": "",
"organisations": [ "DEFAULT" ],
"inactiveOrganisations": [],
"roles": [ "bpcadmin", "bpcuser" ],
"rights": [ "loadModule_dashboard", "loadModule_account", "loadModule_blank" ],
"principals": {
"X-Csrf-Token": [ "_4rpjBU5_dEFBVVAVkF6LUKV1AjvdRWJSC0QLrOoZtagdFfILQoOgtGhu4X8ppd2X2kbowjl8UEp1j_tKEPaIw1c2FbcQNJfaAX-AgoiI8Cse9_FHPO9omcm8z-UE3F-_ScFZfqIL9ZRPAWWpfkM48G20OU3nu8_E5sPdIqF8EY" ],
"org.apache.karaf.jaas.boot.principal.UserPrincipal": [ "bpcadmin" ]
},
"customData": {},
"expirationDate": 1648067566204
}
Antwort wenn ein Fehler auftrat
{
"error": {
"messageKey": "CORE_ERROR_IDENTITY_PROVIDER_AUTHENTICATION_FAILED",
"code": 540,
"name": "AUTHENTICATION_UNAUTHORIZED",
"message": "Authentication failed",
"properties": {}
}
}
API Endpunkt aufrufen
Dabei die Cookies und den X-Csrf-Token setzen.
curl -X GET \
-b cookies.txt \
-H 'X-Csrf-Token: _4rpjBU5_dEFBVVAVkF6LUKV1AjvdRWJSC0QLrOoZtagdFfILQoOgtGhu4X8ppd2X2kbowjl8UEp1j_tKEPaIw1c2FbcQNJfaAX-AgoiI8Cse9_FHPO9omcm8z-UE3F-_ScFZfqIL9ZRPAWWpfkM48G20OU3nu8_E5sPdIqF8EY' \
-H 'Content-Type: application/json' \
"http://localhost:8181/cxf/bpc-core/opensearch/indices"
|
Der |
Keywords: