加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 08:46:14 所属栏目:安全 来源:网络整理
导读:您有使用Akka-Http开发的服务.我必须添加OAuth,根据 documentation,我使用authenticateOAuth2. 但是代码没有编译并给出错误 Type mismatch,expected: (L) = server.Route,actual: (OauthInfo) = server.Route 我无法找到解决此问题的正确解决方案.我甚至尝试
您有使用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在其中显示错误.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读