Skip to content
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

Add logging and uses AAD 2.0 #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions api/GetRoles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = async function (context, req) {
const roles = [];

for (const [role, groupId] of Object.entries(roleGroupMappings)) {
if (await isUserInGroup(groupId, user.accessToken)) {
if (await isUserInGroup(groupId, user.accessToken, context)) {
roles.push(role);
}
}
Expand All @@ -21,7 +21,7 @@ module.exports = async function (context, req) {
});
}

async function isUserInGroup(groupId, bearerToken) {
async function isUserInGroup(groupId, bearerToken, context) {
const url = new URL('https://graph.microsoft.com/v1.0/me/memberOf');
url.searchParams.append('$filter', `id eq '${groupId}'`);
const response = await fetch(url, {
Expand All @@ -32,6 +32,8 @@ async function isUserInGroup(groupId, bearerToken) {
});

if (response.status !== 200) {
const responsebody = await response.json();
context.log.error('Failed to query graph.microsoft.com with http status code', response.status, 'and message:', JSON.stringify(responsebody.error.message));
return false;
}

Expand Down
5 changes: 2 additions & 3 deletions frontend/staticwebapp.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
"rolesSource": "/api/GetRoles",
"identityProviders": {
"azureActiveDirectory": {
"userDetailsClaim": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
"registration": {
"openIdIssuer": "https://login.microsoftonline.com/<YOUR_AAD_TENANT_ID>",
"openIdIssuer": "https://login.microsoftonline.com/<YOUR_AAD_TENANT_ID>/v2.0",
"clientIdSettingName": "AAD_CLIENT_ID",
"clientSecretSettingName": "AAD_CLIENT_SECRET"
},
"login": {
"loginParameters": [
"resource=https://graph.microsoft.com"
"scope=openid+profile+email+user.read"
Copy link

Choose a reason for hiding this comment

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

This is not needed as this is required by default for v2 with OIDC tokens.

]
}
}
Expand Down