好的,我在这里分享我的发现,希望这可以帮助其他人。在深入研究剪影代码时,我发现我们可以轻松地配置我们要从请求的哪个部分(标头、查询字符串……)读取令牌。默认情况下,jwt 令牌是从X-Auth-Token
标头中读取的,但我们可以将其配置为也从查询字符串变量JWTAuthenticator
中读取令牌:
val config =
configuration.underlying
.as[JWTAuthenticatorSettings]("silhouette.authenticator")
// this is the important line of code
.copy(requestParts = Some(Seq(RequestPart.Headers, RequestPart.QueryString)))
new JWTAuthenticatorService(config, None, encoder, idGenerator, clock)
现在,如果您想在带有 a 的控制器后面使用受保护的资产,silhouette.SecureAction
那么您只需将X-Auth-Token
as 查询字符串参数添加到 url:
.my-class {
background-image: url("/image?X-Auth-Token=........")
}