示例#1
0
def oxd_login():
    if current_user.is_authenticated:
        return redirect(url_for("index.home"))

    config = current_app.config["OXD_CLIENT_CONFIG_FILE"]

    if not os.path.exists(config):
        flash("Unable to locate oxd client config file.".format(config),
              "warning")
        return redirect(url_for("index.home"))

    oxc = Client(config)

    try:
        auth_url = oxc.get_authorization_url()
    except OxdServerError as exc:
        print exc  # TODO: use logging
        flash("Failed to process the request due to error in OXD server.",
              "warning")
    except socket.error as exc:
        print exc  # TODO: use logging
        flash("Unable to connect to OXD server.", "warning")
    else:
        return redirect(auth_url)
    return redirect(url_for("index.home"))
示例#2
0
def test_get_auth_url_accepts_optional_params():
    c = Client(config_location)
    # acr values
    auth_url = c.get_authorization_url(["basic", "gplus"])
    assert_in('basic', auth_url)
    assert_in('gplus', auth_url)

    # prompt
    auth_url = c.get_authorization_url(["basic"], "login")
    assert_in('basic', auth_url)
    assert_in('prompt', auth_url)

    # scope
    auth_url = c.get_authorization_url(["basic"], None,
                                       ["openid", "profile", "email"])
    assert_in('openid', auth_url)
    assert_in('profile', auth_url)
    assert_in('email', auth_url)
示例#3
0
def test_openid_commands(config_file):
    """function that runs the commands in a interactive manner

    :param config_file: config file location
    """
    c = Client(config_file)

    print "\n=> Setup Client"
    setup_data = c.setup_client()
    logging.info("Received: %s", setup_data)

    print "\n=> Get Client Token"
    tokens = c.get_client_token(auto_update=False)
    logging.info("Received: %s", tokens)

    print "\n=> Introspect Access Token"
    introspection = c.introspect_access_token(
        access_token=tokens['access_token'])
    logging.info("Received: %s", introspection)

    print "\n=> Update site registration"
    updated = c.update_site()
    c.config.set("client", "scope", "openid,profile")
    logging.info("Received: %s", updated)

    print "\n=> Getting auth URL"
    auth_url = c.get_authorization_url()
    print "Visit this URL in your browser: ", auth_url
    logging.info("Received: %s", auth_url)

    print "\n=> Getting tokens by code"
    callback_url = raw_input("Enter redirected URL to parse tokens: ")
    parsed = urlparse.urlparse(callback_url)
    params = urlparse.parse_qs(parsed.query)
    tokens = c.get_tokens_by_code(params['code'][0], params['state'][0])
    logging.info("Received: %s", tokens)

    print "\n=> Getting user info"
    claims = c.get_user_info(tokens['access_token'])
    logging.info("Received: %s", claims)

    print "\n=> Getting new access token using refresh token"
    new_token = c.get_access_token_by_refresh_token(tokens["refresh_token"])
    logging.info("Received: %s", new_token)

    print "\n=> Getting Logout URI"
    logout_uri = c.get_logout_uri()
    logging.info("Received: %s", logout_uri)
    print "Visit this URL to logout: ", logout_uri

    print "\n=> Register Site"
    reg = c.register_site()
    logging.info("Received: %s", reg)

    print "\n=> Remove Site"
    oxd_id = c.remove_site()
    logging.info("Received: %s", oxd_id)
示例#4
0
def test_get_auth_url_accepts_optional_params():
    c = Client(config_location)
    # acr values
    auth_url = c.get_authorization_url(["basic", "gplus"])
    assert_in("basic", auth_url)
    assert_in("gplus", auth_url)

    # prompt
    auth_url = c.get_authorization_url(["basic"], "login")
    assert_in("basic", auth_url)
    assert_in("prompt", auth_url)

    # scope
    auth_url = c.get_authorization_url(["basic"], None, ["openid", "profile", "email"])
    assert_in("openid", auth_url)
    assert_in("profile", auth_url)
    assert_in("email", auth_url)

    # hd
    auth_url = c.get_authorization_url(None, None, None, "https://test.com")
    assert_in("https://test.com", auth_url)
    assert_in("hd", auth_url)
示例#5
0
def test_get_authorization_url_works_wihtout_explicit_site_registration():
    c = Client(config_location)
    c.oxd_id = None  # assume the client isn't registered
    auth_url = c.get_authorization_url()
    assert_in('callback', auth_url)
示例#6
0
def test_get_authorization_url():
    c = Client(config_location)
    auth_url = c.get_authorization_url()
    assert_in('callback', auth_url)
示例#7
0
def test_get_auth_url_accepts_acrvalues_as_optional_params():
    c = Client(config_location)
    auth_url = c.get_authorization_url(["basic", "gplus"])
    assert_in('basic', auth_url)
    assert_in('gplus', auth_url)
示例#8
0
def test_get_authorization_url():
    c = Client(config_location)
    auth_url = c.get_authorization_url()
    assert_in('client_secret', auth_url)
示例#9
0
def test_get_authorization_url_works_wihtout_explicit_site_registration():
    c = Client(config_location)
    c.oxd_id = None  # assume the client isn't registered
    auth_url = c.get_authorization_url()
    assert_in("callback", auth_url)
示例#10
0
def test_get_authorization_url():
    c = Client(config_location)
    auth_url = c.get_authorization_url()
    assert_in("callback", auth_url)