Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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',

// OpenID Connect
OIDC_REDIRECT_URI: 'http://localhost:1337/strapi-plugin-sso/oidc/callback', // URI after successful login
Expand Down
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',

OIDC_REDIRECT_URI: 'http://localhost:1337/strapi-plugin-sso/oidc/callback',
OIDC_CLIENT_ID: '',
Expand Down
11 changes: 10 additions & 1 deletion server/controllers/azuread.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async function azureAdSignInCallback(ctx) {
const tokenService = strapi.service('admin::token')
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 @@ -73,12 +74,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.email,
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.

@luokui-c12
Sorry for the delay in checking.
This is an email, but is it not a mail correctly?

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

const dbUser = await userService.findOneByEmail(userResponse.data.email);
let activateUser;
let jwtToken;
Expand Down