Skip to content

Keycloak Login results in Error: "Unable to exchange external code" #516

@valerius21

Description

@valerius21

Bug report

Describe the bug

After setting up an instance of Keycloak and using current examples with their latest versions, logging in via. the thrid-party-service Keycloak on a local instance results in an error, which message is "Unable to exchange external code", found in the redirect URL.

To Reproduce

  1. Follow the documentation on setting up Keycloak for Supabase, https://supabase.com/docs/guides/auth/auth-keycloak.
  2. Initialize a new project with npx create-next-app --example "https://github.com/valerius21/auth-helpers/tree/main/examples/nextjs"
    1. Enter the corresponding credentials in a .env.local file (NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY)
    2. Change pages/index.tsx:38 from providers={["google", "github"]} to providers={["google", "github", "keycloak"]}
    3. Start the Dev Server with yarn dev
    4. (This Step is also reproducible with the official supabase-js client)
  3. The site at http://localhost:3000 should have three buttons, one of which has no icon inside. image
  4. Click the button and login on to the local Keycloak instance
  5. Redirected back to the authentication form, no session is established and an error code in the URL is present.
http://localhost:3000/?error=server_error&error_description=Unable+to+exchange+external+code%3A+392cabd5-b422-446a-8497-e4f184453157.0887172c-5c95-44a4-944b-d975911a9563.46e8656a-f404-41c8-ab90-baa7ffb0d727

Expected behavior

A user session, similar to other OAuth2 providers, like Google, GitHub, etc., where querying DB content and one's user profile is possible.

Screenshots

supabase_issue.mp4

System information

  • OS: Ubuntu Linux
  • Browser: Chrome, Brave
  • Version of supabase-js: latest
  • Version of Node.js: 16.15.x

Previous attempts to resolve the issue

  • Checking the Keycloak credentials of whitespaces
  • Adding SSL did not resolve the issue
  • Inspecting the supabase instance logs of errors, but only, as intended, finding 302 requests.
  • Using the supabase client in other frameworks and in other contexts to attempt an authentication request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions