Skip to content

Commit b551c01

Browse files
committed
first commit
0 parents  commit b551c01

15 files changed

Lines changed: 327 additions & 0 deletions

File tree

backend/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MICROSOFT_CLIENT_ID=
2+
MICROSOFT_CLIENT_SECRET=

backend/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "backend",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "main.js",
6+
"type": "module",
7+
"scripts": {
8+
"dev": "nodemon ./src/main.js"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"dotenv": "^16.0.2",
15+
"express": "^4.18.1",
16+
"nodemon": "^2.0.20",
17+
"passport": "^0.6.0",
18+
"passport-microsoft": "^1.0.0"
19+
}
20+
}

backend/src/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import express from "express";
2+
import { loginRouter } from "./routes/microsoft.js";
3+
import passport from "passport";
4+
import "./middlewares/microsoft.js";
5+
6+
const app = express();
7+
8+
app.use(passport.initialize());
9+
10+
app.use("/auth", loginRouter);
11+
12+
app.listen(3000, () => console.log("http://localhost:3000"));
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import passport from "passport";
2+
import { Strategy as MicrosoftStrategy } from "passport-microsoft";
3+
import { config } from "dotenv";
4+
5+
config();
6+
7+
passport.use(
8+
"auth-microsoft",
9+
new MicrosoftStrategy(
10+
{
11+
clientID: process.env.MICROSOFT_CLIENT_ID,
12+
clientSecret: process.env.MICROSOFT_CLIENT_SECRET,
13+
callbackURL: "http://localhost:3000/auth/microsoft/callback",
14+
scope: ["user.read", "calendars.read", "mail.read", "offline_access"],
15+
authorizationURL:
16+
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize",
17+
tokenURL: "https://login.microsoftonline.com/common/oauth2/v2.0/token",
18+
},
19+
function (accessToken, refreshToken, profile, done) {
20+
done(null, profile);
21+
}
22+
)
23+
);

backend/src/routes/microsoft.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Router } from "express";
2+
import passport from "passport";
3+
4+
const loginRouter = Router();
5+
6+
loginRouter.get(
7+
"/microsoft",
8+
passport.authenticate("auth-microsoft", {
9+
prompt: "select_account",
10+
session: false,
11+
})
12+
);
13+
14+
loginRouter.get(
15+
"/microsoft/callback",
16+
passport.authenticate("auth-microsoft", {
17+
failureRedirect: "/auth/microsoft",
18+
session: false,
19+
}),
20+
(req, res) => {
21+
const userString = JSON.stringify(req.user)
22+
res.send(`<!DOCTYPE html>
23+
<html lang="en">
24+
<body>
25+
</body>
26+
<script>
27+
window.opener.postMessage(${userString}, 'http://localhost:5000')
28+
</script>
29+
</html>`)
30+
}
31+
);
32+
33+
export { loginRouter };

frontend/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

frontend/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.jsx"></script>
12+
</body>
13+
</html>

frontend/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "frontend",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite --port 5000",
8+
"build": "vite build",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
"react": "^18.2.0",
13+
"react-dom": "^18.2.0"
14+
},
15+
"devDependencies": {
16+
"@types/react": "^18.0.17",
17+
"@types/react-dom": "^18.0.6",
18+
"@vitejs/plugin-react": "^2.1.0",
19+
"vite": "^3.1.0"
20+
}
21+
}

frontend/public/vite.svg

Lines changed: 1 addition & 0 deletions
Loading

frontend/src/App.css

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#root {
2+
max-width: 1280px;
3+
margin: 0 auto;
4+
padding: 2rem;
5+
text-align: center;
6+
}
7+
8+
.logo {
9+
height: 6em;
10+
padding: 1.5em;
11+
will-change: filter;
12+
}
13+
.logo:hover {
14+
filter: drop-shadow(0 0 2em #646cffaa);
15+
}
16+
.logo.react:hover {
17+
filter: drop-shadow(0 0 2em #61dafbaa);
18+
}
19+
20+
@keyframes logo-spin {
21+
from {
22+
transform: rotate(0deg);
23+
}
24+
to {
25+
transform: rotate(360deg);
26+
}
27+
}
28+
29+
@media (prefers-reduced-motion: no-preference) {
30+
a:nth-of-type(2) .logo {
31+
animation: logo-spin infinite 20s linear;
32+
}
33+
}
34+
35+
.card {
36+
padding: 2em;
37+
}
38+
39+
.read-the-docs {
40+
color: #888;
41+
}

0 commit comments

Comments
 (0)