0
votes

I'm attempting to add basic auth to a route using akka http 10.0.10 by doing the following:

def myUserPassAuthenticator(credentials: Credentials): Option[String] =
  credentials match {
    case p @ Credentials.Provided(id) if p.verify("p4ssw0rd") => Some(id)
    case _ => None
  }

val routes: Route =
  pathPrefix("foo") {
    authenticateBasic(realm = "secure site", myUserPassAuthenticator) { user =>
      path("bar") {
        pathEndOrSingleSlash {
          complete("bla")
        }
      }
    }
  }

This compiles but IDEA is showing me the following error:

Type mismatch, expected L => server.Route, actual String => server.Route

Additionally loading localhost:9000/foo/bar returns a 404. Can anybody help me understand why this is and how to properly structure these directives?

1
Did you import the import akka.http.scaladsl.server.Directives._?? It seems to be okEmiliano Martinez
yes, I did import akka.http.scaladsl.server.Directives._novon

1 Answers

1
votes

The above snipped is correct as far as akka http is concerned and now works fine. My problem came from a hand rolled CORS directive higher up in the directive hierarchy that was not implemented correctly.

Oddly enough IDEA is still complaining about the type mismatch though.