1
votes

I'm writing an app using Akka Streams and Akka Http which needs to connect to an authenticated web service (which returns an authentication token) and then needs to regularly query the service and potentially perform other actions with it in response to the query (download files etc.). The authentication token times out after a certain amount of time and so will need to be refreshed.

How should I handle the authentication token? It needs to be passed to different Flows in the graph (everywhere I'm querying the service), and when the authentication token becomes invalid I need to request a new one.

One idea would be to do the authentication request outside the stream then pass in the token when materialising the stream so that each flow gets the token as a parameter during materialisation. Then when the token eventually times out the stream will fail and I tear it down and make a new one. I think this would work, but it seems a little clumsy and I'd like to know if there's a way to work entirely with the stream-based world.

One thought I had was that the authentication token could be zipped with the other data flowing through the stream and passed along to each Flow element that needed it. Then if the token fails at some point the stream somehow requests a new one with somekind of feedback flow or a recovery mechanism. But I don't know if this is possible or how to implement it.

Is there a third approach I haven't thought of, or something I've missed in Akka streams or Akka HTTP?

1

1 Answers

1
votes

akka-http is built on akka-streams, so you are already covered on that front. For user session management using akka-http, take a look at akka-http-session. You might also want to read through this excellent post.

You might also take a look at some sample code I recently uploaded, which does not use akka-http-session - available here. Hope some of these materials help.