N
Nuxt5mo ago
oneeach

$fetch with cert & key

I have a non-person entity cert and key and would like to provide those during a $fetch to get a one-off token from an auth-provider. How can I do that? This works for me using a curl command (below) but can't figure out how to do this using $fetch TOKEN=$(curl -L -X POST 'https://ssl-url/realms/realm/protocol/openid-connect/token' \ -H 'Content-Type: application/x-www-form-urlencoded' \ --cert /path/to/certificate.crt \ --key /path/to/key.key \ --data-urlencode 'grant_type=password' \ --data-urlencode 'client_id=scs-npe-authentication' \ --data-urlencode 'scope=openid' | jq '.access_token')
1 Reply
oneeach
oneeachOP5mo ago
I've figured out how to do this using Axios, but would rather use $fetch/ofetch if at all possible. This is how I did it with Axios: const npe_cert = useRuntimeConfig().npeCert; const npe_key = useRuntimeConfig().npeKey; const options = { url: "https://ssl-url/realms/realm/protocol/openid-connect/token", method: "POST", data: "grant_type=password&response_type=token&client_id=client_id", headers: { "Content-Type": "application/x-www-form-urlencoded" }, httpsAgent: new https.Agent({ cert: npe_cert, key: npe_key, }), }; let access_token = ""; // Need to use Axios to supply NPE cert/key into httpAgent to get token await axios(options).then((result) => { access_token = result.data.access_token; });
Want results from more Discord servers?
Add your server