Простой оператор return можно использовать перед this.postData, и вы отправите токен в обещании.
let url = window.location.href;
const token = {
authorization(url){
authentication_code = url.split("?")[1].split("&")[1].split("=")[1];
return this.postData("https://www.strava.com/oauth/token?grant_type=authorization_code&client_id=3035dd7&client_secret=3db4fddd039117f8029b406fe72669a4472594bfb6b&code=" + authentication_code)
.then(data => data.access_token) // JSON-string from `response.json()` call
.catch(error => console.error(error));
},
postData(url = "") {
return fetch(url, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
})
.then(response => response.json()); // parses response to JSON
}
};
и при вызове вы получите обещание взамен с токеном, поэтому
token.authorization(url).then(tokenFromResponse=>console.log(tokenFromResponse));
Теперь вы можете использовать токен по желанию.