Team_Website/Pages/Callback.html
2024-05-10 15:59:36 -07:00

43 lines
1.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Authorization Callback</title>
<script>
// Parse the authorization code from the URL
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
// Exchange the authorization code for an access token
fetch('https://login.microsoftonline.com/common/oauth2/v2.0/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams({
'client_id': 'c91a3691-c800-4aed-9e85-1a2c896327de',
'scope': 'Files.ReadWrite.All',
'code': code,
'redirect_uri': 'http://localhost:5500/Pages/upload.html',
'grant_type': 'authorization_code',
'client_secret': 'ddba6e4e-62b1-4a13-b165-08b00ef6723f'
})
})
.then(response => response.json())
.then(data => {
// Save the access token and optionally the refresh token
const accessToken = data.access_token;
const refreshToken = data.refresh_token;
// Use the access token to make API requests
console.log('Access Token:', accessToken);
console.log('Refresh Token:', refreshToken);
})
.catch(error => console.error('Error:', error));
</script>
</head>
<body>
<p>Authorization successful. You can close this window.</p>
</body>
</html>