Redirect user to my app instead of Keycloak, if user won't give access to other IDP

I have added github as idp in keycloak, and in my github oauth app I have added keycloak redirect_uri as callback url.

I am redirecting user to keycloak, which internally redirects user to git hub login page. After login, on consent screen if user gives his consent, then github is redirecting back to keycloak with code in query parameter, which internally redirects back to my callback endpoint.

However, if user doesn’t give his access, then github is redirecting to keycloak with error.

Is there a way I can redirect user back to my application from Keycloak if user denied access.

Unfortunately not. Not out of the box, anyway.

An alternative to that is to set github as the default IDP on your browser authentication flow, so when the github login fails, keycloak login also fails and your application gets a login error which you can them treat and react accordingly.

Check the docs on how to set a default identity provider on Keycloak.