Skip to content

Commit

Permalink
Add example for retrieving userinfo in a Flask app (#470)
Browse files Browse the repository at this point in the history
* Add example for retrieving userinfo in a Flask app

* Better formatting

Co-authored-by: Jacob Woffenden <[email protected]>

* More formatting

Co-authored-by: Jacob Woffenden <[email protected]>

* Update source/documentation/apps/rshiny-app.md

Co-authored-by: Jacob Woffenden <[email protected]>

* Fix typo

* Fix codeblock

* Fix codeblock

---------

Co-authored-by: Jacob Woffenden <[email protected]>
  • Loading branch information
michaeljcollinsuk and jacobwoffenden authored Nov 27, 2024
1 parent 209db26 commit 1541248
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions source/documentation/apps/rshiny-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,23 @@ 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 `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 retrieve 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 1541248

Please sign in to comment.