# Ktor gives me 404 on all authenticated routes

**URL:** <https://discuss.kotlinlang.org/t/ktor-gives-me-404-on-all-authenticated-routes/21085>\
**Category:** Support\
**Created:** [March 4, 2021, 3:15pm UTC](https://discuss.kotlinlang.org/t/ktor-gives-me-404-on-all-authenticated-routes/21085 "2021-03-04T15:15:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![raphael.tarita](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@raphael.tarita](https://discuss.kotlinlang.org/u/raphael.tarita)\
**Post date:** [March 4, 2021, 3:15pm UTC](https://discuss.kotlinlang.org/t/ktor-gives-me-404-on-all-authenticated-routes/21085/1 "2021-03-04T15:15:15Z")

</div>

So, I’ve been working on a server-side application with Ktor, which has both normal and authenticated routes inside the `routing` block. For some reason, I now get a 404 whenever I try to send a request to an authenticated endpoint.

The authentication I use is just `basic`, and I also checked that the credentials are not the problem here, by letting the validation in `"basicAuth"` always return a Principal. It still doesn’t work.

Basically, the structure is like this:

```kotlin
install(Authentication) {
    basic("basicAuth") {
        realm = "Ktor Server"
        validate { object : Principal {} } // to make sure the credentials don't matter in the test
    }
}

routing {
    // some endpoints, including static ones
    
    authenticate("basicAuth") {
        // authenticated endpoints which always return 404
    }
}

```

Now, when I try to access an endpoint that was defined inside of `autheticate`, I get the following response:

```auto
HTTP/1.1 404 Not Found
Vary: Origin
Date: [Date]
X-Engine: Ktor
Server: ktor-server-core/1.5.1 ktor-server-core/1.5.1
Content-Length: 0
Connection: keep-alive

<Response body is empty>

Response code: 404 (Not Found); Time: 45ms; Content length: 0 bytes

```

I have validated that any request from the `authenticate` block will magically work again when I put it in the outer `routing` block instead. With breakpoints, I found out that the handler code of the requested endpoint does not get executed at all, however, when installing `CallLogging`, the server will log:

```auto
[date and time] [DefaultDispatcher-worker-1] INFO Application - 404 Not Found: GET - [requested endpoint]

```

So the server somehow recognizes the request but fails to map it to an endpoint, although there’s one right there in the `authenticate` block.

The weirdest thing is that I remember testing those endpoints earlier and everything worked fine…

Anyway, if you know what the issue here could be, please let me know!

Thanks!

---

<div class="post-metadata">

**Author:** ![dalewking](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dalewking/32/1496_2.png) [@dalewking](https://discuss.kotlinlang.org/u/dalewking)\
**Post date:** [March 5, 2021, 1:22pm UTC](https://discuss.kotlinlang.org/t/ktor-gives-me-404-on-all-authenticated-routes/21085/2 "2021-03-05T13:22:09Z")

</div>

Seems more like a question that should be asked in ktor project, not here.

---

<div class="post-metadata">

**Author:** ![bjonnh](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/bjonnh/32/8106_2.png) [@bjonnh](https://discuss.kotlinlang.org/u/bjonnh)\
**Post date:** [March 10, 2021, 12:45am UTC](https://discuss.kotlinlang.org/t/ktor-gives-me-404-on-all-authenticated-routes/21085/3 "2021-03-10T00:45:45Z")

</div>

Can you try with no arguments for both basic and autheticate (remove the basicAuth) and use validate { null } ?

Ideally make a small git\* project that doesnt work.
