Pass custom values after auth redirect

Hello.
For example this is my url for user login page:
http://keycloak.loc:8090/auth/realms/demo/protocol/openid-connect/auth?response_type=code&client_id=Android-product&redirect_uri=http://localhost:8080

I’d like to add some custom values, for example (just add one query paramter)

http://keycloak.loc:8090/auth/realms/demo/protocol/openid-connect/auth?response_type=code&client_id=Android-product&redirect_uri=http://localhost:8080&key=val

Can later I obtain this value (key=val)?
After success login I got redirect to:

http://localhost:8080/?session_state=47174ec8-c363-4db9-b291-804db2bca77f&code=8e88a5cf-ba65-4f35-b88a-a764e3088824.47174ec8-c363-4db9-b291-804db2bca77f.3c187c21-3cf1-4b8c-bdca-9c3be4b812c9

code is valid - with this code I can obtain tokens (access, refresh etc).
But how can I (is it possible) to obtain my custom vars?

Your approach is correct, but you need to urlencode the redirect_uri:

http://localhost:8080&key=val

should be

http%3A%2F%2Flocalhost%3A8080%26key%3Dval

And after encode I will receive my custom values in URL after redirect?

http://keycloak.loc:8090/auth/realms/demo/protocol/openid-connect/auth?response_type=code&client_id=Android-product&redirect_uri=http%3A%2F%2Flocalhost%3A8080%26key%3Dval

I got Invalid parameter: redirect_uri error

How are your “Valid Redirect URIs” specified in the Client? If you only have http://localhost:8080, it will give you that error. If you have http://localhost:8080/*, it will work properly.

Now it works thanks!
BTW maybe you could know. Can I update user’s email with login form?
Example:
Some user have an account, then the user wants to update his email with oauth2 (via github, google etc)/
Is it possible?

Users can change their email in the account UI if you are using the keycloak javascript you can get the url for that by doing keycloak.accountManagement()

No, I want to update user’s email for already registered in KeyCloak user with external identity providers.
For example:

  1. User registered by common registration form (with email, password etc).
  2. Then this user decided to update his email with github, google etc