Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to authenticate OAuth2 with Akka-Http

Hi have a service developed using Akka-Http. I have to add OAuth to it and according to the documentation, I am using authenticateOAuth2 for this.

However the code isn't compiling and gives the error as

Type mismatch, expected: (L) => server.Route, actual: (OauthInfo) => server.Route

I am unable to find a proper solution to fix this issue. I even tried the exact code mentioned in the example in the documentation but it still throws similar compile time error.

I am using akka-http with circle.

Here is my code:

def route(implicit system: ActorSystem, mat: ActorMaterializer): Route =
Route.seal {
  pathPrefix("newsletter-preferences") {
    authenticateOAuth2(realm = "Secure site", authenticator) { authInfo =>
      path("frequency" / LongNumber) { custNum =>
        authorize(hasScopes(authInfo)) {
          frequencyPreference(custNum) ~ addFreqPref(custNum)
        }
      } ~ path("pause" / LongNumber) { custNum =>
        authorize(hasScopes(authInfo)) {
          pauseInfo(custNum) ~ addPauseInfo(custNum) ~ unPauseUser(custNum)
        }
      }
    } ~
      path("health") {
        healthRoute()
      }
  }
}

def hasScopes(authInfo: OAuthInfo): Boolean = ???

def authenticator(credentials: Credentials)(
  implicit system: ActorSystem,
  mat: ActorMaterializer): Option[OAuthInfo] = {
credentials match {
  case p @ Credentials.Provided(token) =>
    ???
  case _ => None
}
}
like image 638
deep Avatar asked Oct 29 '22 00:10

deep


1 Answers

This was an error in IntelliJ.
The code runs fine but due to some reason IntelliJ Idea shows error all over it.

like image 55
deep Avatar answered Dec 01 '22 00:12

deep