Skip to content

Conversation

T4rk1n
Copy link
Contributor

@T4rk1n T4rk1n commented Jul 24, 2018

Add a logout and create_logout_button methods to PlotlyAuth.

  • logout
    • Must be called from a callback, takes no arguments.
    • Invalidate the plotly_oauth_token.
    • Clear the auth cookies.
  • create_logout_button
    • Returns a logout button component to use in a dash layout.
    • Call logout once clicked then redirect.
    • Options:
      • label: The text (or children component) on the button (default='Logout').
      • redirect_to: Redirect the browser to this link when the button is clicked (default='https://plot.ly).
    • Also takes props keywords from html.Button like style, className, etc.

Example:

import dash
import dash_auth

import dash_html_components as html

app = dash.Dash(__name__)

auth = dash_auth.PlotlyAuth(
    app, 'logout', 'public',
    'http://localhost:8050/')

btn_style = {
    'backgroundColor': 'red',
    'padding': '16px',
    'borderRadius': '8px',
    'border': 'none'
}

app.layout = html.Div([
    html.Div('content', id='content'),
    auth.create_logout_button(
        style=btn_style,
        label='Sign out',
        redirect_to='https://www.google.com')
])

if __name__ == '__main__':
    app.run_server()

@T4rk1n T4rk1n requested review from chriddyp and scjody July 24, 2018 19:20
Copy link

@scjody scjody left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for adding a 🐀 test!

Other than the default redirect, there are a couple of minor issues with the commits themselves that I'd like you to fix before merging:

  • The email address you used <philippe@plot.ly> doesn't match an email address that GitHub knows about. Either add this email address to the T4rk1n account on GitHub, or rebase your commits to change the author to an email address that is associated with that account.
  • 66b87d3 is a fix to a previous commit, so please rebase to get rid of it.


def create_logout_button(self,
id='logout-btn',
redirect_to='https://plot.ly',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should redirect to the root of the app by default.

@T4rk1n
Copy link
Contributor Author

T4rk1n commented Jul 25, 2018

@scjody I was wondering why the commits didn't show my profile picture, added the email thanks.

@T4rk1n T4rk1n merged commit 55f8840 into master Aug 6, 2018
@T4rk1n T4rk1n deleted the logout-btn branch August 6, 2018 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants