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 @@ -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
File renamed without changes.
2 changes: 1 addition & 1 deletion admin/src/utils/getTrad.js → admin/src/getTrad.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pluginId from '../pluginId';
import pluginId from './pluginId';

const getTrad = id => `${pluginId}.${id}`;

Expand Down
20 changes: 10 additions & 10 deletions admin/src/pages/HomePage/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {memo, useEffect, useState} from 'react';
import React, { memo, useEffect, useState } from 'react';
import {
Alert,
Button,
Expand All @@ -13,12 +13,12 @@ import {
Td,
Th
} from '@strapi/design-system';
import {CheckPermissions} from '@strapi/helper-plugin';
import {useIntl} from 'react-intl';
import {Helmet} from 'react-helmet';
import axios from '../../utils/axiosInstance'
import { CheckPermissions } from '@strapi/helper-plugin';
import { useIntl } from 'react-intl';
import { Helmet } from 'react-helmet';
import axios from '../../axiosInstance'
import styled from 'styled-components'
import getTrad from "../../utils/getTrad";
import getTrad from "../../getTrad";

const ButtonWrapper = styled.div`
margin: 10px 0 0 0;
Expand All @@ -42,7 +42,7 @@ const AlertMessage = styled.div`
`

const HomePage = () => {
const {formatMessage} = useIntl();
const { formatMessage } = useIntl();
const [ssoRoles, setSSORoles] = useState([])
const [roles, setRoles] = useState([])
const [showSuccess, setSuccess] = useState(false)
Expand Down Expand Up @@ -93,8 +93,8 @@ const HomePage = () => {
}

return (
<CheckPermissions permissions={[{action: 'plugin::strapi-plugin-sso.read', subject: null}]}>
<Helmet title={'Single Sign On'}/>
<CheckPermissions permissions={[{ action: 'plugin::strapi-plugin-sso.read', subject: null }]}>
<Helmet title={'Single Sign On'} />
<HeaderLayout
title={'Single Sign On'}
subtitle={formatMessage({
Expand Down Expand Up @@ -142,7 +142,7 @@ const HomePage = () => {
<Tr>
<Th>
{/* Not required, but if it doesn't exist, it's an error. */}
<BaseCheckbox style={{display: 'none'}}/>
<BaseCheckbox style={{ display: 'none' }} />
</Th>
{
roles.map(role => (
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