Skip to content

Instantly share code, notes, and snippets.

@Frenchcooc
Last active August 6, 2020 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Frenchcooc/6231b860805b3432aa54b1586b0d283f to your computer and use it in GitHub Desktop.
Save Frenchcooc/6231b860805b3432aa54b1586b0d283f to your computer and use it in GitHub Desktop.
const axios = require("axios");
const authId = "aa4041d0-xxx-xxx-xxxxxx-xxxxxx";
const setupId = "45f63608-xxx-xxx-xxxxxx-xxxxxx";
const authUrl = `https://auth.bearer.sh/apis/typeform/auth/${authId}`;
const pizzlySecretKey = 'secure-secret-key'
const pizzlyAuthenticationHeader = 'Basic ' + Buffer.from(pizzlySecretKey + ':').toString('base64')
axios
.get(authUrl, { headers: { Authorization: "sk_development_xxxxxxxx" } })
.then(({ data }) => {
if (data.error) {
return;
}
const newPayload = {
connectParams: {},
setupId: setupId,
serviceName: "typeform",
userId: authId,
updatedAt: Date.parse(data.tokenResponse.headers.date),
accessToken: data.tokenResponse.body.access_token,
refreshToken: data.tokenResponse.body.refresh_token || null,
idToken: "non",
expiresIn: data.tokenResponse.body.expires_in,
tokenResponseJSON: data.tokenResponse,
callbackParamsJSON: data.callbackParams,
};
const newAuthUrl = `http://localhost:8080/api/typeform/authentications/${authId}`;
const newData = { setup_id: setupId, payload: newPayload, auth_id: authId };
axios
.put(newAuthUrl, newData, { headers: { Authorization: pizzlyAuthenticationHeader } })
.then(({ data }) => console.log(data))
.catch(({ response }) => console.error(response.data));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment