dash-auth-external


Namedash-auth-external JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/jamesholcombe/dash-auth-external
SummaryIntegrate your dashboards with 3rd party APIs and external OAuth providers.
upload_time2023-07-15 18:32:00
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords dash plotly authentication auth external
VCS
bugtrack_url
requirements No requirements were recorded.
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": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "Dash,Plotly,Authentication,Auth,External",
    "author": "",
    "author_email": "jholcombe@hotmail.co.uk",
    "download_url": "https://files.pythonhosted.org/packages/28/fb/2cfd4c53886c7d8ff89d2b18ace1a0e91f51185f6e6c2955163df4d0fd5a/dash-auth-external-1.2.0.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": "",
    "summary": "Integrate your dashboards with 3rd party APIs and external OAuth providers.",
    "version": "1.2.0",
    "project_urls": {
        "Homepage": "https://github.com/jamesholcombe/dash-auth-external"
    },
    "split_keywords": [
        "dash",
        "plotly",
        "authentication",
        "auth",
        "external"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa805458925707b272f65af23f4c714a921e0036a82b0c0e8605a135cd2698aa",
                "md5": "d222bc9ed448f722a4392bcba4269870",
                "sha256": "659866f415b8a035c7fe969dcd17168ecfa01883a68604e21594cef43f1825b4"
            },
            "downloads": -1,
            "filename": "dash_auth_external-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d222bc9ed448f722a4392bcba4269870",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 10511,
            "upload_time": "2023-07-15T18:31:58",
            "upload_time_iso_8601": "2023-07-15T18:31:58.722581Z",
            "url": "https://files.pythonhosted.org/packages/fa/80/5458925707b272f65af23f4c714a921e0036a82b0c0e8605a135cd2698aa/dash_auth_external-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "28fb2cfd4c53886c7d8ff89d2b18ace1a0e91f51185f6e6c2955163df4d0fd5a",
                "md5": "6854a130302e35753dcf71fde9fb1cd7",
                "sha256": "63daf6ae7817213971681025c3ce0ca6e9a157649c3571bc991d42fe4d2d124e"
            },
            "downloads": -1,
            "filename": "dash-auth-external-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6854a130302e35753dcf71fde9fb1cd7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 8178,
            "upload_time": "2023-07-15T18:32:00",
            "upload_time_iso_8601": "2023-07-15T18:32:00.553017Z",
            "url": "https://files.pythonhosted.org/packages/28/fb/2cfd4c53886c7d8ff89d2b18ace1a0e91f51185f6e6c2955163df4d0fd5a/dash-auth-external-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-15 18:32: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": [],
    "lcname": "dash-auth-external"
}
        
Elapsed time: 0.08817s