Last active
August 6, 2020 08:23
-
-
Save Frenchcooc/6231b860805b3432aa54b1586b0d283f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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