0
我无法处理作用域(访问级别,OAuth2)和Scala。 我想要有这些用例:具有play2 scala-oauth2提供程序的全局作用scala
- 定义了控制器的全局范围。能够为某些操作覆盖此全局参数。
- 没有定义一个全局参数,但指定每个动作的范围
这个代码是我想要的一个例子:
package controllers
import scalaoauth2.provider.OAuth2Provider
import scala.concurrent.ExecutionContext.Implicits.global
class MyController extends GlobalAuthController
// define global scope
implicit val scope = Scope.User
// By default, if no parameter, the scope is the implicit value previously defined
def user = ActionWithAuth { request =>
Ok("hello user or admin")
}
def admin = ActionWithAuth(Scope.Admin) {
Ok("hello admin")
}
}
我用nulab/scala-oauth2-provider
库。根据该文档,我创造了这个:
trait OAuth2ActionComposition {
implicit val executionContext: ExecutionContext
def ActionWithAuth[U](implicit scope: Scope): ActionBuilder[({type λ[A] = AuthInfoRequest[A, User]})#λ] = {
Logger.info("Scope : " + scope.toString)
AuthorizedActionFunction(new Users(scope)) compose Action
}
}
object OAuth2ActionComposition extends OAuth2ActionComposition {
implicit val executionContext: ExecutionContext = play.api.libs.concurrent.Execution.defaultContext
}
但与代码我得到一个编译错误:在一行缺少参数类型def user = ActionWithAuth { request =>
see this image
当我明确地传递隐含参数它的工作原理(如def user = ActionWithAuth(scope) { request =>
)。 WTF!但它不方便。
我不明白为什么会出现此错误。我尝试过其他方法,但没有成功。
欢迎堆栈溢出虽然这种联系可以回答这个问题,最好是在这里包括答案的基本部分,并提供链接以供参考,链接的答案可能会失效,如果链接的页面发生变化,请参阅本文:[如何编写一个好答案](http:// stackoverflow .com/help/how-to-answer) – ByteHamster
好的,我明白了,我会尽力更新我的答案以匹配所需的内容。事实上,我的回答并不是我问的问题的直接答案。这更多是一种解决方法。这就是我为什么这样回答的原因。 – Dnomyar