late-restaurant-53559
11/24/2022, 7:34 PM2.x.x
of the @ory/hydra-client
TypeScript lib (the autogenerated one), for a client credentials flow. e.g. the equivalent of this sort of call:
curl -X POST '<http://localhost:4444/oauth2/token>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--user '${CLIENT_ID}:${CLIENT_SECRET}' \
--data-raw 'grant_type=client_credentials&scope=${SCOPE}'
The above call works, but is this possible to do using the @ory/hydra-client
TypeScript lib?
This method seems closest:
oauth2TokenExchange(
grantType: string,
clientId?: string,
code?: string,
redirectUri?: string,
refreshToken?: string,
options?: any
): AxiosPromise<OAuth2TokenExchange>
But it’s unclear how I’d provide the client secret or scope, if that is the right method to use here.dazzling-vase-23428
11/25/2022, 9:17 AMchilly-balloon-35803
11/25/2022, 9:59 AMoauth2TokenExchange
is indeed the correct function to use in order to receive a token. This function is part of the OAuth2Api class. You have to initiate an OAuth2Api object which needs a Configuration object parameter. In the configuration object, you can set hydra's public URL, username = your client_id and password = your client_secret. After that, you should be able to use the oauth2TokenExchange
function to get a token. 🙂chilly-balloon-35803
11/25/2022, 9:59 AMimport { Configuration } from 'hydra-client.configuration';
import { OAuth2Api } from 'hydra-client.api';
config = Configuration(basePath="HYDRA_PUBLIC_URL", username="your_client_id", passwod="your_client_secret")
client = OAuth2Api(config)
token_response = client.oauth2TokenExchange(grantType="client_credentials")
chilly-balloon-35803
11/25/2022, 10:11 AMlate-restaurant-53559
11/26/2022, 2:54 AM