forked from IQSS/dataverse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged OIDC implementeation from IQSS#10905
- Loading branch information
Showing
32 changed files
with
677 additions
and
950 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
New OpenID Connect implementation including new log in scenarios (see [the guides](https://dataverse-guide--10905.org.readthedocs.build/en/10905/installation/oidc.html#choosing-provisioned-providers-at-log-in)) for the current JSF frontend, the new Single Page Application (SPA) frontend, and a generic API usage. The API scenario using Bearer Token authorization is illustrated with a Python script that can be found in the `doc/sphinx-guides/_static/api/bearer-token-example` directory. This Python script prompts you to log in to the Keycloak in a new browser window using selenium. You can run that script with the following commands: | ||
|
||
```shell | ||
cd doc/sphinx-guides/_static/api/bearer-token-example | ||
./run.sh | ||
``` | ||
|
||
This script is safe for production use, as it does not require you to know the client secret or the user credentials. Therefore, you can safely distribute it as a part of your own Python script that lets users run some custom tasks. | ||
|
||
The following settings become deprecated with this change and can be removed from the configuration: | ||
- `dataverse.auth.oidc.pkce.enabled` | ||
- `dataverse.auth.oidc.pkce.method` | ||
- `dataverse.auth.oidc.pkce.max-cache-size` | ||
- `dataverse.auth.oidc.pkce.max-cache-age` | ||
|
||
The following settings new: | ||
- `dataverse.auth.oidc.issuer-identifier` | ||
- `dataverse.auth.oidc.issuer-identifier-field` | ||
- `dataverse.auth.oidc.subject-identifier-field` | ||
|
||
Also, the bearer token authentication is now always enabled. Therefore, the `dataverse.feature.api-bearer-auth` feature flag is no longer used and can be removed from the configuration as well. | ||
|
||
The new implementation relies now on the builtin OIDC support in our application server (Payara). With this change the Nimbus SDK is no longer used and is removed from the dependencies. |
28 changes: 28 additions & 0 deletions
28
doc/sphinx-guides/_static/api/bearer-token-example/get_session.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import contextlib | ||
import selenium.webdriver as webdriver | ||
import selenium.webdriver.support.ui as ui | ||
import re | ||
import json | ||
import requests | ||
|
||
with contextlib.closing(webdriver.Firefox()) as driver: | ||
driver.get("http://localhost:8080/oidc/login?target=API&oidcp=oidc-mpconfig") | ||
wait = ui.WebDriverWait(driver, 100) # timeout after 100 seconds | ||
wait.until(lambda driver: "accessToken" in driver.page_source) | ||
driver.get("view-source:http://localhost:8080/api/v1/oidc/session") | ||
result = wait.until( | ||
lambda driver: ( | ||
driver.page_source if "accessToken" in driver.page_source else False | ||
) | ||
) | ||
m = re.search("<pre>(.+?)</pre>", result) | ||
if m: | ||
found = m.group(1) | ||
session = json.loads(found) | ||
|
||
token = session["data"]["accessToken"] | ||
endpoint = "http://localhost:8080/api/v1/users/:me" | ||
headers = {"Authorization": "Bearer " + token} | ||
|
||
print() | ||
print(requests.get(endpoint, headers=headers).json()) |
2 changes: 2 additions & 0 deletions
2
doc/sphinx-guides/_static/api/bearer-token-example/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
selenium | ||
requests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/bash | ||
|
||
python3 -m venv run_env | ||
source run_env/bin/activate | ||
python3 -m pip install -r requirements.txt | ||
python3 get_session.py | ||
rm -rf run_env |
22 changes: 22 additions & 0 deletions
22
doc/sphinx-guides/_static/frontend/PKCE-example/PKCE-example.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!doctype html> | ||
<html> | ||
|
||
<body> | ||
<script src="http://unpkg.com/[email protected]/dist/keycloak-authz.js"></script> | ||
<script src="http://unpkg.com/[email protected]/dist/keycloak.js"></script> | ||
|
||
<script> | ||
const kc = new Keycloak({ | ||
url: 'http://keycloak.mydomain.com:8090', | ||
realm: 'test', | ||
clientId: 'test' | ||
}); | ||
kc.init({ | ||
pkceMethod: 'S256', | ||
redirectUri: 'http://localhost:8080/api/v1/users/:me' | ||
}); | ||
kc.login(); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6430,3 +6430,46 @@ Parameters: | |
``per_page`` Number of results returned per page. | ||
.. _oidc-session: | ||
Session | ||
------- | ||
The Session API is used to get the information on the current OIDC session (after being successfully authenticated using the OpenID Connect :ref:`oidc-log-in`). | ||
You can be either redirected to that endpoint using the `API` log in flow as illustrated in the :ref:`bearer-tokens` example, or going to this endpoint directly, | ||
after logging-in in your browser. The returned JSON looks like this: | ||
.. code-block:: json | ||
{ | ||
"status": "OK", | ||
"data": { | ||
"user": { | ||
"id": 3, | ||
"userIdentifier": "aUser", | ||
"lastName": "User", | ||
"firstName": "Dataverse", | ||
"email": "[email protected]", | ||
"isSuperuser": false, | ||
"createdTime": "2024-10-07 08:26:29.453", | ||
"lastLoginTime": "2024-10-07 08:26:29.453", | ||
"deactivated": false, | ||
"mutedEmails": [], | ||
"mutedNotifications": [] | ||
}, | ||
"session": "6164900bf35e7f576a92e4f771cc", | ||
"accessToken": "eyJhbGc...7VvYOMYxreH-Uo3RpaA" | ||
} | ||
} | ||
You can then use the retrieved `session` and `accessToken` for subsequent calls to the API or the session endpoint, as illustrated in the following curl examples: | ||
.. code-block:: bash | ||
export BEARER_TOKEN=eyJhbGc...7VvYOMYxreH-Uo3RpaA | ||
export SESSION=6164900bf35e7f576a92e4f771cc | ||
export SERVER_URL=https://demo.dataverse.org | ||
curl -H "Authorization: Bearer $BEARER_TOKEN" "$SERVER_URL/api/oidc/session" | ||
curl -v --cookie "JSESSIONID=$SESSION" "$SERVER_URL/api/oidc/session" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ services: | |
DATAVERSE_DB_HOST: postgres | ||
DATAVERSE_DB_PASSWORD: secret | ||
DATAVERSE_DB_USER: dataverse | ||
DATAVERSE_FEATURE_API_BEARER_AUTH: "1" | ||
DATAVERSE_MAIL_SYSTEM_EMAIL: "Demo Dataverse <[email protected]>" | ||
DATAVERSE_MAIL_MTA_HOST: "smtp" | ||
JVM_ARGS: -Ddataverse.files.storage-driver-id=file1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.