<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Michał Zięba</title>
    <description>The latest articles on DEV Community by Michał Zięba (@mzieba-pretius).</description>
    <link>https://dev.to/mzieba-pretius</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2567086%2F4d94deb4-df8d-4cfb-a1b5-e19f0f230409.png</url>
      <title>DEV Community: Michał Zięba</title>
      <link>https://dev.to/mzieba-pretius</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mzieba-pretius"/>
    <language>en</language>
    <item>
      <title>Keycloak &amp; Docker integration tutorial: Learn how to do it step by step</title>
      <dc:creator>Michał Zięba</dc:creator>
      <pubDate>Mon, 16 Dec 2024 12:49:14 +0000</pubDate>
      <link>https://dev.to/mzieba-pretius/keycloak-docker-integration-tutorial-learn-how-to-do-it-step-by-step-1ioo</link>
      <guid>https://dev.to/mzieba-pretius/keycloak-docker-integration-tutorial-learn-how-to-do-it-step-by-step-1ioo</guid>
      <description>&lt;p&gt;&lt;strong&gt;Do you want to configure a Keycloak - Docker integration for your Angular app? Read on to find out how to set everything up.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Keycloak is a powerful authentication and authorization solution that provides plenty of useful features, such as roles and subgroups, advanced password policy and single sign-on (if you’re new to Keycloak, check out our &lt;a href="https://pretius.com/blog/keycloak-docker/" rel="noopener noreferrer"&gt;Keycloak SSO guide for 2024&lt;/a&gt;. It’s also very easy to integrate with other solutions. &lt;/p&gt;

&lt;p&gt;We’ve already shown you how to &lt;a href="https://pretius.com/blog/keycloak-angular-integration/" rel="noopener noreferrer"&gt;connect Keycloak to your Angular app&lt;/a&gt;, but there’s more you can do. For example, by integrating this technology with Cypress, you can enable the simulation of real-user login scenarios, including multi-factor authentication and social logins, ensuring that security protocols are correctly implemented and functioning as expected.&lt;/p&gt;

&lt;p&gt;Most importantly, you can also use Docker containers to provide a portable and consistent environment across different platforms (possibly with &lt;a href="https://www.armosec.io/glossary/container-image-scanning/" rel="noopener noreferrer"&gt;container image scanning&lt;/a&gt;, for increased security). This integration ensures easy deployment, scalability, and efficient dependency management, streamlining the process of securing applications and services. Additionally, Docker Compose can be used to orchestrate multiple containers, simplifying complex configurations and enhancing the overall management of Keycloak instances.&lt;/p&gt;

&lt;p&gt;This guide will show you precisely how to set all of this up. Let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;The article is based on the contents of a &lt;a href="https://www.armosec.io/glossary/container-image-scanning/" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; consisting of several elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frontend application written in Angular&lt;/li&gt;
&lt;li&gt;Keycloak configuration&lt;/li&gt;
&lt;li&gt;E2E tests written in Cypress&lt;/li&gt;
&lt;li&gt;Docker configuration for the whole stack&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The point of this tech stack is to allow users to work with Angular/Keycloak/Cypress locally and also in Docker containers. &lt;/p&gt;

&lt;h2&gt;
  
  
  Keycloak configuration
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fch3tze2osatdn23ygsnl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fch3tze2osatdn23ygsnl.png" alt="Image description" width="800" height="414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’ll start by setting up Keycloak, which is a crucial part of both configurations. The idea is to run it inside a Docker container and exposed at &lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt;. Keycloak has predefined configurations, including users, realm and client ID, so setting it up for this project requires minimum effort.&lt;/p&gt;

&lt;h3&gt;
  
  
  Normal user
&lt;/h3&gt;

&lt;p&gt;Your normal user in the Keycloak panel should be configured using the following details:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User:&lt;/strong&gt; test&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Password:&lt;/strong&gt; sIjKqg73MTf9uTU&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Keycloak administrator
&lt;/h3&gt;

&lt;p&gt;Here’s the default configuration for the admin user (of course, you probably shouldn’t use default settings for the admin account in real-world scenarios).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;User:&lt;/strong&gt; admin&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Password:&lt;/strong&gt; admin&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Local configuration
&lt;/h2&gt;

&lt;p&gt;This configuration allows you to work locally with an Angular application in dev mode along with E2E tests. It requires Keycloak to be run and available on &lt;strong&gt;&lt;a href="http://localhost:8080" rel="noopener noreferrer"&gt;http://localhost:8080&lt;/a&gt;&lt;/strong&gt;. This is set in the Docker configuration, which is partially used here. To run the configuration locally, use the following commands in the command line. &lt;/p&gt;

&lt;p&gt;First, in the main project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;strong&gt;/e2e&lt;/strong&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the main directory for frontend application development:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;strong&gt;/e2e&lt;/strong&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run cy:run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the main project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up -d keycloak
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Docker configuration
&lt;/h2&gt;

&lt;p&gt;Installing and configuring Docker is a relatively simple matter – the solution provides &lt;a href="https://www.armosec.io/glossary/container-image-scanning/" rel="noopener noreferrer"&gt;detailed documentation&lt;/a&gt; you can use if you run into any problems.&lt;/p&gt;

&lt;p&gt;In the context of our project, the Docker configuration does several key things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Running Keycloak and importing the predefined realm along with users&lt;/li&gt;
&lt;li&gt;Building and exposing the Angular application on &lt;strong&gt;&lt;a href="http://localhost:4200" rel="noopener noreferrer"&gt;http://localhost:4200&lt;/a&gt;&lt;/strong&gt; via &lt;strong&gt;nginx&lt;/strong&gt; on a separate Docker container&lt;/li&gt;
&lt;li&gt;Running &lt;strong&gt;e2e&lt;/strong&gt; container to allow you to run tests via Cypress&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To run a dockerized configuration, type in the command line in the main project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  docker-compose up -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run Cypress tests inside the container, use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker container exec -ti e2e bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, inside the container, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  npm run cy:run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test artifacts are connected to the host machine via volume, so test reports, screenshots and videos will be available immediately on path &lt;strong&gt;/e2e/cypress/&lt;/strong&gt; in the following folders: &lt;strong&gt;reports&lt;/strong&gt;, &lt;strong&gt;screenshots&lt;/strong&gt; and &lt;strong&gt;videos&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;And that’s about it. As you can see, integrating Keycloak (or rather an Angular app that uses Keycloak), Docker and Cypress is a relatively straightforward process. There are only a couple of steps you must take to get a consistent, containerized environment for easy deployment, scaling and efficient dependency management – with the added benefit of real-user login scenario simulation thanks to Cypress for top-notch security.&lt;/p&gt;

&lt;p&gt;Feel free to use our &lt;a href="https://github.com/Pretius/angular-keycloak-e2e-integration" rel="noopener noreferrer"&gt;repository on GitHub&lt;/a&gt;. And if you need to set up an enterprise-grade project based on these technologies, let us know at &lt;a href="//mailto:hello@pretius.com"&gt;hello@pretius.com&lt;/a&gt; (or by using the contact form below this blogpost). At Pretius, we strive in such software projects so there’s a big chance that we could help you do it.&lt;/p&gt;

&lt;p&gt;In the meantime, if you’re interested in content related to Keycloak or Angular, you can also check out some of the other publications on our blog:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://pretius.com/blog/keycloak-angular-integration/" rel="noopener noreferrer"&gt;Keycloak-Angular integration: Practical tutorial for connecting your app to a powerful IAM system&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pretius.com/blog/keycloak-sso/" rel="noopener noreferrer"&gt;Keycloak SSO guide for 2024: Advantages, installation, protips, and the real cost&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pretius.com/blog/keycloak-tutorial/" rel="noopener noreferrer"&gt;Keycloak tutorial: Learn how to use this technology's advanced features&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pretius.com/blog/angularjs-upgrade/" rel="noopener noreferrer"&gt;AngularJS upgrade: Why 2023 is the time for migrating and how to do it&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pretius.com/blog/angular-vs-react/" rel="noopener noreferrer"&gt;Angular vs React: In-depth comparison of the most popular front-end technologies&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>keycloak</category>
      <category>docker</category>
      <category>angular</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
