From the course: Transitioning from Java to Kotlin

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Authenticating routes

Authenticating routes

- [Instructor] We've added the ability to add items to our ProductDatabase. This is very helpful if you're an admin or other team member, but probably not something that should be publicly accessible to anyone. Let's take a look at how basic authentication works in Ktor, so that we may prevent unauthorized access to our endpoints for manipulating the database. Authentication in Ktor is another plugin. So, like other plugins, we'll start by adding the dependency to our project. So, we'll open our build.gradle file, and we will add in a new dependency for ktor-server-auth. And then, we will resync our project. And again, like other plugins, we will create an extension method to configure how authentication should work for our application. So, in our plugins package, we will create a new Kotlin file. And we will name this one Authentication. And we will create our basic extension step. And name the function…

Contents