scala – 无法使用Akka-Http验证OAuth2

您有使用Akka-Http开发的服务.我必须添加OAuth,根据
documentation,我使用authenticateOAuth2.

但是代码没有编译并给出错误

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

我无法找到解决此问题的正确解决方案.我甚至尝试了文档中example中提到的确切代码,但它仍然会引发类似的编译时错误.

我正在使用带圆圈的akka​​-http.

这是我的代码:

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
}
}

最佳答案 这是IntelliJ中的错误.

代码运行正常但由于某些原因,IntelliJ Idea在其中显示错误.

点赞