fa-fifi / keycloak_wrapper

Keycloak Single Sign-On (SSO) authentication package for Flutter framework.
https://pub.dev/packages/keycloak_wrapper
BSD 3-Clause "New" or "Revised" License
12 stars 11 forks source link

Is it possible to customize the redirectUri? #49

Closed tumluliu closed 1 month ago

tumluliu commented 1 month ago

Hi, thank you for making such a simple and elegant wrapper! I have one question regarding the redirectUri from the KeycloakConfig. It seems that it's hardcoded as a combination of the bundleIdentifier and ://login-callback. But in our case, this redirectUri is a link like https://OUR_BE_HOST/api/auth/callback. So my question is: is it possible to customize this redirectUri?

https://github.com/fa-fifi/keycloak_wrapper/blob/0c58aecd9e3c7f06a234056a173a781549394423/lib/src/config.dart#L42-L51

Thank you again

fa-fifi commented 1 month ago

The reason I hardcoded that redirectUri is because users most probably want to be redirected back to the app once they login. So, may I know why you want to customize the url? As of now, it is not customizable, but I can make it customizable if there is a usecase for that particular feature.

tumluliu commented 1 month ago

@fa-fifi Thanks for your reply. Interesting, I was not aware that the token exchange could also be done from the mobile client side. But anyway, as of now the "code-to-token" exchange action is done in our server-side API by an endpoint like https://OUR_BE_HOST/api/auth/callback which apparently doesn't follow the pattern $bundleIdentifier://login-callback. We need to call this endpoint to get an Authorization access_token in order to call some specific endpoints that only logged-in users can access (imagine sth. like user browsing history, etc.).

I'm open to change the token exchanging from server-side to client-side. Then the question becomes: how to handle this token exchanging with keycloak_wrapper. I haven't seen this part from your example. Could you please provide some further hints? Thanks.

tumluliu commented 1 month ago

am I supposed to use this accessToken?

https://github.com/fa-fifi/keycloak_wrapper/blob/0c58aecd9e3c7f06a234056a173a781549394423/lib/src/wrapper.dart#L34-L37

fa-fifi commented 1 month ago

Yup. Once you logged in, you will receive an accessToken that can be used to access your resources. If you need to customize the url just because you want to get the accessToken, then you should be using the one provided by the package.

Try that first and see if it's working or not.

tumluliu commented 1 month ago

UPDATE: we managed to successfully utilize the accessToken without the necessity to customize the redirectURI. Thanks for your kind support, @fa-fifi !