oidc-provider-mock


Nameoidc-provider-mock JSON
Version 0.0.2a1 PyPI version JSON
download
home_pageNone
SummaryOpenID Connect provider server for testing authentication
upload_time2025-01-22 14:32:13
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords oauth oidc openid connect authentication development mock testing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # OpenID Provider Mock

[![PyPI version](https://img.shields.io/pypi/v/oidc-provider-mock)](https://pypi.org/project/oidc-provider-mock/)
[![main](https://github.com/geigerzaehler/oidc-provider-mock/actions/workflows/main.yaml/badge.svg)](https://github.com/geigerzaehler/oidc-provider-mock/actions/workflows/main.yaml)
[![documentation](https://readthedocs.org/projects/oidc-provider-mock/badge/?version=latest)][docs]

> A mock OpenID Provider server to test and develop OpenID Connect
> authentication.

You can find the full documentation [here][docs].

[docs]: https://oidc-provider-mock.readthedocs.io/latest/

## Usage

Run the OpenID Provider server

```bash
$ pipx run oidc-provider-mock
Started OpenID provider http://localhost:9400
```

Configure the OpenID Connect client library in your app to use
`http://localhost:9400` as the issuer URL. You can use any client ID and client
secret with the provider.

Now you can authenticate and authorize the app in the login form.

Take a look at the following example for using the server in a test.

```python
@pytest.fixture
def oidc_server():
    logging.getLogger("oidc_provider_mock.server").setLevel(logging.DEBUG)
    with oidc_provider_mock.run_server_in_thread() as server:
        yield f"http://localhost:{server.server_port}"


def test_login(client, oidc_server):
    # Let the OIDC provider know about the user’s email and name
    httpx.put(
        f"{oidc_server}/users/{quote('alice@example.com')}",
        json={"userinfo": {"email": "alice@example.com", "name": "Alice"}},
    )

    # Start login on the client and get the authorization URL
    response = client.get("/login")
    assert response.location

    # Authorize the client by POSTing to the authorization URL.
    response = httpx.post(response.location, data={"sub": "alice@example.com"})

    # Go back to the client with the authorization code
    assert response.has_redirect_location
    response = client.get(response.headers["location"], follow_redirects=True)

    # Check that we have been authenticated
    assert response.text == "Welcome Alice <alice@example.com>"
```

For all full testing example, see
[`examples/flask_oidc_example.py`](examples/flask_oidc_example.py)

If you’re using [Playwright](https://playwright.dev) for end-to-end tests, a
login test looks like this:

```python
def test_auth_code_login_playwright(live_server, page, oidc_server):
    # Let the OIDC provider know about the user’s email and name
    httpx.put(
        f"{oidc_server}/users/{quote('alice@example.com')}",
        json={"userinfo": {"email": "alice@example.com", "name": "Alice"}},
    )

    # Start login and be redirected to the provider
    page.goto(live_server.url("/login"))

    # Authorize with the provider
    page.get_by_placeholder("sub").fill("alice@example.com")
    page.get_by_role("button", name="Authorize").click()

    # Verify that we’re logged in
    expect(page.locator("body")).to_contain_text("Welcome Alice (alice@example.com)")
```

You can find a full example at
[`examples/flask_oidc_example.py`](examples/flask_oidc_example.py), too

## Alternatives

There already exist a couple of OpendID provider servers for testing. This is
how they differ from this project (to the best of my knowledge):

[`axa-group/oauth2-mock-server`](https://github.com/axa-group/oauth2-mock-server)

- Does not offer a HTML login form where the subject can be input or
  authorization denied.
- Behavior can only be customized through the JavaScript API.

[`Soluto/oidc-server-mock`](https://github.com/Soluto/oidc-server-mock)

- Identities (users) and clients must be statically configured.
- Requires a non-trivial amount of configuration before it can be used.

[`oauth2-proxy/mockoidc`](https://github.com/oauth2-proxy/mockoidc`)

- Does not have a CLI, only available as a Go library

<https://oauth.wiremockapi.cloud/>

- Only a hosted version exists
- Claims and user info cannot be customized
- Cannot simulate errors

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "oidc-provider-mock",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "OAuth, OIDC, OpenID Connect, authentication, development, mock, testing",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/a7/17/c0d6e366767cb7bc24f2701f9cce8cf1f9375fadc9347a2a11a0962a5a43/oidc_provider_mock-0.0.2a1.tar.gz",
    "platform": null,
    "description": "# OpenID Provider Mock\n\n[![PyPI version](https://img.shields.io/pypi/v/oidc-provider-mock)](https://pypi.org/project/oidc-provider-mock/)\n[![main](https://github.com/geigerzaehler/oidc-provider-mock/actions/workflows/main.yaml/badge.svg)](https://github.com/geigerzaehler/oidc-provider-mock/actions/workflows/main.yaml)\n[![documentation](https://readthedocs.org/projects/oidc-provider-mock/badge/?version=latest)][docs]\n\n> A mock OpenID Provider server to test and develop OpenID Connect\n> authentication.\n\nYou can find the full documentation [here][docs].\n\n[docs]: https://oidc-provider-mock.readthedocs.io/latest/\n\n## Usage\n\nRun the OpenID Provider server\n\n```bash\n$ pipx run oidc-provider-mock\nStarted OpenID provider http://localhost:9400\n```\n\nConfigure the OpenID Connect client library in your app to use\n`http://localhost:9400` as the issuer URL. You can use any client ID and client\nsecret with the provider.\n\nNow you can authenticate and authorize the app in the login form.\n\nTake a look at the following example for using the server in a test.\n\n```python\n@pytest.fixture\ndef oidc_server():\n    logging.getLogger(\"oidc_provider_mock.server\").setLevel(logging.DEBUG)\n    with oidc_provider_mock.run_server_in_thread() as server:\n        yield f\"http://localhost:{server.server_port}\"\n\n\ndef test_login(client, oidc_server):\n    # Let the OIDC provider know about the user\u2019s email and name\n    httpx.put(\n        f\"{oidc_server}/users/{quote('alice@example.com')}\",\n        json={\"userinfo\": {\"email\": \"alice@example.com\", \"name\": \"Alice\"}},\n    )\n\n    # Start login on the client and get the authorization URL\n    response = client.get(\"/login\")\n    assert response.location\n\n    # Authorize the client by POSTing to the authorization URL.\n    response = httpx.post(response.location, data={\"sub\": \"alice@example.com\"})\n\n    # Go back to the client with the authorization code\n    assert response.has_redirect_location\n    response = client.get(response.headers[\"location\"], follow_redirects=True)\n\n    # Check that we have been authenticated\n    assert response.text == \"Welcome Alice <alice@example.com>\"\n```\n\nFor all full testing example, see\n[`examples/flask_oidc_example.py`](examples/flask_oidc_example.py)\n\nIf you\u2019re using [Playwright](https://playwright.dev) for end-to-end tests, a\nlogin test looks like this:\n\n```python\ndef test_auth_code_login_playwright(live_server, page, oidc_server):\n    # Let the OIDC provider know about the user\u2019s email and name\n    httpx.put(\n        f\"{oidc_server}/users/{quote('alice@example.com')}\",\n        json={\"userinfo\": {\"email\": \"alice@example.com\", \"name\": \"Alice\"}},\n    )\n\n    # Start login and be redirected to the provider\n    page.goto(live_server.url(\"/login\"))\n\n    # Authorize with the provider\n    page.get_by_placeholder(\"sub\").fill(\"alice@example.com\")\n    page.get_by_role(\"button\", name=\"Authorize\").click()\n\n    # Verify that we\u2019re logged in\n    expect(page.locator(\"body\")).to_contain_text(\"Welcome Alice (alice@example.com)\")\n```\n\nYou can find a full example at\n[`examples/flask_oidc_example.py`](examples/flask_oidc_example.py), too\n\n## Alternatives\n\nThere already exist a couple of OpendID provider servers for testing. This is\nhow they differ from this project (to the best of my knowledge):\n\n[`axa-group/oauth2-mock-server`](https://github.com/axa-group/oauth2-mock-server)\n\n- Does not offer a HTML login form where the subject can be input or\n  authorization denied.\n- Behavior can only be customized through the JavaScript API.\n\n[`Soluto/oidc-server-mock`](https://github.com/Soluto/oidc-server-mock)\n\n- Identities (users) and clients must be statically configured.\n- Requires a non-trivial amount of configuration before it can be used.\n\n[`oauth2-proxy/mockoidc`](https://github.com/oauth2-proxy/mockoidc`)\n\n- Does not have a CLI, only available as a Go library\n\n<https://oauth.wiremockapi.cloud/>\n\n- Only a hosted version exists\n- Claims and user info cannot be customized\n- Cannot simulate errors\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "OpenID Connect provider server for testing authentication",
    "version": "0.0.2a1",
    "project_urls": {
        "Documentation": "https://github.com/geigerzaehler/oidc-provider-mock",
        "Homepage": "https://github.com/geigerzaehler/oidc-provider-mock",
        "Issues": "https://github.com/geigerzaehler/oidc-provider-mock/issues",
        "Source": "https://github.com/geigerzaehler/oidc-provider-mock"
    },
    "split_keywords": [
        "oauth",
        " oidc",
        " openid connect",
        " authentication",
        " development",
        " mock",
        " testing"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6da1c419de7d1589fe4939d8c4256b10aa9cb88f7fa6cc82fe8d0476d02ed1b2",
                "md5": "2e79f70028d626ec8c218356f26e537f",
                "sha256": "f202cc0100e1ced2dac9d54aa3fa1f4e55617faf07daf55e51cc55f3126195c1"
            },
            "downloads": -1,
            "filename": "oidc_provider_mock-0.0.2a1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2e79f70028d626ec8c218356f26e537f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 12420,
            "upload_time": "2025-01-22T14:32:11",
            "upload_time_iso_8601": "2025-01-22T14:32:11.505006Z",
            "url": "https://files.pythonhosted.org/packages/6d/a1/c419de7d1589fe4939d8c4256b10aa9cb88f7fa6cc82fe8d0476d02ed1b2/oidc_provider_mock-0.0.2a1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a717c0d6e366767cb7bc24f2701f9cce8cf1f9375fadc9347a2a11a0962a5a43",
                "md5": "c4a3bd096728537b099a28c41fc772a7",
                "sha256": "2e80c0fcbe703e25c75e7e9470a8790679a76b24969daf3e84bcb2a565f6f05e"
            },
            "downloads": -1,
            "filename": "oidc_provider_mock-0.0.2a1.tar.gz",
            "has_sig": false,
            "md5_digest": "c4a3bd096728537b099a28c41fc772a7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 149837,
            "upload_time": "2025-01-22T14:32:13",
            "upload_time_iso_8601": "2025-01-22T14:32:13.963773Z",
            "url": "https://files.pythonhosted.org/packages/a7/17/c0d6e366767cb7bc24f2701f9cce8cf1f9375fadc9347a2a11a0962a5a43/oidc_provider_mock-0.0.2a1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-22 14:32:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "geigerzaehler",
    "github_project": "oidc-provider-mock",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "oidc-provider-mock"
}
        
Elapsed time: 1.36266s