由于错误的隐式参数,删除 auth 信息失败

Removal of auth info fails due to bad implicit parameter

我正在使用 Silhouette 来管理我的 Play 应用程序中的身份验证。注册、登录和授权工作正常。但是,当尝试注销(=删除)用户帐户时,相应的授权信息删除失败。

特别是以下行抛出异常:

authInfoRepository.remove(LoginInfo(credentialsProvider.id, username))

(authInfoRepository是一个注入的AuthInfoRepository,配置为DelegableAuthInfoRepository)

异常:

com.mohiva.play.silhouette.api.exceptions.ConfigurationException: Cannot remove auth info of type: class scala.runtime.Nothing$; Please configure the DAO for this type
at com.mohiva.play.silhouette.persistence.repositories.DelegableAuthInfoRepository.remove(DelegableAuthInfoRepository.scala:115)
[...]

查看有问题的方法,它需要一个隐式参数 implicit tag: ClassTag[T]。那个不知何故最终变成了 Nothing,这在我看来是错误的,但我不完全理解发生了什么,或者预期会发生什么。

Why is the implicit ClassTag parameter even relevant?

ClassTag 是相关的,因为 remove 期望这样的隐式:https://github.com/mohiva/play-silhouette/blob/master/silhouette-persistence/src/main/scala/com/mohiva/play/silhouette/persistence/repositories/DelegableAuthInfoRepository.scala#L104-L118

Do I need to manually put a ClassTag object into the right context to avoid Nothing to be inferred?

我想反之亦然,你应该指定 T(没有这样指定,T 现在被推断为 Nothing)并且会找到适当的隐式。

尝试以下选项之一:

authInfoRepository.remove[CasInfo](LoginInfo(credentialsProvider.id, username))
authInfoRepository.remove[OAuth1Info](LoginInfo(credentialsProvider.id, username))
authInfoRepository.remove[OAuth2Info](LoginInfo(credentialsProvider.id, username))
authInfoRepository.remove[OpenIDInfo](LoginInfo(credentialsProvider.id, username))
authInfoRepository.remove[PasswordInfo](LoginInfo(credentialsProvider.id, username))