title: How to configure FIWARE Components to avoid AZF domain not created for application response
body: <p>Summary of the question: How can we let the FIWARE IdM Keyrock and the FIWARE Authzforce set properly the AZF domains, thus without getting "AZF domain not created for application XYZ" response?</p>
  
  <p>I'm trying to configure a server with FIWARE Orion, FIWARE PepProxy Wilma, FIWARE IdM Keyrock, FIWARE Authzforce properly.
  I arrived at the point in which the first 3 components work properly and interact with each other, but now I'm trying to insert autorization and I obtain the following error:
  <code>AZF domain not created for application</code>.
  I've already tried all the solutions presented at the following links but no one works:</p>
  
  <ul>
  <li><a href="https://fiware-pep-proxy.readthedocs.io/en/latest/user_guide/#level-2-basic-authorization" rel="nofollow noreferrer">https://fiware-pep-proxy.readthedocs.io/en/latest/user_guide/#level-2-basic-authorization</a></li>
  <li><a href="https://www.youtube.com/watch?v=coxFQEY0_So" rel="nofollow noreferrer">https://www.youtube.com/watch?v=coxFQEY0_So</a></li>
  <li><a href="https://stackoverflow.com/questions/29628531/how-to-configure-the-fiware-pep-wilma-proxy-to-use-a-keyrock-and-orion-instance/31169049#31169049">How to configure the Fiware PEP WILMA proxy to use a Keyrock and Orion instance on my own servers</a></li>
  <li><a href="https://stackoverflow.com/questions/45017142/fiware-idmauthzforcepep-proxy-wilma/45018719#45018719">Fiware IDM+AuthZForce+PEP-Proxy-Wilma</a></li>
  <li><a href="https://stackoverflow.com/questions/49360026/fiware-how-to-connect-pep-proxy-to-orion-and-configure-both-with-https">Fiware - how to connect PEP proxy to Orion and configure both with HTTPS?</a></li>
  <li><a href="https://stackoverflow.com/questions/42714175/fiware-authzforce-error-azf-domain-not-created-for-application">Fiware AuthZForce error: &quot;AZF domain not created for application&quot;</a></li>
  <li><a href="https://stackoverflow.com/questions/36606813/authzforce-security-level-2-basic-authorization-error-azf-domain-not-created-f">AuthZForce Security Level 2: Basic Authorization error &quot;AZF domain not created for application&quot;</a></li>
  <li><a href="https://www.slideshare.net/daltoncezane/integrating-fiware-orion-keyrock-and-wilma" rel="nofollow noreferrer">https://www.slideshare.net/daltoncezane/integrating-fiware-orion-keyrock-and-wilma</a></li>
  <li><a href="https://stackoverflow.com/questions/40513118/azf-domain-not-created-for-application-authzforce">“AZF domain not created for application” AuthZforce</a></li>
  <li><a href="https://stackoverflow.com/questions/42714175/fiware-authzforce-error-azf-domain-not-created-for-application">Fiware AuthZForce error: &quot;AZF domain not created for application&quot;</a></li>
  <li><a href="https://stackoverflow.com/questions/42622048/fiware-suitable-components">Fiware suitable Components</a></li>
  <li><a href="https://www.slideshare.net/FI-WARE/adding-identity-management-and-access-control-to-your-app-70523086" rel="nofollow noreferrer">https://www.slideshare.net/FI-WARE/adding-identity-management-and-access-control-to-your-app-70523086</a></li>
  <li><a href="https://authzforce-ce-fiware.readthedocs.io/en/latest/UserAndProgrammersGuide.html#integration-with-the-idm-and-pep-proxy-ges-e-g-for-oauth" rel="nofollow noreferrer">Official documentation not usable because refers to (maybe) old python version of IdM</a></li>
  </ul>
  
  <p>In the following you can find the instructions to reproduce my scenario:</p>
  
  <ol>
  <li><p>Install Orion by using the Docker container</p>
  
  <ul>
  <li>Create a directory on your system on which to work (for example, <code>/home/fiware-orion-docker</code>).</li>
  <li>Create a new file called <code>docker-compose.yml</code> inside your directory with the following contents:  </li>
  </ul>
  
  <pre><code>     mongo:
           image: mongo:3.4
           command: --nojournal
       orion:
           image: fiware/orion
           links:
               - mongo
           ports:
               - "1026:1026"
           command: -dbhost mongo -logLevel DEBUG
           dns:
               - 208.67.222.222
               - 208.67.220.220
  </code></pre>
  
  <ul>
  <li>PAY ATTENTION: without the DNS it will never send notifications!!!</li>
  <li><p>PAY ATTENTION 2 (<a href="https://svenv.nl/unixandlinux/dockerufw/" rel="nofollow noreferrer">source</a> ): Connections from docker containers get routed into the (iptables) FORWARD chain, this needs to be configured to allow connections through it. The default is to DROP the connections. Thus if you use a firewall you have to change it:</p>
  
  <ul>
  <li><code>sudo nano /etc/default/ufw</code></li>
  <li>Set DEFAULTFORWARDPOLICY to “ACCEPT”.
      <code>
      DEFAULT_FORWARD_POLICY="ACCEPT"
  </code></li>
  <li>Save the file.</li>
  <li>Reload ufw
      <code>
      sudo ufw reload
  </code></li>
  </ul></li>
  <li>Within the directory you created, type the following command in the command line: <code>sudo docker-compose up -d</code>.</li>
  <li>After a few seconds you should have your Context Broker running and listening on port <code>1026</code>.</li>
  <li>Check that everything works with<br>
       <code>curl localhost:1026/version</code></li>
  </ul></li>
  <li><p>Install FIWARE IdM Keyrock (used for authentication over the Orion Context Broker):<br>
  <a href="https://github.com/ging/fiware-idm" rel="nofollow noreferrer">https://github.com/ging/fiware-idm</a></p>
  
  <ul>
  <li>WARNING -1: (if the next command doesn't work: <code>
  sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu artful stable"</code> )</li>
  <li>WARNING 0: if you have a firewall: <strong>DISABLE IT</strong>, otherwise docker-compose will not work</li>
  <li>sudo apt-get install docker-compose</li>
  <li>mkdir fiware-idm</li>
  <li>cd fiware-idm</li>
  <li>create docker-compose.yml
  <code>nano docker-compose.yml</code></li>
  </ul>
  
  <pre><code>    version: "3.5"
  services:
      keyrock:
          image: fiware/idm:7.6.0
          container_name: fiware-keyrock
          hostname: keyrock
          networks:
              default:
                  ipv4_address: 172.18.1.5
          depends_on:
              - mysql-db
          ports:
              - "3000:3000"
          environment:
              - DEBUG=idm:*
              - IDM_DB_HOST=mysql-db
              - IDM_HOST=http://localhost:3000
              - IDM_PORT=3000
              # Development use only
              # Use Docker Secrets for Sensitive Data
              - IDM_DB_PASS=secret
              - IDM_DB_USER=root
              - IDM_ADMIN_USER=admin
              - IDM_ADMIN_EMAIL=admin@test.com
              - IDM_ADMIN_PASS=1234
  
      mysql-db:
          restart: always
          image: mysql:5.7
          hostname: mysql-db
          container_name: db-mysql
          expose:
              - "3306"
          ports:
              - "3306:3306"
          networks:
              default:
                  ipv4_address: 172.18.1.6
          environment:
              # Development use only
              # Use Docker Secrets for Sensitive Data
              - "MYSQL_ROOT_PASSWORD=secret"
              - "MYSQL_ROOT_HOST=172.18.1.5"
          volumes:
              - mysql-db:/var/lib/mysql
  
  networks:
      default:
          ipam:
              config:
                  - subnet: 172.18.1.0/24
  volumes:
      mysql-db: ~
  </code></pre>
  
  <ul>
  <li><code>sudo docker-compose up -d</code> (This will automatically download the two images and run the IdM Keyrock service. (-d is used to run it in background)).  </li>
  <li>Now you should be able to access the Identity Management tool through the website <a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>
  
  <ul>
  <li>username: <code>admin@test.com</code></li>
  <li>password: <code>1234</code></li>
  </ul></li>
  <li>Register a new user and enable it through the interface</li>
  <li>Then use the GUI to:
  
  <ul>
  <li>Create an "Organization" (e.g., ORGANIZ1)</li>
  <li>Create an "application"
  
  <ul>
  <li>Step 1:  
  
  <pre><code>Name: Orion Idm
  Description: Orion Idm
  URL: http://localhost
  Callback URL: http://localhost
  Grant Type: Authorization Code, Implicit, Resource Owner Password, Client Credentials, Refresh Token
  Provider: newuser
  </code></pre></li>
  <li>Step 2: leave empty</li>
  <li>Step 3: choose "Provider"</li>
  <li>Step 4: 
  
  <ul>
  <li>click on "OAuth2 Credentials" and take notes of "Client ID" (94480bc9-43e8-4c15-ad45-0bb227e42e63) and "Client Secret" (4f6ye5y7-b90d-473a-3rr7-ea2f6dd43246)</li>
  <li>Click on "PEP Proxy" and then on "Register a new PEP Proxy"</li>
  <li>take notes of "Application Id" (94480bc9-43e8-4c15-ad45-0bb227e42e63), "Pep Proxy Username" (pep_proxy_dad356d2-dasa-4f95-a9hf-9ab06tccf929), and "Pep Proxy Password" (pep_proxy_a33667ec-57y1-498k-85aa-ef77ue5f6234)</li>
  <li>Click on "Authorize" (Users) and authorize all the existing users with both roles (Purchaser and Provider for all the options)</li>
  <li>Click on "Authorize" (Organizations) and authorize all the existing organizations with both roles (Purchaser and Provider for all the options)</li>
  </ul></li>
  </ul></li>
  </ul></li>
  </ul></li>
  <li><p>Install the FIWARE Authzforce</p>
  
  <ul>
  <li><code>sudo docker pull authzforce/server:latest</code> (latest was 8.1.0 at the moment of writing)</li>
  <li><code>sudo docker run -d -p 8085:8080 --name authzforce_server authzforce/server</code></li>
  </ul></li>
  <li><p>Install the FIWARE PEP Proxy Wilma (used to enable https and authentication for Orion):</p>
  
  <ul>
  <li>git clone <a href="https://github.com/ging/fiware-pep-proxy.git" rel="nofollow noreferrer">https://github.com/ging/fiware-pep-proxy.git</a></li>
  <li>cd fiware-pep-proxy</li>
  <li>cp config.js.template config.js</li>
  <li>nano config.js  </li>
  </ul>
  
  <pre><code>var config = {};
  
      // Used only if https is disabled
      config.pep_port = 5056;
      config.https = undefined
  
      config.idm = {
          host: 'localhost',
          port: 3000,
          ssl: false
      }
  
      config.app = {
          host: 'localhost',
          port: '1026',
          ssl: false // Use true if the app server listens in https
      }
  
      config.response_type = 'code';
  
      // Credentials obtained when registering PEP Proxy in app_id in Account Portal
      config.pep = {
          app_id: '91180bc9-43e8-4c14-ad45-0bb117e42e63',
          username: 'pep_proxy_dad356d2-dasa-4f95-a9hf-9ab06tccf929',
          password: 'pep_proxy_a33667ec-57y1-498k-85aa-ef77ue5f6234',
          trusted_apps : []
      }
  
      // in seconds
      config.cache_time = 300;
  
      // list of paths that will not check authentication/authorization
      // example: ['/public/*', '/static/css/']
      config.public_paths = [];
  
      config.magic_key = undefined;
  
      module.exports = config;
  
      config.authorization = {
          enabled: true,
          pdp: 'authzforce',      // idm|authzforce  
          azf: {
              protocol: 'http',
              host: 'localhost',
              port: 8085,
              custom_policy: undefined, // use undefined to default policy checks (HTTP verb + path).
          } 
      }
  
  </code></pre>
  
  <ul>
  <li>install all the dependencies
  <code>npm install</code></li>
  <li>run the proxy
  <code>sudo node server</code></li>
  </ul></li>
  <li><p>Create a user role:
  Reconnect to the IdM <code>http://localhost:3000</code>:</p>
  
  <ul>
  <li>click on your application</li>
  <li>click on <code>Manage rules</code> at the top of the page</li>
  <li>click on the <code>+</code> button near Roles
  
  <ul>
  <li>Name: "trial"</li>
  </ul></li>
  <li>Save</li>
  <li>click on the <code>+</code> button near Permission
  
  <ul>
  <li>Permission Name: trial1</li>
  <li>Description: trial1</li>
  <li>HTTP action: GET</li>
  <li>Resource: version</li>
  </ul></li>
  <li>Save</li>
  <li>come back to the application</li>
  <li>Click on "Authorize" near "Authorized users"</li>
  <li>Assign the "trial" role to your user</li>
  </ul></li>
  <li><p>Now use PostMan to get a token:</p>
  
  <ul>
  <li>connect to localhost:3000/oauth2/token and send the following parameters
  
  <ul>
  <li>Body:</li>
  <li>username: </li>
  <li>password: </li>
  <li>grant_type: password</li>
  <li>Header:</li>
  <li>Content-Type: application/x-www-form-urlencoded</li>
  <li>Authorization: BASIC </li>
  </ul></li>
  <li>take note of the obtained <code>access_token</code></li>
  </ul></li>
  <li><p>Try to connect to Orion though <a href="http://localhost:5056/version" rel="nofollow noreferrer">http://localhost:5056/version</a> with the following parameters:</p>
  
  <ul>
  <li>Header:
  
  <ul>
  <li>X-auth-token: </li>
  </ul></li>
  </ul></li>
  <li><p>You will obtain the following response:
  <code>AZF domain not created for application 91180bc9-43e8-4c14-ad45-0bb117e42e63</code></p></li>
  </ol>