Skip to content

Commit 73da4f9

Browse files
committed
feat: store used provider n cookies
1 parent 39fa06b commit 73da4f9

File tree

5 files changed

+54
-7
lines changed

5 files changed

+54
-7
lines changed

src/auth/app_auth_login_provider/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ module.exports = async function (context, req) {
2020
domain: "localhost",
2121
SameSite: "None",
2222
},
23+
{
24+
name: "StaticWebAppsAuthCookie__PROVIDER",
25+
value: provider,
26+
path: "/",
27+
secure: false,
28+
HttpOnly: false,
29+
domain: "localhost",
30+
SameSite: "None",
31+
},
2332
],
2433
headers: {
2534
location,

src/auth/app_auth_logout_complete/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ module.exports = async function (context, req) {
2424
domain: "localhost",
2525
expires: new Date(1970),
2626
},
27+
{
28+
name: "StaticWebAppsAuthCookie__PROVIDER",
29+
value: "deleted",
30+
path: "/",
31+
secure: false,
32+
HttpOnly: false,
33+
domain: "localhost",
34+
expires: new Date(1970),
35+
},
2736
],
2837
headers: {
2938
location: SWA_EMU_HOST,

src/userManager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const users = require("./users.json");
2+
const { getProviderFromCookie } = require("./utils");
23

3-
module.exports.currentUser = () => {
4-
return users[0];
4+
module.exports.currentUser = (cookie) => {
5+
const provider = getProviderFromCookie(cookie);
6+
return users[provider] || null;
57
};

src/users.json

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
1-
[
2-
{
1+
{
2+
"github": {
33
"identityProvider": "github",
44
"userId": "59cd31faa8c34919ac22c19af50482b8",
55
"userDetails": "manekinekko",
66
"userRoles": ["anonymous", "authenticated"]
7+
},
8+
"twitter": {
9+
"identityProvider": "twitter",
10+
"userId": "59cd31faa8c34919ac22c19af50482b8",
11+
"userDetails": "manekinekko",
12+
"userRoles": ["anonymous", "authenticated"]
13+
},
14+
"google": {
15+
"identityProvider": "google",
16+
"userId": "59cd31faa8c34919ac22c19af50482b8",
17+
"userDetails": "manekinekko",
18+
"userRoles": ["anonymous", "authenticated"]
19+
},
20+
"facebook": {
21+
"identityProvider": "facebook",
22+
"userId": "59cd31faa8c34919ac22c19af50482b8",
23+
"userDetails": "manekinekko",
24+
"userRoles": ["anonymous", "authenticated"]
25+
},
26+
"aad": {
27+
"identityProvider": "aad",
28+
"userId": "59cd31faa8c34919ac22c19af50482b8",
29+
"userDetails": "manekinekko",
30+
"userRoles": ["anonymous", "authenticated"]
731
}
8-
]
32+
}

src/utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ module.exports.validateCookie = (cookieValue) => {
6666
return false;
6767
};
6868

69+
module.exports.getProviderFromCookie = (cookieValue) => {
70+
const cookies = cookie.parse(cookieValue);
71+
return cookies.StaticWebAppsAuthCookie__PROVIDER;
72+
};
73+
6974
module.exports.ɵɵUseGithubDevToken = async () => {
7075
console.log("!!!! Notice: You are using a dev GitHub token. You should create and use your own!");
7176
console.log("!!!! Read https://docs.github.com/en/developers/apps/building-oauth-apps");
@@ -106,13 +111,11 @@ module.exports.readConfigFile = () => {
106111
api_location = "api",
107112
} = swaBuildConfig.with;
108113

109-
110114
// the following locations must be under the user's project folder
111115
// - app_location
112116
// - api_location
113117
// - app_artifact_location
114118

115-
116119
app_location = path.join(process.cwd(), app_location);
117120
api_location = path.join(process.cwd(), api_location);
118121

0 commit comments

Comments
 (0)