我的喷涂项目中出现了这个错误.
Error:(41, 28) type mismatch;
found : spray.routing.authentication.ContextAuthenticator[co.s4n.authentication.entities.Usuario]
(which expands to) spray.routing.RequestContext => scala.concurrent.Future[scala.util.Either[spray.routing.Rejection,co.s4n.authentication.entities.Usuario]]
required: spray.routing.directives.AuthMagnet[?]
authenticate(validateToken) {
^
Run Code Online (Sandbox Code Playgroud)
这是我的TokenValidator特征
trait TokenValidator {
def validateToken: ContextAuthenticator[Usuario] = {
ctx =>
val header = ctx.request.headers.find(_.name == "Access_Token")
if (header isDefined) {
doAuth(header.get)
}
else {
Future(Left(AuthenticationFailedRejection(AuthenticationFailedRejection.CredentialsMissing, List())))
}
}
def doAuth(header: HttpHeader): Future[Authentication[Usuario]] = {
Dao.validateToken(header.value).map {
case Some(usuario) => Right(usuario)
case None => Left(AuthenticationFailedRejection(AuthenticationFailedRejection.CredentialsRejected, List()))
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我遇到错误的地方
//@DELETE
//localhost:9090/authenticacion/users/{{userEmail}}
val `users/{{email}}` =
pathPrefix(`path-prefix`) {
pathPrefix(`users-path-prefix` / Segment) {
emailRef => {
delete {
authenticate(validateToken) { **HERE!!!!**
usuario =>
.....
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
有谁知道我做错了什么?
祝你们一切顺利!
Rod*_*mez 11
我唯一缺少的是ExecutionContext在范围内并且import ExecutionContext.Implicits.global工作正常.
这是让Futures工作,因为他们声明一个隐含的ExecutionContext参数.
| 归档时间: |
|
| 查看次数: |
1321 次 |
| 最近记录: |