I am trying to generate access token and use it as a bearer token. So that i can use it to generate an encrypted url from it. When i click on button i need to reload that encrypted url. I am new to this environment trying to do this but i am not able to generate what i was expected to do.I am not sure if this possible. can anyone help me
My backend code:
import { fetch } from ‘wix-fetch’ ;
// wix-fetch is the API we provide to make https calls in the backend
export function Authentication() {
return fetch( “url” , {
method: ‘POST’ ,
body: JSON.stringify({
‘grant_type’ : ‘client credentials’ ,
‘clientid’ : ‘xxxxxx’ ,
‘client_secret’ : ‘xxxxxxx’ ,
‘scope’ : ‘xxxxxx’ ,
‘client_authentication’ : ‘xxxxxxx’
})
}).then( function (response) {
if (response.status >= 200 && response.status < 300 )
//console.log(response.text());
return response.text();
else
throw new Error(response.statusText);
});
}
I am not sure how to call the backend variable to here.
frontend code:
import { Authentication } from ‘backend/OAuth2.jsw’ ;
import wixLocation from ‘wix-location’ ;
export function button9_click_1(event) {
wixLocation.to(“url”);
let url = “url”;
return fetch(url, {
method: ‘get’ ,
headers: {
“Authorization” : “Bearer xxxxxxxxx”
},
})
.then((httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
}
})
. catch ((err) => {
return err;
});
}