Hey gang,
I’m trying to prove a site can be deployed through netlify Rest API/google apps script, as long as there’s oAuth2 working.
So far can’t do it; “Redirect URI doesn’t match application”.
What’s wrong with my code? Searched literally everywhere online.
var CLIENT_ID = 'client id';
var CLIENT_SECRET = 'mysecret';
function run() {
var zipLink = "@https://drive.google.com/uc?export=download&id=1_fOKfBIsandsomeothertext"
var service = getService();
if (service.hasAccess()) {
var url = "https://api.netlify.com/api/v1/sites";
var options = {
'method': 'post',
'muteHttpExceptions': true,
"data-binary": zipLink,
'headers': {
'Authorization': 'Bearer ' + service.getAccessToken(),
"Content-Type": "application/zip"
}
};
var response = UrlFetchApp.fetch(url, options);
var result = JSON.parse(response.getContentText());
Logger.log(JSON.stringify(result, null, 2));
} else {
var authorizationUrl = service.getAuthorizationUrl();
Logger.log('Open the following URL and re-run the script: %s',
authorizationUrl);
}
}
/**
* Reset the authorization state, so that it can be re-tested.
*/
function reset() {
getService().reset();
}
/**
* Configures the service.
*/
function getService() {
return OAuth2.createService('Netlify')
// Set the endpoint URLs.
.setAuthorizationBaseUrl('https://app.netlify.com/authorize')
.setTokenUrl('https://api.netlify.com/auth/done')
// Set the client ID and secret.
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
// Set the name of the callback function that should be invoked to
// complete the OAuth flow.
.setCallbackFunction('authCallback')
// Set the property store where authorized tokens should be persisted.
.setPropertyStore(PropertiesService.getUserProperties())
.setTokenHeaders({
'Authorization': 'Basic ' +
Utilities.base64Encode(CLIENT_ID + ':' + CLIENT_SECRET)
});
}
/**
* Handles the OAuth callback.
*/
function authCallback(request) {
var service = getService();
var authorized = service.handleCallback(request);
if (authorized) {
return HtmlService.createHtmlOutput('Success!');
} else {
return HtmlService.createHtmlOutput('Denied.');
}
}
/**
* Logs the redict URI to register.
*/
function logRedirectUri() {
Logger.log(OAuth2.getRedirectUri());
}