TNG / keycloak-mock

A Java library to test REST endpoints secured by Keycloak via OpenID connect.
Apache License 2.0
120 stars 27 forks source link

Added ability to set token's lifespan for server mode #150

Closed Akvel closed 11 months ago

Akvel commented 1 year ago

Hi,

subj

In some cases we need checks refresh/401 in tests. For this case we need configure exp field for server mode.

Here the little changes that add this funtionality.

ostrya commented 1 year ago

Thanks for the PR. But I wonder: does your use case, i.e. testing if an expired token is rejected, really warrant a server configuration which is applied globally? I would have just added an option to the TokenConfig class to configure the lifespan.

Or do you mean you start the mock as a standalone application? In that case, I'd have added a CLI option to configure the lifespan. Alternatively, you could add another input field to the "login" page.

Akvel commented 1 year ago

Thanks for the PR. But I wonder: does your use case, i.e. testing if an expired token is rejected, really warrant a server configuration which is applied globally? I would have just added an option to the TokenConfig class to configure the lifespan.

Or do you mean you start the mock as a standalone application? In that case, I'd have added a CLI option to configure the lifespan. Alternatively, you could add another input field to the "login" page.

Hello,

In my case, KeycloakMock is set up as a server directly in tests, and it is used to process all authorizations. There are cases when I need to verify the correctness of token refreshing via URL and ensure that the new token is used in all parts. For this, I need the ability to specify the token's lifespan in the ServerConfig.

The application uses Spring oauth2 client to work with Keycloak, which automatically refreshes tokens internally. Therefore, I cannot use TokenConfig and getAccessToken.

ostrya commented 11 months ago

I took the liberty of amending your fix commit so the pre-commit hook check is actually green. Otherwise, since your explanation makes sense, let's just go for it.