def test_list_option_with_2_client_ids_in_db(self, db_file_path):
        client_ids = {'the_first', 'the_2nd'}

        client_db = CDB(db_file_path)
        for client_id in client_ids:
            client_db.cdb[client_id] = {
                'client_secret':
                'hardToGuess',
                'client_id':
                client_id,
                'client_salt':
                'saltedAndReady!',
                'redirect_uris':
                pack_redirect_uri(
                    ['file:///dev/null', 'http://localhost:1337/'])
            }
        client_db.cdb.close()

        for list_option_form in ('-l', '--list'):
            result = run(CLI_INVOCATION + list_option_form + ' ' +
                         db_file_path,
                         shell=True,
                         stdout=PIPE,
                         stderr=STDOUT)
            assert set(result.stdout.decode().splitlines()) == client_ids
    def test_list_option_with_2_client_ids_in_db(self, db_file_path):
        client_ids = {"the_first", "the_2nd"}

        client_db = CDB(db_file_path)
        for client_id in client_ids:
            client_db.cdb[client_id] = {
                "client_secret":
                "hardToGuess",
                "client_id":
                client_id,
                "client_salt":
                "saltedAndReady!",
                "redirect_uris":
                pack_redirect_uri(
                    ["file:///dev/null", "http://localhost:1337/"]),
            }
        client_db.cdb.close()

        for list_option_form in ("-l", "--list"):
            result = run(
                CLI_INVOCATION + list_option_form + " " + db_file_path,
                shell=True,
                stdout=PIPE,
                stderr=STDOUT,
            )
            assert set(result.stdout.decode().splitlines()) == client_ids
Esempio n. 3
0
def generate_static_client_credentials(parameters):
    redirect_uris = parameters['redirect_uris']
    jwks_uri = str(parameters['jwks_uri'][0])
    _cdb = CDB(config.CLIENT_DB)
    static_client = _cdb.create(redirect_uris=redirect_uris,
                                # policy_uri="example.com",
                                # logo_uri="example.com",
                                jwks_uri=jwks_uri)
    return static_client['client_id'], static_client['client_secret']
Esempio n. 4
0
def generate_static_client_credentials(parameters):
    redirect_uris = parameters['redirect_uris']
    jwks_uri = str(parameters['jwks_uri'][0])
    _cdb = CDB(config.CLIENT_DB)
    static_client = _cdb.create(redirect_uris=redirect_uris,
                                # policy_uri="example.com",
                                # logo_uri="example.com",
                                jwks_uri=jwks_uri)
    return static_client['client_id'], static_client['client_secret']
Esempio n. 5
0
def generate_static_client_credentials(parameters):
    redirect_uris = parameters['redirect_uris']
    client_db_path = os.environ.get("OIDC_CLIENT_DB", "client_db")
    LOGGER.info("Updating db: {}".format(client_db_path))
    cdb = CDB(client_db_path)
    static_client = cdb.create(redirect_uris=redirect_uris,
                               policy_uri="example.com",
                               logo_uri="example.com")
    static_client["response_types"] = [
        "code", "id_token", "id_token token", "code id_token", "code token",
        "code id_token token"
    ]
    cdb.cdb.close()
    LOGGER.info("Generated client credentials: %s", json.dumps(static_client))
    return static_client['client_id'], static_client['client_secret']
    def test_list_option_with_1_client_id_in_db(self, db_file_path):
        client_db = CDB(db_file_path)
        client_db.cdb['the_first'] = {
            'client_secret': 'hardToGuess',
            'client_id': 'the_first',
            'client_salt': 'saltedAndReady!',
            'redirect_uris': pack_redirect_uri(['file:///dev/null'])
        }
        client_db.cdb.close()

        for list_option_form in ('-l', '--list'):
            result = run(CLI_INVOCATION + list_option_form + ' ' +
                         db_file_path,
                         shell=True,
                         stdout=PIPE,
                         stderr=STDOUT)
            assert result.stdout.decode().splitlines() == ['the_first']
    def test_list_option_with_1_client_id_in_db(self, db_file_path):
        client_db = CDB(db_file_path)
        client_db.cdb["the_first"] = {
            "client_secret": "hardToGuess",
            "client_id": "the_first",
            "client_salt": "saltedAndReady!",
            "redirect_uris": pack_redirect_uri(["file:///dev/null"]),
        }
        client_db.cdb.close()

        for list_option_form in ("-l", "--list"):
            result = run(
                CLI_INVOCATION + list_option_form + " " + db_file_path,
                shell=True,
                stdout=PIPE,
                stderr=STDOUT,
            )
            assert result.stdout.decode().splitlines() == ["the_first"]
def cdb():
    file = tempfile.NamedTemporaryFile()  # just get a unique filename
    file.close()
    return CDB(file.name)
Esempio n. 9
0
#!/usr/bin/env python
import json

from oic.utils.client_management import CDB

if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('-l', dest='list', action='store_true')
    parser.add_argument('-a', dest='add')
    parser.add_argument('-d', dest='delete')
    parser.add_argument(dest="config")
    args = parser.parse_args()

    # Client data base
    cdb = CDB(args.config)

    if args.list:
        for key, val in cdb.items():
            print('{}:{}'.format(key, val['redirect_uris']))

    if args.add:
        fp = open(args.add)
        spec = json.load(fp)
        cli_info = cdb.create(**spec)
        print(cli_info)

    if args.delete:
        del cdb[args.delete]