dash-auth-external


Namedash-auth-external JSON
Version 1.2.1 PyPI version JSON
download
home_pagehttps://github.com/jamesholcombe/dash-auth-external
SummaryIntegrate your dashboards with 3rd party APIs and external OAuth providers.
upload_time2024-05-12 20:22:00
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords dash plotly authentication auth external
VCS
bugtrack_url
requirements dash requests requests-oauthlib
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dash-auth-external

Integrate your dashboards with 3rd party APIs and external OAuth providers.

## Overview

Do you want to build a Plotly Dash app which pulls user data from external APIs such as Google, Spotify, Slack etc?

**Dash-auth-external** provides a simple interface to authenticate users through OAuth2 code flow. Allowing developers to serve user tailored content.

## Installation

**Dash-auth-external** is distributed via [PyPi](https://pypi.org/project/dash-auth-external/)

```
pip install dash-auth-external
```

## Usage

```python
#using spotify as an example
AUTH_URL = "https://accounts.spotify.com/authorize"
TOKEN_URL = "https://accounts.spotify.com/api/token"
CLIENT_ID = "YOUR_CLIENT_ID"

# creating the instance of our auth class
auth = DashAuthExternal(AUTH_URL, TOKEN_URL, CLIENT_ID)
```

We then pass the flask server from this object to dash on init.

```python
app = Dash(__name__, server= auth.server)
```

That's it! You can now define your layout and callbacks as usual.

> To obtain your access token, call the get_token method of your Auth object.
> **NOTE** This can **ONLY** be done in the context of a dash callback.

```python
...

app.layout = html.Div(
[
html.Div(id="example-output"),
dcc.Input(id="example-input")
])

@app.callback(
Output("example-output", "children"),
Input("example-input", "value")
)
def example_callback(value):
    token = auth.get_token()
     ##The token can only be retrieved in the context of a dash callback

    token_data = auth.get_token_data()
    # get_token_data can be used to access other data returned by the OAuth Provider
    print(token)
    print(token_data)

    return token

```

Results in something like:

```bash
>>> fakeToken123
>>> {
    "access_token" : "fakeToken123",
    "user_id" : "lucifer",
    "some_other_key" : 666,
    "expires_at" : "judgmentDay"
}

```

## Refresh Tokens

If your OAuth provider supports refresh tokens, these are automatically checked and handled in the _get_token_ method.

> Check if your OAuth provider requires any additional scopes to support refresh tokens

## Troubleshooting

If you hit 400 responses (bad request) from either endpoint, there are a number of things that might need configuration.

Make sure you have checked the following

- **Register your redirect URI** with OAuth provider!

_The library uses a default redirect URI of http://127.0.0.1:8050/redirect_.

## Contributing

Contributions, issues, and ideas are all more than welcome.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jamesholcombe/dash-auth-external",
    "name": "dash-auth-external",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "Dash, Plotly, Authentication, Auth, External",
    "author": null,
    "author_email": "jholcombe@hotmail.co.uk",
    "download_url": "https://files.pythonhosted.org/packages/c5/a9/800f2632675dc7b3160c60df065cba693a95f2b76ca4f387fd5969fa4c5d/dash_auth_external-1.2.1.tar.gz",
    "platform": null,
    "description": "# dash-auth-external\n\nIntegrate your dashboards with 3rd party APIs and external OAuth providers.\n\n## Overview\n\nDo you want to build a Plotly Dash app which pulls user data from external APIs such as Google, Spotify, Slack etc?\n\n**Dash-auth-external** provides a simple interface to authenticate users through OAuth2 code flow. Allowing developers to serve user tailored content.\n\n## Installation\n\n**Dash-auth-external** is distributed via [PyPi](https://pypi.org/project/dash-auth-external/)\n\n```\npip install dash-auth-external\n```\n\n## Usage\n\n```python\n#using spotify as an example\nAUTH_URL = \"https://accounts.spotify.com/authorize\"\nTOKEN_URL = \"https://accounts.spotify.com/api/token\"\nCLIENT_ID = \"YOUR_CLIENT_ID\"\n\n# creating the instance of our auth class\nauth = DashAuthExternal(AUTH_URL, TOKEN_URL, CLIENT_ID)\n```\n\nWe then pass the flask server from this object to dash on init.\n\n```python\napp = Dash(__name__, server= auth.server)\n```\n\nThat's it! You can now define your layout and callbacks as usual.\n\n> To obtain your access token, call the get_token method of your Auth object.\n> **NOTE** This can **ONLY** be done in the context of a dash callback.\n\n```python\n...\n\napp.layout = html.Div(\n[\nhtml.Div(id=\"example-output\"),\ndcc.Input(id=\"example-input\")\n])\n\n@app.callback(\nOutput(\"example-output\", \"children\"),\nInput(\"example-input\", \"value\")\n)\ndef example_callback(value):\n    token = auth.get_token()\n     ##The token can only be retrieved in the context of a dash callback\n\n    token_data = auth.get_token_data()\n    # get_token_data can be used to access other data returned by the OAuth Provider\n    print(token)\n    print(token_data)\n\n    return token\n\n```\n\nResults in something like:\n\n```bash\n>>> fakeToken123\n>>> {\n    \"access_token\" : \"fakeToken123\",\n    \"user_id\" : \"lucifer\",\n    \"some_other_key\" : 666,\n    \"expires_at\" : \"judgmentDay\"\n}\n\n```\n\n## Refresh Tokens\n\nIf your OAuth provider supports refresh tokens, these are automatically checked and handled in the _get_token_ method.\n\n> Check if your OAuth provider requires any additional scopes to support refresh tokens\n\n## Troubleshooting\n\nIf you hit 400 responses (bad request) from either endpoint, there are a number of things that might need configuration.\n\nMake sure you have checked the following\n\n- **Register your redirect URI** with OAuth provider!\n\n_The library uses a default redirect URI of http://127.0.0.1:8050/redirect_.\n\n## Contributing\n\nContributions, issues, and ideas are all more than welcome.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Integrate your dashboards with 3rd party APIs and external OAuth providers.",
    "version": "1.2.1",
    "project_urls": {
        "Homepage": "https://github.com/jamesholcombe/dash-auth-external"
    },
    "split_keywords": [
        "dash",
        " plotly",
        " authentication",
        " auth",
        " external"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "02b0bc35c9ccbe95ea68b30482a09103f52d3da19cbf2c52e0d4d21e63bd197e",
                "md5": "11f38550b4c1b18e427f42753d6f50bb",
                "sha256": "4661fa1f4d9c12c2fd91f3a014dbf85f6ed7d3079c96b1c7d15fece033c346fa"
            },
            "downloads": -1,
            "filename": "dash_auth_external-1.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "11f38550b4c1b18e427f42753d6f50bb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10526,
            "upload_time": "2024-05-12T20:21:59",
            "upload_time_iso_8601": "2024-05-12T20:21:59.324339Z",
            "url": "https://files.pythonhosted.org/packages/02/b0/bc35c9ccbe95ea68b30482a09103f52d3da19cbf2c52e0d4d21e63bd197e/dash_auth_external-1.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c5a9800f2632675dc7b3160c60df065cba693a95f2b76ca4f387fd5969fa4c5d",
                "md5": "8943722dddd2d96c78d514c7b443a6a2",
                "sha256": "dd2bbf695e7e91400a96652a9b5aaf587070fff1ccd1b083d605d1fcfc6a2ea0"
            },
            "downloads": -1,
            "filename": "dash_auth_external-1.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8943722dddd2d96c78d514c7b443a6a2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 8259,
            "upload_time": "2024-05-12T20:22:00",
            "upload_time_iso_8601": "2024-05-12T20:22:00.549380Z",
            "url": "https://files.pythonhosted.org/packages/c5/a9/800f2632675dc7b3160c60df065cba693a95f2b76ca4f387fd5969fa4c5d/dash_auth_external-1.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-12 20:22:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jamesholcombe",
    "github_project": "dash-auth-external",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "dash",
            "specs": [
                [
                    ">=",
                    "2.0.0"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "1.0.0"
                ]
            ]
        },
        {
            "name": "requests-oauthlib",
            "specs": [
                [
                    ">=",
                    "0.3.0"
                ]
            ]
        }
    ],
    "lcname": "dash-auth-external"
}
        
Elapsed time: 0.37124s