10000 fix: Move request helper function by iamsaumya · Pull Request #2594 · outline/outline · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Move request helper function #2594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 1 addition & 13 deletions server/routes/auth/providers/azure.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// @flow
import passport from "@outlinewiki/koa-passport";
import { Strategy as AzureStrategy } from "@outlinewiki/passport-azure-ad-oauth2";
import fetch from "fetch-with-proxy";
import jwt from "jsonwebtoken";
import Router from "koa-router";
import accountProvisioner from "../../../commands/accountProvisioner";
import env from "../../../env";
import { MicrosoftGraphError } from "../../../errors";
import passportMiddleware from "../../../middlewares/passport";
import { StateStore } from "../../../utils/passport";
import { StateStore, request } from "../../../utils/passport";

const router = new Router();
const providerName = "azure";
Expand All @@ -18,17 +17,6 @@ const AZURE_RESOURCE_APP_ID = process.env.AZURE_RESOURCE_APP_ID;

const scopes = [];

export async function request(endpoint: string, accessToken: string) {
const response = await fetch(endpoint, {
method: "GET",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
});
return response.json();
}

export const config = {
name: "Microsoft",
enabled: !!AZURE_CLIENT_ID,
Expand Down
17 changes: 3 additions & 14 deletions server/routes/auth/providers/oidc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow
import passport from "@outlinewiki/koa-passport";
import fetch from "fetch-with-proxy";
import Router from "koa-router";
import get from "lodash/get";
import { Strategy } from "passport-oauth2";
Expand All @@ -12,7 +11,7 @@ import {
} from "../../../errors";
import passportMiddleware from "../../../middlewares/passport";
import { getAllowedDomains } from "../../../utils/authentication";
import { StateStore } from "../../../utils/passport";
import { StateStore, request } from "../../../utils/passport";

const router = new Router();
const providerName = "oidc";
Expand All @@ -36,18 +35,8 @@ const scopes = OIDC_SCOPES.split(" ");

Strategy.prototype.userProfile = async function (accessToken, done) {
try {
const response = await fetch(OIDC_USERINFO_URI, {
credentials: "same-origin",
headers: {
Authorization: `Bearer ${accessToken}`,
},
});

try {
return done(null, await response.json());
} catch (err) {
return done(err);
}
const response = await request(OIDC_USERINFO_URI, accessToken);
return done(null, response);
} catch (err) {
return done(err);
}
Expand Down
13 changes: 13 additions & 0 deletions server/utils/passport.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import { addMinutes, subMinutes } from "date-fns";
import fetch from "fetch-with-proxy";
import { type Request } from "koa";
import { OAuthStateMismatchError } from "../errors";
import { getCookieDomain } from "./domains";
Expand Down Expand Up @@ -47,3 +48,15 @@ export class StateStore {
callback(null, true);
};
}

export async function request(endpoint: string, accessToken: string) {
const response = await fetch(endpoint, {
method: "GET",
credentials: "same-origin",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json",
},
});
return response.json();
}
0