繁体   English   中英

身份验证后如何从Flask返回令牌到Watson Assistant?

[英]How to return tokens from Flask after authentication to Watson Assistant?

我使用Flask-Security开发了使用Flask的用户管理系统。 我想在页面上添加一个Watson聊天机器人,它应该检查用户是否已通过身份验证。 这将在Flask-Security内部的登录模块中完成,如下所示:

@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)

当用户开始从聊天界面提问时(例如,从系统中的注册日期开始提问),我们可以将其重定向到Flask的登录页面,并且在身份验证之后,我们返回到对话对话框并提取相关数据给已认证的用户(例如,用户配置文件的记录时间戳)?

在应用程序上下文中查看Watson Assistant体系结构图 Watson Assistant是或可以只是解决方案的多项服务之一。 通常,您的应用程序会通过反复向Watson Assistant发送消息并获取响应来引发对话和对话。

您的Flask应用可处理整个流程,身份验证以及如何将聊天数据(可能是聊天窗口)嵌入到UI中。 请参阅IBM Cloud App ID以获取不同的认证流程。 IBM Cloud教程基于Flask,并使用App ID实现OIDC。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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