Is it possible to use Silhouette without database in Play?


#1

Hi community,

I am developing a web app and the current requirement is to implement user log in/out (authenticate credentials by external service, no register needed), but the strange thing is that there’s no DB and I’m not allowed to deploy DB. So I wonder could I use Silhouette under such condition?

Thanks.


#2

Hi,

Yes, if you use a social authentication method, then you need no database. You can store the access token returned from the provider, but this is not needed.

Best regards,
Christian


#3

Hi Christian,

Sorry for my ambiguity.
It’s technically not a social authentication, I can only use the service to see if the user/password works and nothing else. Under this condition, may I still use Silhouette?

Thanks.


#4

Sure, there are two possibilities. Either you could implement your own authentication provider which checks against your API or you use the credentials provider if you need password hashing on the Silhouette side. In this case the AuthInfoRepository, which you must pass to the CredentialsProvider, can make the API requests for you.


#5

Hi Zanecat,

Look here: https://github.com/mohiva/play-silhouette-seed/blob/8fd4beb05182da27f3cd385a1945e20f63df3c54/app/controllers/SocialAuthController.scala
— you can replace the handle-auth-results code with your own, and do anything you want. This line:
silhouette.env.eventBus.publish(LoginEvent(user, request))

Hmm and maybe you need to replace this:   userService.save(profile)
with something else too.

I’ve done that, look here: https://github.com/debiki/ed-server/blob/3fb14b27155bc5d390843550d1a5d759fd6fa9c4/app/controllers/LoginWithOpenAuthController.scala#L169 (I eventually do write something to a database though, but that’s me doing it with my own code, not any Silhouette built-in stuff.) — that line (L169) gets the open-auth login result, and does “whatever I want”. That’s Silhouette 4.0 and Play 2.5 though; I’m upgrading right now … trying …

B.t.w. cool username, i.e. zanecat :- ) Gives me many ideas of other new usernames :- )


#6

LOL, thanks very much and with pleasure that my name brought you ideas.