示例#1
0
        def decorated(*args, **kwargs):
            raw_access_token = oidc.get_access_token()
            pre, tkn, post = raw_access_token.split('.')
            access_token = b64decode(tkn + '=' * (-len(tkn) % 4))
            access_token = json.loads(access_token.decode('utf-8'))

            user_id = oidc.user_getfield('sub')
            access_token_id = access_token['sub']

            if oidc.validate_token(raw_access_token) and (user_id == access_token_id):
                for role in roles:
                    if role in access_token['realm_access']['roles']:
                        return view_func(*args, **kwargs)
                else:
                    flash('Unauthorized!', 'danger')
                    return redirect(url_for('dash.dashboard')) 
            else:
                flash('Invalid Token!', 'danger')
                return redirect(url_for('dash.dashboard'))
示例#2
0
def dashboard():
    if oidc.user_loggedin:
        info = oidc.user_getinfo(['sub'])
        user_id = info.get('sub')

        if user_id in oidc.credentials_store:

            flash('Welcome %s' % oidc.user_getfield('preferred_username'),
                  'success')
            return render_template('main.html')

        else:
            session.clear()
            oidc.logout()
            return redirect(
                'http://localhost:8080/auth/realms/Application1/protocol/openid-connect/logout?redirect_uri=http://localhost:5000/'
            )

    return redirect(url_for('start.Startscreen'))
示例#3
0
def Startscreen():
    if oidc.user_loggedin:
        flash('Welcome %s' % oidc.user_getfield('username'))
        return redirect(url_for('dash.dashboard'))
    else:
        return render_template('startscreen.html')
示例#4
0
def Startscreen():
    if oidc.user_loggedin:
        flash('Welcome %s' % oidc.user_getfield('username'))
        return redirect(url_for('dash.dashboard'))
    else:
        return 'Welcome anonymous, <a href="/my">Log in</a>'