简体   繁体   中英

How to return tokens from Flask after authentication to Watson Assistant?

I have developed a user management system using Flask using Flask-Security . I would like to add a Watson chatbot to the page, and it should check if the user is authenticated or not. This will be done inside Flask-Security in its login module as follows:

@app.route('/login', methods=['GET', 'POST'])
def login():
    # Here we use a class of some kind to represent and validate our
    # client-side form data. For example, WTForms is a library that will
    # handle this for us, and we use a custom LoginForm to validate.
    form = LoginForm()
    if form.validate_on_submit():
        # Login and validate the user.
        # user should be an instance of your `User` class
        login_user(user)

        flask.flash('Logged in successfully.')

        next = flask.request.args.get('next')
        # is_safe_url should check if the url is safe for redirects.
        # See http://flask.pocoo.org/snippets/62/ for an example.
        if not is_safe_url(next):
            return flask.abort(400)

        return flask.redirect(next or flask.url_for('index'))
    return flask.render_template('login.html', form=form)

Is it possible when a user starts asking questions from the chat interface (eg asking from the date of registration in the system) we redirect him/her to the login page of Flask and after authentication, we get back to conversation dialog and pull data related to the authenticated user (eg the record timestamp of user profile)?

See the architecture diagram for Watson Assistant in the app context . Watson Assistant is or can be just one of several services for a solution. Typically, your app would drive a dialog, a conversation, by repeatedly sending a message to Watson Assistant and obtaining the response.

Your Flask app handles the overall flow, the authentication, and how the chat data (maybe as a chat window) is embedded into the UI. See IBM Cloud App ID for different authentication flows. This IBM Cloud tutorial is based on Flask and implements OIDC with App ID.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM