示例#1
0
def test_merge_client_preferred(keycloak_server, admin_username, admin_password):
    session = auth.AuthSession(admin_username, admin_password)
    kc_admin = admin.Admin(session)
    created_client = kc_admin.realm('master').create_client('test-merge-prefer-client', "openid-connect")
    merging_client = client.Client(session, dict_rep={'clientId': 'test-merge-prefer-client', 'enabled': True, 'protocol': 'openid-connect', 'directAccessGrantsEnabled': False })
    merged_client = created_client.merge(merging_client, prefer_self=True)
    assert merged_client.json['directAccessGrantsEnabled'] == True
示例#2
0
    def create_client(self, client_id, protocol, rootUrl=None):
        create_client_url = "{0}/auth/admin/realms/{1}/clients".format(
            self.auth_session.host, self.id)
        create_client_response = requests.post(
            create_client_url,
            json={
                'enabled': True,
                'attributes': {},
                'redirectUris': [],
                'clientId': client_id,
                'protocol': protocol,
                'rootUrl': rootUrl
            },
            headers=self.auth_session.bearer_header)

        # TODO fix inconsistent errors... most things just throw an exception
        # instead of providing useful feedback
        if create_client_response.status_code != 201:
            logging.error("Failed to create client: [{}]{}".format(
                create_client_response.status_code,
                create_client_response.text))
            raise RealmException(
                "Could not create client with clientId: {}".format(client_id))

        new_client = requests.get(create_client_response.headers['Location'],
                                  headers=self.auth_session.bearer_header)
        if new_client.status_code != 200:
            raise RealmException(
                "Error attempting to retrieve newly created client: {}".format(
                    client_id))

        return client.Client(self.auth_session,
                             json_rep=json.loads(new_client.text))
示例#3
0
 def client_id(self, client_id):
     client_json = next(
         filter(lambda client: client.get('clientId') == client_id,
                self.clients()), None)
     if client_json:
         return client.Client(self.auth_session, json_rep=client_json)
     else:
         return None
示例#4
0
    def client(self, id):
        client_url = "{0}/auth/admin/realms/{1}/clients/{2}".format(
            self.auth_session.host, self.id, id)
        client_response = requests.get(client_url,
                                       headers=self.auth_session.bearer_header)

        if (client_response.status_code != 200):
            raise RealmException(
                "Could not retrieve clients for id: {}.  Did you specify using the clientId field instead of GUID?"
                .format(id))

        return client.Client(self.auth_session,
                             json_rep=json.loads(client_response.text))
示例#5
0
    def update_client(self, updated_client):
        client_url = "{0}/auth/admin/realms/{1}/clients/{2}".format(
            self.auth_session.host, self.id, updated_client.get('id'))
        update_client_response = requests.put(
            client_url,
            json=updated_client,
            headers=self.auth_session.bearer_header)

        if update_client_response.status_code != 204:
            raise RealmException(
                "Error attempting to update client: {}".format(
                    updated_client['id']))

        updated_client = requests.get(client_url,
                                      headers=self.auth_session.bearer_header)
        if updated_client.status_code != 200:
            raise RealmException(
                "Error attempting to retrieve newly created client: {}".format(
                    client_id))

        return client.Client(self.auth_session,
                             json_rep=json.loads(updated_client.text))