I have developed a javascript program (html file) which accesses my dropbox app files. It works fine with a short term access code when I am logged into my dropbox account. I need to generate on demand short term access codes when other users access the html file.
Below is a function that I am using to try to generate on demand short term access code :
function app_authorization2() {
const CLIENT_ID = app_key;
const REDIRECT_URI = redirect_uri;
// Generate PKCE values for security
function generateCodeVerifier() {
const array = new Uint32Array(56);
window.crypto.getRandomValues(array);
return Array.from(array, dec => ('0' + dec.toString(16)).substr(-2)).join('');
}
async function gererateCodeChallenge(verifier) {
const encoder = new TextEncoder();
const data = encoder.encode(verifier);
const digest = await window.crypto.subtle.digest('SHA-256', data);
return btoa(String.fromCharCode.apply(null, new Uint8Array(digest)))
.replace(/+/g, '-').replace(///g, '-').replace(/=+$/, '');
}
// Redirect the user to Dropbox
async function initiateDropboxLogin() {
const verifier = generateCodeVerifier();
localStorage.setItem('dropbox_verifier', verifier);
const challenge = await gererateCodeChallenge(verifier);
const dbx = new Dropbox.Dropbox({ clientId: CLIENT_ID });
const authUrl = await dbx.auth.getAuthenticationUrl (
REDIRECT_URI, // redirectUri
null, // state'code', // authType
'offline', // tokenAccessType
['files.content.write', 'files.content.read'], // scope
'none', // includeGrantedScopes
challenge,
true // usePKCE
);
window.location.href = authUrl;
console.log("Authorization URL Properties - ", authUrl);}
initiateDropboxLogin();
Access_Code = authUrl.code;
console.log("Access Code - ", Access_Code);
return Access_Code;
}
When I run it it gives me the following screens :
The final screen is :
The redirect uri is :
const redirect_uri = 'http://localhost:3000/auth';
I am not sure if this is the correct uri I should be using. As you can see I get a authorization code, but need to get to the next step and get an access token.
Any help would be greatly appreciated, thanks.