Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions site/docs/getting-started/azureAuthorize.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,51 @@
import React from "react";

export const AzureAuthorizeComponent = () => {
const ourAppId = "42cb0c6c-dab0-411f-9c21-16d5a2b1b025";
const redirectUri = "https://eyrcnmuzzyriypdajwdk.supabase.co/functions/v1/azure-dpc-oauth";
const resourceId = "https://storage.azure.com";
const SETTINGS = {
appId: "42cb0c6c-dab0-411f-9c21-16d5a2b1b025",
redirectUri: "https://eyrcnmuzzyriypdajwdk.supabase.co/functions/v1/azure-dpc-oauth",
resourceId: 'https://storage.azure.com',
responseType: 'code',
stateKey: 'state',
storageKey: 'docs_est:azure_oauth_state'
}

const generateAuthorizeUrl = (theirTenant) => {
const state = crypto.randomUUID()
sessionStorage.setItem(SETTINGS.storageKey, state);
Comment on lines +13 to +14
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the MAJOR update here. We need to store this off and validate it down below.


const generateAuthorizeUrl = (theirTenant) =>
`https://login.microsoftonline.com/${theirTenant}/oauth2/authorize?client_id=${ourAppId}&response_type=code&redirect_uri=${encodeURIComponent(
redirectUri
)}&resource_id=${encodeURIComponent(resourceId)}`;
const params = new URLSearchParams({
client_id: SETTINGS.appId,
redirect_uri: SETTINGS.redirectUri,
resource_id: SETTINGS.resourceId,
response_type: SETTINGS.responseType,
[SETTINGS.stateKey]: state,
});
Comment on lines +16 to +22
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting up the params in this way should handle escaping for us.


return `https://login.microsoftonline.com/${encodeURIComponent(theirTenant)}/oauth2/authorize?${params}`
};

export const AzureAuthorizeComponent = () => {
const [tenant, setTenant] = React.useState("");

// Try to get the auth code but first ensure the states match
// if there is an issue this will fail silently (Q4 2025)
const authCode = React.useMemo(() => {
return new URLSearchParams(window.location.search.slice(1)).get("code");
const params = new URLSearchParams(window.location.search);
const code = params.get(SETTINGS.responseType);
const returnedState = params.get(SETTINGS.stateKey);
const storedState = sessionStorage.getItem(SETTINGS.storageKey);

if (code) {
sessionStorage.removeItem(SETTINGS.storageKey);

if (!returnedState || !storedState || returnedState !== storedState) {
return null;
}

return code;
}

return null;
}, []);

if (authCode) {
Expand Down
Loading