Compare commits

...

1 Commits

Author SHA1 Message Date
Tom Moor 308ca17643 fix: Dropbox OIDC requires POST to userinfo endpoint 2025-01-22 23:06:55 -05:00
4 changed files with 22 additions and 5 deletions
+6 -2
View File
@@ -57,10 +57,14 @@ if (env.AZURE_CLIENT_ID && env.AZURE_CLIENT_SECRET) {
const [profileResponse, organizationResponse] = await Promise.all([
// Load the users profile from the Microsoft Graph API
// https://docs.microsoft.com/en-us/graph/api/resources/users?view=graph-rest-1.0
request(`https://graph.microsoft.com/v1.0/me`, accessToken),
request("GET", `https://graph.microsoft.com/v1.0/me`, accessToken),
// Load the organization profile from the Microsoft Graph API
// https://docs.microsoft.com/en-us/graph/api/organization-get?view=graph-rest-1.0
request(`https://graph.microsoft.com/v1.0/organization`, accessToken),
request(
"GET",
`https://graph.microsoft.com/v1.0/organization`,
accessToken
),
]);
if (!profileResponse) {
+3
View File
@@ -70,6 +70,7 @@ if (env.DISCORD_CLIENT_ID && env.DISCORD_CLIENT_SECRET) {
const client = getClientFromContext(ctx);
/** Fetch the user's profile */
const profile: RESTGetAPICurrentUserResult = await request(
"GET",
"https://discord.com/api/users/@me",
accessToken
);
@@ -105,6 +106,7 @@ if (env.DISCORD_CLIENT_ID && env.DISCORD_CLIENT_SECRET) {
if (env.DISCORD_SERVER_ID) {
/** Fetch the guilds a user is in */
const guilds: RESTGetAPICurrentUserGuildsResult = await request(
"GET",
"https://discord.com/api/users/@me/guilds",
accessToken
);
@@ -146,6 +148,7 @@ if (env.DISCORD_CLIENT_ID && env.DISCORD_CLIENT_SECRET) {
/** Fetch the user's member object in the server for nickname and roles */
const guildMember: RESTGetCurrentUserGuildMemberResult =
await request(
"GET",
`https://discord.com/api/users/@me/guilds/${env.DISCORD_SERVER_ID}/member`,
accessToken
);
+7 -1
View File
@@ -81,8 +81,14 @@ if (
) => void
) {
try {
// Some providers require a POST request to the userinfo endpoint, add them as exceptions here.
const usePostMethod = [
"https://api.dropboxapi.com/2/openid/userinfo",
];
const profile = await request(
env.OIDC_USERINFO_URI ?? "",
usePostMethod.includes(env.OIDC_USERINFO_URI!) ? "POST" : "GET",
env.OIDC_USERINFO_URI!,
accessToken
);
+6 -2
View File
@@ -68,9 +68,13 @@ export class StateStore {
};
}
export async function request(endpoint: string, accessToken: string) {
export async function request(
method: "GET" | "POST",
endpoint: string,
accessToken: string
) {
const response = await fetch(endpoint, {
method: "GET",
method,
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",