How to get a GitHub OAuth 2.0 access token using Keycloak Token Management API

Hello Keycloak community,

I am trying to get a GitHub OAuth 2.0 access token using the Keycloak Token Management API, but I am having some difficulties.

I have followed the documentation and set up an identity provider for GitHub in Keycloak, and I am able to successfully authenticate users with their GitHub accounts. However, I am not sure how to use the Keycloak Token Management API to get a GitHub access token that I can use to access the GitHub API on behalf of the authenticated user.

I have tried using the “urn:ietf:params:oauth:grant-type:token-exchange” grant type and specifying “https://api.github.com” as the “resource” in my request for a delegated access token, but I get an error saying “Feature not enabled”.

Could someone please help me understand how to use the Keycloak Token Management API to get a GitHub access token?

Thank you in advance for any help you can provide!

Documentation on retrieving external IDP tokens is here:
https://www.keycloak.org/docs/latest/server_development/index.html#retrieving-external-idp-tokens