Skip to content

Commit

Permalink
Added Sign in with GitHub menu action, closes #65
Browse files Browse the repository at this point in the history
Refs #62
  • Loading branch information
simonw committed Jan 22, 2021
1 parent dc91e96 commit 3dfa270
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Datasette plugin that authenticates users against GitHub.

The new [0.13a0 alpha release](https://github.com/simonw/datasette-auth-github/releases/tag/0.13a0) requires [Datasette 0.44](https://datasette.readthedocs.io/en/latest/changelog.html#v0-44) or later.
The new [0.13a0 alpha release](https://github.com/simonw/datasette-auth-github/releases/tag/0.13a0) requires [Datasette 0.51](https://datasette.readthedocs.io/en/latest/changelog.html#v0-51) or later.

## Setup instructions

Expand Down
11 changes: 11 additions & 0 deletions datasette_auth_github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ def register_routes():
(r"^/-/github-auth-start$", github_auth_start),
(r"^/-/auth-callback$", github_auth_callback),
]


@hookimpl
def menu_links(datasette, actor):
if not actor:
return [
{
"href": datasette.urls.path("/-/github-auth-start"),
"label": "Sign in with GitHub",
},
]
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def get_long_description():
version=VERSION,
packages=["datasette_auth_github"],
entry_points={"datasette": ["auth_github = datasette_auth_github"]},
install_requires=["datasette>=0.51"],
extras_require={
"test": ["datasette", "pytest", "pytest-asyncio", "httpx", "sqlite-utils"]
},
Expand Down
11 changes: 11 additions & 0 deletions test_datasette_auth_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,14 @@ async def test_github_auth_callback(ds, monkeypatch):
}
} == ds.unsign(response.cookies["ds_actor"], "actor")
assert "/" == response.headers["location"]


@pytest.mark.asyncio
async def test_sign_in_with_github_button(ds):
response = await ds.client.get("/")
fragment = '<li><a href="/-/github-auth-start">Sign in with GitHub</a></li>'
assert fragment in response.text
response2 = await ds.client.get(
"/", cookies={"ds_actor": ds.sign({"a": {"display": "user"}}, "actor")}
)
assert fragment not in response2.text

0 comments on commit 3dfa270

Please sign in to comment.