Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = ({env}) => ({
AZUREAD_OAUTH_CLIENT_ID: '[Client ID created in AzureAD]', // [Application (client) ID]
AZUREAD_OAUTH_CLIENT_SECRET: '[Client Secret created in AzureAD]',
AZUREAD_SCOPE: 'user.read', // https://learn.microsoft.com/en-us/graph/permissions-reference
AZUREAD_OAUTH_USE_OIDC: 'true', //
}
}
})
Expand Down
2 changes: 2 additions & 0 deletions docs/en/azuread/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This document provides instructions for integrating AzureAD as a Single Sign-On
| AZUREAD_TENANT_ID | ✅ | - |
| AZUREAD_OAUTH_REDIRECT_URI | - | http://localhost:1337/strapi-plugin-sso/azuread/callback |
| AZUREAD_SCOPE | - | user.read |
| AZUREAD_OAUTH_USE_OIDC | - | true |

### Configuring environment variables

Expand All @@ -27,5 +28,6 @@ Use the following environment variables to configure the AzureAD integration:
3. `AZUREAD_TENANT_ID`: The Tenant ID created in AzureAD.
4. `AZUREAD_OAUTH_REDIRECT_URI`: The callback URL used by AzureAD to redirect the user after authentication. Defaults to 'http://localhost:1337/strapi-plugin-sso/azuread/callback'.
5. `AZUREAD_SCOPE`: The permissions your application requires from the user. Defaults to 'user.read'. More information on permissions can be found in the [Microsoft Graph permissions reference](https://docs.microsoft.com/en-us/graph/permissions-reference).
6. `AZUREAD_OAUTH_USE_OIDC`: Using OIDC calls graph.microsoft.com/oidc/userinfo while setting it to false calls /me as documented here : https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http

Make sure to replace the placeholders with the actual values you obtained from AzureAD.
1 change: 1 addition & 0 deletions server/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
AZUREAD_OAUTH_CLIENT_ID: '',
AZUREAD_OAUTH_CLIENT_SECRET: '',
AZUREAD_SCOPE: 'user.read',
AZUREAD_OAUTH_USE_OIDC: 'true',
},
validator() {
},
Expand Down
15 changes: 12 additions & 3 deletions server/controllers/azuread.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ async function azureAdSignInCallback(ctx) {
const userService = getService("user");
const oauthService = strapi.plugin("strapi-plugin-sso").service("oauth");
const roleService = strapi.plugin("strapi-plugin-sso").service("role");
const isOIDC = config["AZUREAD_OAUTH_USE_OIDC"] !== 'false';

if (!ctx.query.code) {
return ctx.send(oauthService.renderSignUpError(`code Not Found`));
Expand All @@ -74,12 +75,20 @@ async function azureAdSignInCallback(ctx) {
"Content-Type": "application/x-www-form-urlencoded",
},
});
const userResponse = await axios.get(OAUTH_USER_INFO_ENDPOINT, {
const apiResponse = await axios.get(isOIDC ? OAUTH_USER_INFO_ENDPOINT : 'https://graph.microsoft.com/v1.0/me', {
headers: {
Authorization: `Bearer ${response.data.access_token}`,
},
});

const userResponse = isOIDC ? apiResponse : {
data: {
email: apiResponse.data.userPrincipalName,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@yanicklandry
Can we use the parameter mail instead of userPrincipalName?

family_name: apiResponse.data.surname,
given_name: apiResponse.data.givenName,
}
}

const dbUser = await userService.findOneByEmail(userResponse.data.email);
let activateUser;
let jwtToken;
Expand All @@ -92,8 +101,8 @@ async function azureAdSignInCallback(ctx) {
const roles =
azureAdRoles && azureAdRoles["roles"]
? azureAdRoles["roles"].map((role) => ({
id: role,
}))
id: role,
}))
: [];

const defaultLocale = oauthService.localeFindByHeader(
Expand Down