Skip to content

Commit 61201a9

Browse files
authored
Add id field to actor object for consistency with Datasette actor format (#77)
* Add id field to actor object for consistency with Datasette actor format This change adds an "id" field to the actor object returned by the GitHub authentication callback. The id field follows the format "github:{user_id}" which is consistent with Datasette's actor format conventions and ensures unique identification of authenticated users. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 83add2b commit 61201a9

3 files changed

Lines changed: 4 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Visit `/-/actor` when signed in to see the shape of the authenticated actor. It
6464
```json
6565
{
6666
"actor": {
67+
"id": "github:9599",
6768
"display": "simonw",
6869
"gh_id": "9599",
6970
"gh_name": "Simon Willison",
@@ -106,7 +107,7 @@ Note that GitHub allows users to change their username, and it is possible for o
106107
```json
107108
{
108109
"allow": {
109-
"gh_id": "9599"
110+
"id": "github:9599"
110111
}
111112
}
112113
```

datasette_auth_github/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ async def github_auth_callback(datasette, request, scope, receive, send):
7676
except ValueError:
7777
return await response_error(datasette, "Could not load GitHub profile")
7878
actor = {
79+
"id": "github:{}".format(profile["id"]),
7980
"display": profile["login"],
8081
"gh_id": str(profile["id"]),
8182
"gh_name": profile["name"],

tests/test_datasette_auth_github.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ async def test_github_auth_callback(ds, mocked_github_api):
154154
)
155155
actor = ds.unsign(response.cookies["ds_actor"], "actor")["a"]
156156
assert {
157+
"id": "github:123",
157158
"display": "demouser",
158159
"gh_id": "123",
159160
"gh_name": "GitHub User",

0 commit comments

Comments
 (0)