more research on Auth stuff, examples of getting Auth token from Mastodon

This commit is contained in:
Dave Lane 2023-12-18 22:59:38 +13:00
parent f4340a5b8c
commit 6f0267713d
4 changed files with 266 additions and 2 deletions

80
AuthNotes.md Normal file
View file

@ -0,0 +1,80 @@
References related to Authentication
With Svelte + SQLite:
https://medium.com/@mateuszpiorowski/oauth2-is-so-complicated-or-90-lines-of-code-with-svelte-ab0f5d80d659
With Auth.js + Node.js + Mastodon!:
https://medium.com/@jibla/auth-js-exploration-1b6c27cf076f
code: https://github.com/jibla/authjs-node-example
## Example Auth Flow for Mastodon:
ref: https://docs.joinmastodon.org/client/token/#app
### Step 1 - Get Client info
sent:
`curl -X POST -F 'client_name=Mastodon Map' -F 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' -F 'scopes=read write push' -F 'website=https://mastomap.magnificent.nz' https://mastodon.nzoss.nz/api/v1/apps`
response (json):
```
{
"id":"6929",
"name":"Mastodon Map",
"website":"https://mastomap.magnificent.nz",
"redirect_uri":"urn:ietf:wg:oauth:2.0:oob",
"client_id":"RzTkGQY5MXuvRpMjhG6QuW3NADRjTn14e_JqywgX0IA",
"client_secret":"Sm6hUzIyvnAjYh6j1vXITJqObqCCwK-es33PAoRuhmI",
"vapid_key":"BDyHmBqMmcoCZQPQoSBAlRG06AuOMsJ64hQyTLUxoB8gP-uaACHJyAGRBj0JjtMtbl7WuQxRNuHh2fFQqSfmQMs="
}
```
### Step 2 - Get Auth Token
sent:
```
curl -X POST \
-F 'client_id=RzTkGQY5MXuvRpMjhG6QuW3NADRjTn14e_JqywgX0IA' \
-F 'client_secret=Sm6hUzIyvnAjYh6j1vXITJqObqCCwK-es33PAoRuhmI' \
-F 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' \
-F 'grant_type=client_credentials' \
https://mastodon.nzoss.nz/oauth/token
```
response (json):
```
{
"access_token":"l3rutZOWZ_LTkku-kjdeZ6F2tv7mucBid5AIgpLEjbg",
"token_type":"Bearer",
"scope":"read",
"created_at":1702891488
}
```
### Step 3 - Verify Auth Token
sent:
```
curl \
-H 'Authorization: Bearer l3rutZOWZ_LTkku-kjdeZ6F2tv7mucBid5AIgpLEjbg' \
https://mastodon.nzoss.nz/api/v1/apps/verify_credentials
```
response (json):
```
{
"name":"Mastodon Map",
"website":"https://mastomap.magnificent.nz",
"vapid_key":"BDyHmBqMmcoCZQPQoSBAlRG06AuOMsJ64hQyTLUxoB8gP-uaACHJyAGRBj0JjtMtbl7WuQxRNuHh2fFQqSfmQMs="
}
```
### Step 4 - actual request (for user 1, i.e. lightweight):
sent:
```
curl \
-H 'Authorization: Bearer l3rutZOWZ_LTkku-kjdeZ6F2tv7mucBid5AIgpLEjbg' \
https://mastodon.nzoss.nz/api/v1/accounts/1/followers?limit=6 | jq > MastoFollowers.json
```
and see MastoFollowers.json for the first 6 results (see limit=6 above).

184
MastoFollowers.json Normal file
View file

@ -0,0 +1,184 @@
[
{
"id": "111595856736442672",
"username": "Catt",
"acct": "Catt@universeodon.com",
"display_name": "Kat",
"locked": false,
"bot": false,
"discoverable": true,
"group": false,
"created_at": "2023-12-07T00:00:00.000Z",
"note": "<p>I love communism and anarchism, and hate capitalism and the state.</p>",
"url": "https://universeodon.com/@Catt",
"uri": "https://universeodon.com/users/Catt",
"avatar": "https://mastodon.nzoss.nz/system/cache/accounts/avatars/111/595/856/736/442/672/original/e13193aa3ff24f74.jpg",
"avatar_static": "https://mastodon.nzoss.nz/system/cache/accounts/avatars/111/595/856/736/442/672/original/e13193aa3ff24f74.jpg",
"header": "https://mastodon.nzoss.nz/system/cache/accounts/headers/111/595/856/736/442/672/original/5748b78234377f3f.png",
"header_static": "https://mastodon.nzoss.nz/system/cache/accounts/headers/111/595/856/736/442/672/original/5748b78234377f3f.png",
"followers_count": 525,
"following_count": 3191,
"statuses_count": 42,
"last_status_at": null,
"emojis": [],
"fields": []
},
{
"id": "111594947763130191",
"username": "ArtemisMkV",
"acct": "ArtemisMkV@defcon.social",
"display_name": "ArtemisMkV",
"locked": false,
"bot": false,
"discoverable": false,
"group": false,
"created_at": "2023-11-11T00:00:00.000Z",
"note": "",
"url": "https://defcon.social/@ArtemisMkV",
"uri": "https://defcon.social/users/ArtemisMkV",
"avatar": "https://mastodon.nzoss.nz/avatars/original/missing.png",
"avatar_static": "https://mastodon.nzoss.nz/avatars/original/missing.png",
"header": "https://mastodon.nzoss.nz/headers/original/missing.png",
"header_static": "https://mastodon.nzoss.nz/headers/original/missing.png",
"followers_count": 2,
"following_count": 219,
"statuses_count": 0,
"last_status_at": null,
"emojis": [],
"fields": []
},
{
"id": "111585911731826986",
"username": "randulo",
"acct": "randulo@mozilla.social",
"display_name": "Bluesbreaker Randy",
"locked": false,
"bot": false,
"discoverable": false,
"group": false,
"created_at": "2023-12-15T00:00:00.000Z",
"note": "<p>Longtime in music, first vinyl in 1972, but also a lot of tech, communications and many other lives.<br>I've been living in France for 42 years.</p>",
"url": "https://mozilla.social/@randulo",
"uri": "https://mozilla.social/users/randulo",
"avatar": "https://mastodon.nzoss.nz/system/cache/accounts/avatars/111/585/911/731/826/986/original/87fa8c405af5a5ff.png",
"avatar_static": "https://mastodon.nzoss.nz/system/cache/accounts/avatars/111/585/911/731/826/986/original/87fa8c405af5a5ff.png",
"header": "https://mastodon.nzoss.nz/system/cache/accounts/headers/111/585/911/731/826/986/original/1ce51e1cc21cf93d.jpg",
"header_static": "https://mastodon.nzoss.nz/system/cache/accounts/headers/111/585/911/731/826/986/original/1ce51e1cc21cf93d.jpg",
"followers_count": 292,
"following_count": 2797,
"statuses_count": 42,
"last_status_at": "2023-12-17",
"emojis": [],
"fields": [
{
"name": "Wikipedia",
"value": "<a href=\"https://en.wikipedia.org/wiki/Randy_Resnick\" rel=\"nofollow noopener noreferrer\" translate=\"no\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">en.wikipedia.org/wiki/Randy_Re</span><span class=\"invisible\">snick</span></a>",
"verified_at": null
},
{
"name": "Music",
"value": "<a href=\"https://randulo.com\" rel=\"nofollow noopener noreferrer\" translate=\"no\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">randulo.com</span><span class=\"invisible\"></span></a>",
"verified_at": null
},
{
"name": "Writing",
"value": "<a href=\"https://StrictlyBeta.com\" rel=\"nofollow noopener noreferrer\" translate=\"no\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">StrictlyBeta.com</span><span class=\"invisible\"></span></a>",
"verified_at": null
},
{
"name": "Streaming platforms",
"value": "<a href=\"https://ffm.bio/randulo\" rel=\"nofollow noopener noreferrer\" translate=\"no\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">ffm.bio/randulo</span><span class=\"invisible\"></span></a>",
"verified_at": null
}
]
},
{
"id": "110669092986119925",
"username": "hall",
"acct": "hall@mastodonapp.uk",
"display_name": "David Hall",
"locked": false,
"bot": false,
"discoverable": false,
"group": false,
"created_at": "2022-11-21T00:00:00.000Z",
"note": "<p>FRGS</p>",
"url": "https://mastodonapp.uk/@hall",
"uri": "https://mastodonapp.uk/users/hall",
"avatar": "https://mastodon.nzoss.nz/system/cache/accounts/avatars/110/669/092/986/119/925/original/9b232f8dbabb1869.png",
"avatar_static": "https://mastodon.nzoss.nz/system/cache/accounts/avatars/110/669/092/986/119/925/original/9b232f8dbabb1869.png",
"header": "https://mastodon.nzoss.nz/system/cache/accounts/headers/110/669/092/986/119/925/original/db36bc922661d241.jpg",
"header_static": "https://mastodon.nzoss.nz/system/cache/accounts/headers/110/669/092/986/119/925/original/db36bc922661d241.jpg",
"followers_count": 3,
"following_count": 23,
"statuses_count": 19,
"last_status_at": "2023-12-14",
"emojis": [],
"fields": [
{
"name": "Geo",
"value": "Teesdale",
"verified_at": null
}
]
},
{
"id": "109392198659255923",
"username": "SrRochardBunson",
"acct": "SrRochardBunson@universeodon.com",
"display_name": "Sir Rochard 'Dock' Bunson",
"locked": true,
"bot": false,
"discoverable": true,
"group": false,
"created_at": "2022-11-20T00:00:00.000Z",
"note": "<p><a href=\"https://universeodon.com/tags/Antifascist\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>Antifascist</span></a> <a href=\"https://universeodon.com/tags/Generalist\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>Generalist</span></a></p><p>Be excellent to each other.</p><p>Except for <a href=\"https://universeodon.com/tags/Fascists\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>Fascists</span></a>. They can get fucked.</p><p>If you aren't a <a href=\"https://universeodon.com/tags/Nazi\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>Nazi</span></a> but I annoy you, you can mute my <a href=\"https://universeodon.com/tags/Boosts\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>Boosts</span></a></p><p>\"Help grow your <a href=\"https://universeodon.com/tags/local\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>local</span></a> <a href=\"https://universeodon.com/tags/bee\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>bee</span></a> &amp; <a href=\"https://universeodon.com/tags/Butterflies\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>Butterflies</span></a> polulation\"</p><p>Make Punching Nazis Cool Again<br><a href=\"https://universeodon.com/tags/MPNCA\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>MPNCA</span></a></p><p><a href=\"https://universeodon.com/tags/ArtFED\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>ArtFED</span></a> <a href=\"https://universeodon.com/tags/TVAC\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>TVAC</span></a></p><p>\"The Resistance Will Be Federated\"</p><p>🙏 Take my Stuff (Original posts CC-BY-SA 4.0)</p><p><a href=\"https://universeodon.com/tags/TheResistanceWillBeFederated\" class=\"mention hashtag\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">#<span>TheResistanceWillBeFederated</span></a><br>🐝<br>Also at <span class=\"h-card\" translate=\"no\"><a href=\"https://firefish.social/@SrRochardBunson\" class=\"u-url mention\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">@<span>SrRochardBunson</span></a></span> &amp; with Resistance International</p><p>No TERFs or astroturf</p>",
"url": "https://universeodon.com/@SrRochardBunson",
"uri": "https://universeodon.com/users/SrRochardBunson",
"avatar": "https://mastodon.nzoss.nz/system/cache/accounts/avatars/109/392/198/659/255/923/original/9719bf36bbbd0248.jpg",
"avatar_static": "https://mastodon.nzoss.nz/system/cache/accounts/avatars/109/392/198/659/255/923/original/9719bf36bbbd0248.jpg",
"header": "https://mastodon.nzoss.nz/system/cache/accounts/headers/109/392/198/659/255/923/original/2c26be9f48246cf1.jpg",
"header_static": "https://mastodon.nzoss.nz/system/cache/accounts/headers/109/392/198/659/255/923/original/2c26be9f48246cf1.jpg",
"followers_count": 3811,
"following_count": 7191,
"statuses_count": 7935,
"last_status_at": "2023-12-18",
"emojis": [],
"fields": [
{
"name": "ArtFED Audio Collage",
"value": "<a href=\"https://on.soundcloud.com/h8N1q\" rel=\"nofollow noopener noreferrer\" translate=\"no\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">on.soundcloud.com/h8N1q</span><span class=\"invisible\"></span></a>",
"verified_at": null
},
{
"name": "Resistance International",
"value": "<a href=\"https://ko-fi.com/resistanceinternational/shop\" rel=\"nofollow noopener noreferrer\" translate=\"no\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"ellipsis\">ko-fi.com/resistanceinternatio</span><span class=\"invisible\">nal/shop</span></a>",
"verified_at": null
}
]
},
{
"id": "110891195218520061",
"username": "hamsbsijsvbsj",
"acct": "hamsbsijsvbsj@toot.io",
"display_name": "FAZ3🔵",
"locked": false,
"bot": false,
"discoverable": false,
"group": false,
"created_at": "2023-08-15T00:00:00.000Z",
"note": "<p>“If people are doubting how far you can go, go so far that you cant hear them anymore🌹🌹🌹</p>",
"url": "https://toot.io/@hamsbsijsvbsj",
"uri": "https://toot.io/users/hamsbsijsvbsj",
"avatar": "https://mastodon.nzoss.nz/system/cache/accounts/avatars/110/891/195/218/520/061/original/19d9534fbf232860.jpg",
"avatar_static": "https://mastodon.nzoss.nz/system/cache/accounts/avatars/110/891/195/218/520/061/original/19d9534fbf232860.jpg",
"header": "https://mastodon.nzoss.nz/system/cache/accounts/headers/110/891/195/218/520/061/original/b79545bd525136c6.jpg",
"header_static": "https://mastodon.nzoss.nz/system/cache/accounts/headers/110/891/195/218/520/061/original/b79545bd525136c6.jpg",
"followers_count": 49,
"following_count": 381,
"statuses_count": 390,
"last_status_at": "2023-12-07",
"emojis": [],
"fields": []
}
]

View file

@ -11,5 +11,5 @@ services:
ports: ports:
- "127.0.0.1:8085:8080" - "127.0.0.1:8085:8080"
environment: environment:
- API_URL=http://localhost:3000/ - API_URL=http://localhost:3500/
restart: unless-stopped restart: unless-stopped

View file

@ -44,7 +44,7 @@ services:
container_name: postgrest container_name: postgrest
image: postgrest/postgrest:latest image: postgrest/postgrest:latest
ports: ports:
- "127.0.0.1:3000:3000" - "127.0.0.1:3500:3000"
# Available environment variables documented here: # Available environment variables documented here:
# https://postgrest.org/en/latest/configuration.html#environment-variables # https://postgrest.org/en/latest/configuration.html#environment-variables
environment: environment: