GithubHelp home page GithubHelp logo

jpfcabral / dash-auth-external Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jamesholcombe/dash-auth-external

0.0 0.0 0.0 80 KB

Plotly Dash plugin to allow authentication through 3rd party OAuth providers.

Home Page: https://pypi.org/project/dash-auth-external/

License: MIT License

Python 100.00%

dash-auth-external's Introduction

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

pip install dash-auth-external

Simple Usage

#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.

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.

...

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
    return token

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.

dash-auth-external's People

Contributors

jamesholcombe avatar alonbl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.