Skip to content

Commit 7567cd7

Browse files
committed
docs: describe front service procedure
1 parent e809b0b commit 7567cd7

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,66 @@ The key benefit of this design is that it requires zero changes to the back serv
161161
sudo -u {USER} /opt/shibboleth-idp/bin/plugin.sh -i $PWD/andrvotr-dist/target/idp-plugin-andrvotr-*-SNAPSHOT.tar.gz --noCheck
162162
```
163163

164-
<!-- TODO: ## Developing compatible front services -->
164+
## Developing front services
165+
166+
Front services which want to use Andrvotr to connect to a back service must follow this procedure.
167+
168+
Andrvotr currently does not have a reusable client library in any language. You must implement it yourself.
169+
170+
You will need:
171+
172+
- a SAML Service Provider module or library
173+
- an HTTP client library with cookie management
174+
- an HTML parser library
175+
176+
### Login procedure
177+
178+
1. Read the SAML attribute containing the Andrvotr Authority Token.
179+
- It is identified by `Name="tag:fmfi-svt.github.io,2024:andrvotr-authority-token"` and
180+
`NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"`.
181+
- How to read attributes depends on your SP software. In most cases it should be trivial.
182+
- If you use mod_shib (Shibboleth SP), it is not trivial because it discards any unknown attributes. Edit `/etc/shibboleth/attribute-map.xml` and add this:
183+
```xml
184+
<Attribute name="tag:fmfi-svt.github.io,2024:andrvotr-authority-token" id="ANDRVOTR_AUTHORITY_TOKEN" />
185+
```
186+
- If the IdP does not send you the attribute, the process cannot continue.
187+
This is most likely because the IdP is not configured correctly (andrvotr.allowedConnections, andrvotr.apiKeys).
188+
189+
2. Initialize an empty cookie jar. It will be used for all HTTP requests you send.
190+
191+
3. Send an HTTP request to the back service URL which initiates the login process.
192+
Disable automatic HTTP redirect processing in your client library.
193+
(If the URL is not known, use e.g. browser dev tools to see what happens when you click the login button.)
194+
195+
4. Process the response to decide what request should be sent next:
196+
- If it is a HTTP 3xx redirect, the *next request* will be a GET of that Location header.
197+
- If it is a pseudo-redirect (an invisible form which is immediately submitted by JavaScript), parse the HTML page.
198+
The *next request* will be a POST to that form's action with the form's hidden inputs.
199+
Detecting this case might need some finetuning, but searching for the string "`document.forms[0].submit()`" works well in practice.
200+
- If it is a success page (back service specific), return success.
201+
- Otherwise, return failure.
202+
203+
5. If the *next request* is `GET https://$your_idp/...`, instead set *next request* to `POST https://$your_idp/idp/profile/andrvotr/fabricate` with POST body parameters:
204+
- `front_entity_id` = the SAML SP entity ID of the front service
205+
- `api_key` = your Andrvotr API key (must match andrvotr.apiKeys)
206+
- `andrvotr_authority_token` = token from the SAML attribute
207+
- `target_url` = the original *next request* URL
208+
209+
6. Send the *next request*.
210+
211+
7. Go to step 4 to process the response.
212+
213+
### Example implementations
214+
215+
[demo/demo.py](/demo/demo.py) implements an Andrvotr client in 50 lines of Python.
216+
It is not integrated with an SP -- you must extract the token and run demo.py manually from the command line.
217+
218+
```shell
219+
./demo.py "$back_service_target_url" "$front_entity_id" "$api_key" "$andrvotr_authority_token"
220+
```
221+
222+
The demo requires some Python libraries. Either [install "uv"](https://docs.astral.sh/uv/getting-started/installation/) which will take care of it. Or `apt install python3-bs4 python3-requests` and run with `python3 demo.py ...`. Or create a venv with `beautifulsoup4` and `requests`.
223+
224+
[Votr](https://github.com/fmfi-svt/votr/blob/master/fladgejt/login.py) contains another implementation of this procedure (also in Python).
165225

166226
<!-- TODO: ## Similar projects -->

0 commit comments

Comments
 (0)