Skip to content

Instantly share code, notes, and snippets.

@pforret
Last active October 12, 2022 13:55
Show Gist options
  • Save pforret/7c0ef92228cab2dcf65ede1c73e23be2 to your computer and use it in GitHub Desktop.
Save pforret/7c0ef92228cab2dcf65ede1c73e23be2 to your computer and use it in GitHub Desktop.
checklyhq snippet to get a JWT token with client_id/client_secret
const axios = require('axios');
// get your secrets from Environment Variables
const email = process.env.SERVICE_CLIENT_ID
const password = process.env.SERVICE_CLIENT_SECRET
const url = process.env.SERVICE_LOGIN_URL
const scope = process.env.SERVICE_CLIENT_SCOPE
var token = "";
var config = {
method: 'post',
url: url,
headers: {
'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'application/x-www-form-urlencoded'
},
data: JSON.stringify({
'grant_type': 'client_credentials',
'client_id': email,
"client_secret": password,
'scope': scope})
};
await axios(config)
.then(function (response) {
token = response.data.access_token;
})
.catch(function (error) {
console.log(error);
});
request.headers['Authorization'] = `Bearer ${token}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment