Hello,
would you recommend the authentication code flow or the password credentials flow, when you're writing a RESTful Server-API, which should be processed by a simple HTTPClient in any programming language or even curl? It's for a storage system, so that I assume the resource owner flow is the one to use. I assume for my use case where the resource owner uses my temporal storage system (the RESTful Server-API) it's even safe. The users usually are in control of both my storage system and Keycloak and their programs should just make some API-calls to retrieve the data they need in their applications (via HTTP for now).
Even though I built a simple working Web-Client for the whole authentication code flow with Vert.x, too (just for integration tests for now, and still pretty ugly with the callback hell until I figure out how to start a coroutine in a test-method).
However, I just tried to simply switch the server (which is the client in terms of OAuth2) to the password credentials flow:
route().handler(CookieHandler.create())
route().handler(BodyHandler.create())
route().handler(SessionHandler.create(LocalSessionStore.create(vertx)))
val oauth2 = KeycloakAuth.discoverAwait(
vertx,
OAuth2ClientOptions()
.setFlow(OAuth2FlowType.PASSWORD)
.setSite("http://localhost:8080/auth/realms/master")
.setClientID("sirix")
.setClientSecret("c8b9b4ed-67bb-47d9-bd73-a3babc470b2c"))
route().handler(UserSessionHandler.create(oauth2))
//val oauth2 = KeycloakAuth.create(vertx, OAuth2FlowType.AUTH_CODE, keycloakJson)
val oauth2Handler = OAuth2AuthHandler.create(oauth2)
oauth2Handler.setupCallback(get("/callback"))
// Create.
put("/:database").handler(oauth2Handler).coroutineHandler { Create(location).handle(it) }
And I'm getting the exception (stacktrace):
Could not start application.
java.lang.IllegalArgumentException: OAuth2Auth + Bearer Auth requires OAuth2 AUTH_CODE flow
at io.vertx.ext.web.handler.impl.OAuth2AuthHandlerImpl.verifyProvider(OAuth2AuthHandlerImpl.java:60)
at io.vertx.ext.web.handler.impl.OAuth2AuthHandlerImpl.<init>(OAuth2AuthHandlerImpl.java:77)
at io.vertx.ext.web.handler.OAuth2AuthHandler.create(OAuth2AuthHandler.java:54)
at org.sirix.rest.SirixVerticle.createRouter(SirixVerticle.kt:63)
What would I need to change, and would you change at all?