使用GenericHttpCredentials从http请求标头中提取令牌

时间:2017-12-19 15:14:55

标签: scala akka akka-http

我正在尝试从HTTP请求的授权标头中提取令牌。授权标头的格式为Authorization: Token token=abcdefg123。我想有以下函数签名但是当我尝试下面的代码片段时,编译错误是Cannot resolve symbol Map. Cannot resolve method Map.unapply。我不确定为什么会这样。任何帮助表示赞赏。

def extractToken(request: HttpRequest): Option[String] = {
  for {
    Authorization(GenericHttpCredentials("Token", "", Map("token"->token))) 
       <- request.header[Authorization]
  } yield token
}

1 个答案:

答案 0 :(得分:0)

找出一个工作函数,

private def extractToken(request: HttpRequest): Option[String] = {
  for {
    Authorization(GenericHttpCredentials("Token", "", params)) <- request.header[Authorization]
    token <- params.get("token")
  } yield token
}