softwaremill/akka-http-session

Redirect unauthenticated request

dave-kav opened this issue · 1 comments

Hi guys,

I'm wondering whether there is any existing directive that allows a request to be re-directed if the request is made to an un-authenticated user to a secured endpoint.

I am using this in a web console, and currently I am seeing:

The supplied authentication is not authorized to access this resource

It would be more useful however to redirect the request to a login page. Is this possible at the minute, am I just missing something? I haven't been able to find anything in the main docs or the faqs.

adamw commented

You should be able to use the session directive (https://github.com/softwaremill/akka-http-session/blob/master/core/src/main/scala/com/softwaremill/session/SessionDirectives.scala#L31), which gives you a SessionResult, and matching on that value check if there's is a session or not, and dynamically choose the "next" directive (see https://github.com/softwaremill/akka-http-session/blob/master/core/src/main/scala/com/softwaremill/session/SessionManager.scala#L181)