Beispiel #1
0
def index():
    """
    :return: the index page with the tokens, if set.
    """
    print "Main page"
    user = None
    is_logged_in = False
    if 'session_id' in session:
        user = _session_store.get(session['session_id'])
    if user:
        is_logged_in = True
        if user.id_token:
            user.id_token_json = decode_token(user.id_token)
        if user.access_token:
            user.access_token_json = decode_token(user.access_token)

    if 'base_url' not in _config:
        _config['base_url'] = request.base_url

    if 'redirect_uri' not in _config:
        _config['redirect_uri'] = _config['base_url'].rstrip('/') + '/callback'

    if is_logged_in:
        return render_template('index.html',
                               server_name=_config['issuer'],
                               session=user)
    else:
        client_data = _client.get_client_data()
        is_registered = client_data and 'client_id' in client_data
        client_id = client_data['client_id'] if is_registered else ''
        return render_template('welcome.html',
                               registered=is_registered,
                               client_id=client_id,
                               issuer=_config['issuer'],
                               client_data=_client.get_client_data())
Beispiel #2
0
def index():
    """
    :return: the index page with the tokens, if set.
    """
    user = None
    if 'session_id' in session:
        user = _session_store.get(session['session_id'])

    if 'base_url' not in _config or not _config['base_url']:
        _config['base_url'] = request.base_url

    if 'redirect_uri' not in _config:
        _config['redirect_uri'] = _config['base_url'].rstrip('/') + '/callback'

    if isinstance(user, (str, unicode)):
        # User is a string! Probably a bunch of HTML from a previous error. Just bail and hope for the best.
        return user

    if user:
        if user.front_end_id_token:
            user.front_end_id_token_json = decode_token(
                user.front_end_id_token)

        if user.front_end_access_token:
            user.front_end_access_token_json = decode_token(
                user.front_end_access_token)

        if user.id_token:
            user.id_token_json = decode_token(user.id_token)

        if user.access_token:
            user.access_token_json = decode_token(user.access_token)

        return render_template('index.html',
                               server_name=_config['issuer'],
                               session=user,
                               flow=session.get("flow", "code"))
    else:
        client_data = _client.get_client_data()
        dynamically_registered = bool(client_data
                                      and 'client_id' in client_data)
        using_static_registration = "client_id" in _config and "client_secret" in _config
        registered = dynamically_registered or using_static_registration
        client_id = client_data[
            'client_id'] if dynamically_registered else _config.get(
                "client_id", "")

        return render_template(
            'welcome.html',
            registered=registered,
            client_id=client_id,
            server_name=_config['issuer'],
            client_data=client_data,
            flow="code",
            using_dynamic_registration=dynamically_registered,
            authorization_endpoint=_config["authorization_endpoint"])
Beispiel #3
0
def index():
    """
    :return: the index page with the tokens, if set.
    """
    user = None
    if 'session_id' in session:
        user = _session_store.get(session['session_id'])
    if user:
        if user.id_token:
            user.id_token_json = decode_token(user.id_token)
        if user.access_token:
            user.access_token_json = decode_token(user.access_token)

    return render_template('index.html',
                           server_name=urlparse(
                               _config['authorization_endpoint']).netloc,
                           session=user)
Beispiel #4
0
def index():
    """
    :return: the index page with the tokens, if set.
    """
    user = None
    if 'session_id' in session:
        user = _session_store.get(session['session_id'])

    if 'base_url' not in _config or not _config['base_url']:
        _config['base_url'] = request.base_url

    if 'redirect_uri' not in _config:
        _config['redirect_uri'] = _config['base_url'].rstrip('/') + '/callback'

    if user:
        if user.front_end_id_token:
            user.front_end_id_token_json = decode_token(
                user.front_end_id_token)

        if user.front_end_access_token:
            user.front_end_access_token_json = decode_token(
                user.front_end_access_token)

        if user.id_token:
            user.id_token_json = decode_token(user.id_token)

        if user.access_token:
            user.access_token_json = decode_token(user.access_token)

        return render_template('index.html',
                               server_name=_config['issuer'],
                               session=user,
                               flow=session.get("flow", "code"))
    else:
        client_data = _client.get_client_data()
        is_registered = client_data and 'client_id' in client_data
        client_id = client_data['client_id'] if is_registered else ''
        return render_template('welcome.html',
                               registered=is_registered,
                               client_id=client_id,
                               server_name=_config['issuer'],
                               client_data=client_data)