Skip to main content
Account
Lesson 6 of 9

Your First Application

Learn how to configure your first application in the Zitadel console, hook it up to a sample application, and inspect the JWT claims. We'll cover the PKCE flow, token introspection, and adding user roles.

Your First Application

Hello, welcome back. So far we’ve covered how to install and get Zitadel ready. I think it’s about time we take a look at how to actually make it work and integrate with your applications. So in this video we are gonna take a look at the Zitadel console, configure our first application, and get it hooked up to the point where we can log in and visualize the claims of our JWT token.

Let’s have some fun.

Creating Your First Application

The first thing we’re gonna do is click Create an application. This guides us through creating our first project. I’ll call this Rawkode Academy.

Now you can select that you have some sort of front end framework. I’ll click React. This is just telling us we’re going to use the PKCE flow. I’ll cover more about that in just a moment, but this is the recommended, preferred, most secure way to handle OIDC within your application.

We then need to provide a redirect URL that is allowed to go through our flow. Because we’re working on a local application today, we can leave this as a default localhost:3000/callback, although we will have to modify that shortly.

Click Create, and now we have our first project and application configured. A project can house one or more applications, meaning you can use the same project across mobile, web, server, CLIs, et cetera.

In order to make this work with our application, we’ll need to go to URLs where we can get the discovery endpoint. We copy this, and this endpoint contains everything that you need to configure any OIDC application.

Understanding PKCE

PKCE (Proof Key for Code Exchange) is a security extension for OAuth 2.0 that prevents authorization code interception attacks. It’s essential for public clients, like single-page applications and mobile applications that can’t securely store client secrets.

Here is how PKCE works:

  1. Your application generates a cryptographically random code verifier.
  2. It then creates a code challenge by applying a SHA256 hash to this verifier and Base64 URL encoding the result.
  3. When initiating the authorization request, your app sends a code challenge and challenge method to the authorization server.
  4. The user authenticates and grants permission. The authorization server returns an authorization code to your redirect URL.
  5. Your application can then exchange this code for tokens, but crucially, it must include the original code verifier.
  6. The authorization server verifies that the code verifier matches the challenge it received earlier.

If you’re working on a web application, you would typically have to provide a client ID and a client secret. For front-end applications, the PKCE flow is just a lot easier as you don’t have to worry about passing that secret material.

Integrating with a Sample App

Let’s run bun run dev and refresh our application. The code for this will be available in a resources section below.

Let’s click Login and our application asks for our OIDC well-known configuration URL and our OAuth client ID. We can get the client ID from the application configuration page.

After pasting them in, you might see an error about the redirect URI. This is a common issue. Because I’ve put together a very simple single-page application, we just need to modify our redirect URL to only be localhost:3000.

After correcting that, we can log in and we are presented with our token introspection page.

Token Introspection and Roles

The first thing we have is our access token, and the second thing we have is our ID token. The ID token can be decoded to give us claims. We can see here that we have the issuer, the subject, the audience, an expiration, and the client ID.

At the moment, there are no user roles. Let’s add some.

From the console, I have added two roles to this project, grouped into C-Suite and Forge. You can add roles as you wish. I can then go to Authorizations and assign these roles to my user for the project.

If we go back to our web application and log in again, we get a new token. The decoded claims are bigger, and we can now see the roles assigned to our user.

Required Configuration

For this to work, we do have to configure a few things within the project and the organization.

In our React application’s Token Settings, you’ll see that we have User Roles and User Info inside ID Token enabled. This makes it easy to debug and print that information to the UI. If you don’t have this, your application can just as easily contact the user info endpoint to get this information once it has the authentication token.

Also, within the organization’s Login Settings, we need to make sure that User Registration is allowed. This is disabled by default, so you will have to turn this on when you create your new Zitadel instance.

In subsequent videos, we’re gonna take a look at turning on SSO and OAuth authentication, allowing our users to sign in with their own accounts rather than Zitadel provisioned users. We will also take a look at the simple email and password user registration flow soon, too.

Transcript

Generated from English captions. Select a timestamp to jump to that moment.

0:01 David Flanagan: Hello, welcome back. So far we've covered how to install and get Zitadel ready. I think it's about time we take a look at how to actually make it work and integrate with your applications. So in this video we are gonna take a look at the Zitadel console, configure our first application, and get it hooked up to the point where we can log in and visualize the claims of our JWT token. Let's have some fun. So the first thing we're gonna do is click create an application. This guides us through creating our first project.

0:52 I'll call this Raw Code Academy. Now you can select that you have some sort of front end framework. So I'll click React. Now this is just telling us we're going to use the PKCE flow. And I'll cover more about that in just a moment, but this is the recommended, preferred, most secure way to handle OIDC within your application. We then need to provide a redirect URL that is allowed to go through our flow. Now because we're working on a local application today. We can leave this as a default localhost:3000/callback, although we will have to modify that shortly.

1:42 We click create, and now we have our first project and application configured. If we click back here, we can click on our Rawkode Academy project and we'll see our React application here. A project can house one or more applications, meaning you can use. The same project across mobile web server, CLIs, et cetera. Now, in order to make this work with our application, we'll need to go to URLs where we can get the discovery endpoint. We copy this, and this endpoint contains everything that you need to configure any OIDC application. So let's talk about PKCE. So PKCE is a security extension for OAuth two that prevents authorization

2:37 code interception attacks. It's essential for public clients, like single page applications and mobile applications that can't securely store client secrets. Here is how PKCE works. Your application generates a cryptographically random code verifier. This is the 43 to 128 character string. It then creates a code challenge by applying a sha256 to this verifier and base64 URL encoding the result. When initiating the authorization request, your app sends a code challenge and challenge method to the authorization server. The user authenticates and grants permission. The authorization server returns an authorization code to your redirect URL. Your application can then exchange this code for tokens, but crucially, it must

3:37 include the original code verifier. The authorizations server verifies that the code verifier matches the challenge it received earlier. Simple. Now, you don't need to understand all of that. Just take away that if you're working on a web application, typically you would have to provide a client ID and a client secret with the client's secret being available on the server side of your application. But for front end applications, the PKCE flow is just a lot easier where you don't have to worry about passing that secret material or providing a server API endpoint to handle that for you.

4:25 Making your life that little bit easier as we're about to see. All right, so let's run bun run dev, and refresh our application. Now, the code for this will be available in a resources section below. Let's click login and our application asks for our OIDC well-known configuration, URL and our OAuth client. so we can click configuration and grab our client ID here. We drop this in, we click okay. And now it's telling us that our read write URI doesn't reflect our configuration. Now, if you're ever unsure what that is, you can look at the URL, whether U uh,

5:09 rewrite URL is actually inside of your URL because I'm building or have put together a very simple single page application. We just need to modify a redirect URL to only be localhost:3000, which I could have done when setting up, but I did want to walk through that that error is very common and happens all the time. So we could just go back where we click login. Paste or configuration, URL paste then or client id, and we are presented with. Our token introspection, magic webpage, not very exciting, but it will allow us to understand what just happened.

6:09 the second thing we have is our ID token. The ID token can be decoded to give us claims. And we can see here that we have the issuer, which is our Zitadel Cloud instance. The subject, which is my user account, the subject has access to a couple of audiences. One of them being our prototype project that we just set up. The other one being the Zitadel organization itself. For management purposes, our token has an expiration, which is configured through the default settings, and then we have the client id, et cetera. Now, at the moment, there are no user roles, so I'm going to log out

6:52 and come back to the Zitadel admin. So from console I have added two roles to this project. These are grouped, so I have a C-Suite group and a forge group, A kept forge where someone could be a contributor or someone could be the CEO of the C-suite. Now you can add roles as much as you want, like A COO, and add this also to the C-suite, completely arbitrary. You decide what works for you. I can then go to authorizations and say, new, where I select the admin user, which is myself, the Rawkode Academy project. And then I can get myself every role.

7:35 Now, I probably wouldn't be the COO and CEO. So we'll turn one off and click save. We can then go back to our web application And log in. We have a new access token, a new ID token. Our decoded claims are bigger, and already we can see the roles and the raw form here, and a list of roles here. Awesome. So before we wrap this up. Let's just confirm and take a look at a few things that are happening because of configuration within Zitadel. Okay, so in order for this to work, we do have to configure a few things

8:22 within the project and the organization. So if we come into our React application. And go to token settings. You'll see that we have user roles and user info inside of the ID token. This is just what it made it easy to debug, introspect, and print that information to the web ui. If you don't have this, your application can just as easily contact the user info endpoint to get this information once it has the authentication token. Also within the organization, we click modify into login and we scroll down to make sure that registration, user registration is allowed.

9:08 This is disabled by default, so you will have to turn this on when you create your new Zitadel instance. Other than that, there's not a lot to cover. And then subsequent videos, we're gonna take a look at turning on SSO and OAuth authentication, allowing our users to sign in with their own accounts rather than Zitadel provisioned users. But we will also take a look at the simple email and password user registration flow soon. Two. So go check out those videos and we'll see you all next time on the Ccomplete Guide to Zitadel.

Course curriculum (9 lessons)
  1. 01. Introduction
  2. 02. Prerequisites
  3. 03. How to Install Zitadel with Docker Compose (Step-by-Step)
  4. 04. Installing Zitadel on Kubernetes with Helm
  5. 05. Zitadel Cloud
  6. 06. Your First Application
  7. 07. Integrating with an Astro Application
  8. 08. Passwords, Passkeys, and MFA
  9. 09. Configuring OAuth Providers (Google, GitHub, etc.)

Loading optional course email signup. If it does not load, reload this lesson to retry. Signup requires JavaScript; all lesson content remains available without signing up.