Silhouette is an authentication library for Play Framework applications that supports several authentication methods, including OAuth1, OAuth2, OpenID, Credentials or custom authentication schemes.
akkie on gh-pages
updated site (compare)
akkie on gh-pages
updated site (compare)
akkie on gh-pages
updated site (compare)
akkie on master
Fixed Auth0ProfileParser to get… (compare)
akkie on gh-pages
updated site (compare)
akkie on gh-pages
updated site (compare)
akkie on 7.0.0
akkie on master
Release version 7.0.0 (compare)
akkie on 7.0.0-RC1
RequestHandlerBuilder
protected def handleAuthentication[B](implicit request: Request[B]): Future[(Option[Either[E#A, E#A]], Option[E#I])] = {
environment.authenticatorService.retrieve.flatMap {
// A valid authenticator was found so we retrieve also the identity
case Some(a) if a.isValid => environment.identityService.retrieve(a.loginInfo).map(i => Some(Left(a)) -> i)
@AndreyLadniy I see what you mean.
Maybe other people here can help better, but here are my thoughts.
One idea you could use is to create a custom action that extends SecuredAction and does not require login info... by changing this part in SecuredAction#invokeBlock:
// An authenticator but no user was found. The request will ask for authentication and the authenticator will be discarded
case (Some(authenticator), None, _) =>
In a previous job I used two different setups. Sharing in case it helps.
In one setup, I used Silohuette as a "login/auth server" and then other microservices just validated the JWT tokens using a shared key with the login server. The other servers didn't have sillohuette - they used a scala jwt library to decode and validate the tokens using a custom Play action I created.
In another setup, I wasn't expecting high traffic, so I implemented the "login/auth service" as a REST api and had a sort of proxy that validated every external request against the auth server before redirecting to the destination microservice.
I try implement Bearer token
(as refresh) and JWT
(as access token). So I implement two Environments
. Problem with disabling
I solve = :
IdentityService
override def retrieve(loginInfo: LoginInfo): Future[Option[String]] = {
Future.successful(Some(loginInfo.providerKey))
}
but when I try store JWT in httpOnly secured cookie, I understand something going wrong, so JWTbyCookieAuthenticationService
needed and so on.
I'm already leaning towards the number one solution like yours. The resource server does not need a large Silhouette library.
@akkie the second snippet (without using the type parameter [T]) does compile but it gives an Error. The same error is thrown when using the type parameter [T].
[error] application - ! @7cm23k6mg - Internal server error, for (GET) [/] -> play.api.UnexpectedException: Unexpected exception[CreationException: Unable to create injector, see the following errors: 1) No implementation for scala.reflect.ClassTag<com.mohiva.play.silhouette.api.util.PasswordInfo> was bound. while locating scala.reflect.ClassTag<com.mohiva.play.silhouette.api.util.PasswordInfo> for the 3rd parameter of daos.password.PasswordDAO.<init>(PasswordDAO.scala:18) at modules.SilhouetteModule.configure(SilhouetteModule.scala:78) (via modules: com.google.inject.util.Modules$OverrideModule -> modules.SilhouetteModule)
I have run to the very exact same problem. How did you end up solving it? Do you mind sending a code snippet, please?
class PersistedAuthInfoDAO @Inject() (db: Database)
(implicit executionContext: DatabaseExecutionContext,
implicit val classTag: ClassTag[PasswordInfo])
extends DelegableAuthInfoDAO[PasswordInfo] {
@Provides
def providesAuthInfoDAO(authInfoDAO: PersistedAuthInfoDAO, classTag: ClassTag[PasswordInfo])(
implicit
ex: ExecutionContext): DelegableAuthInfoDAO[PasswordInfo] = {
authInfoDAO
}
@Provides
def providesAuthInfoDAO(db: Database)(
implicit ex: DatabaseExecutionContext): DelegableAuthInfoDAO[PasswordInfo] = {
new PersistedAuthInfoDAO(db)
}