-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AuthenticationClient methods imply Async #14
Comments
@mfulgo Thanks! this is a great place for that discussion. This thought had crossed my mind, but I wasn't sure how developers would prefer to consume it. My preference would be returning Neither of these options require the method to be async, it all depends on how the method is called. This lib could be used in a CLI or a webapp. What type of application were you thinking about using this lib with? Great feed back, thanks! |
@bdemers Perfect. So, in my particular use case, I'm implementing a proxy/broker. For me, the problem with the handler is that it actually gets in the way of returning a response, but a void return would be worse. var response: AuthenticationResponse = null
val handler = new AuthenticationStateHandlerAdapter {
override def handleUnknown(authResp: AuthenticationResponse) = {
response = tweakAuthResponse(authResp)
}
}
client.authenticate(user, pass, relayState) // Assuming it returns void
ok(response) However, if it returns the val authResp = client.authenticate(user, pass, relayState)
val response = tweakAuthResponse(authResp)
ok(response)
// Or just...
ok(tweakAuthResponse(client.authenticate(user, pass, relayState))) This gets a little more complicated when dealing with Futures and thread pools, but I think the second approach gives you more control over that as well. (i.e. What context is executing the http request vs handling the response. If the client methods take in the handler, the only option is to have the client thread execute the handler methods.) |
Thanks @mfulgo great examples and points! I'll chew this over a bit more. |
The method signatures on the
AuthenticationClient
seem a bit conflicting to me: The methods both return theAuthenticationResponse
as well as feeding that value to theAuthenticationStateHandler
before returning. Typically, when passing in a handler such as this, I'd expect the method to be asynchronous and to return void.What I'd propose is to restructure it a bit so a) the methods do not take the handler and b) the case logic lives in the handler or a separate class.
Perhaps there's a reason for this approach, but I didn't find one in the commit history. If there's a better place to have this discussion, please feel free to redirect me and close this.
The text was updated successfully, but these errors were encountered: