Skip to content

Commit

Permalink
Add example for retrieving userinfo in a Flask app
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljcollinsuk committed Nov 27, 2024
1 parent 209db26 commit badf064
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions source/documentation/apps/rshiny-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ profile <- fromJSON(content(GET("http://localhost:3001/userinfo", add_headers(.h
[This line](https://github.com/moj-analytical-services/shiny-headers-demo/blob/c274d864e5ee020d3a41497b347b299c07305271/app.R#L61)
shows the code in context.

You can also access the userinfo in a similar manner from a python based application. You will need to access the raw cookie string and pass it as a header in the request to the `userinfo` endpoint.

For example in a Flask application, where you have access to a `request` object, you can retreive the raw cookie string from the header as below:
```python
cookie = request.headers.get("Cookie")
```

You can then use the [`requests` library](https://requests.readthedocs.io/en/latest/) to call the `userinfo` endpoint, passing the cookie as a `"App-Cookie"` header as below:
```python
requests.get(
"http://localhost:3001/userinfo",
headers={"App-Cookie": cookie},
)
```

##### Example response

```json
Expand Down

0 comments on commit badf064

Please sign in to comment.