没有 Client_secret 的赛普拉斯 SSO Azure

时间:2021-05-14 16:09:24

标签: azure single-sign-on cypress microsoft-dynamics

我正在努力解决我在尝试使用赛普拉斯通过 Microsoft Azure 单点登录登录时遇到的问题。不使用 Client_Secret 可以做到吗?我该怎么做?

我已经花了一个多星期试图解决这个问题......

我是这方面的大三学生,所以如果您能帮助我,我将不胜感激。

非常感谢,

1 个答案:

答案 0 :(得分:1)

是的,你可以。在门户中导航到您的 AD 应用程序 -> Authentication -> 将 Allow public client flows 设置为 Yes,如下所示。

enter image description here

然后在blog中,在步骤Cypress utility for mimicking react-adal中,它使用了client credential flow,博客下面有@Bryce Kolton的评论帖子,他使用了ROPC flow ,在此流程中,您可以通过公共客户端应用程序在没有 Client_Secret 的情况下使用它,正如您在上面所做的更改(允许公共客户端流程),只需参考它。

/* eslint-disable no-underscore-dangle */
import { AuthenticationContext } from ‘react-adal’;
import { azTenantId, azClientId } from ‘../../server/config/environment’;

// Need to get data points from server’s environment, not src
const adalConfig = {
tenant: azTenantId,
clientId: azClientId,
cacheLocation: ‘localStorage’,
replyUrl: ‘/’,
endpoints: {
api: ”,
},
};
const authContext = new AuthenticationContext(adalConfig);

export default async function doLogin() {
// getCachedToken also does an expiration check so we know for sure the tokens are usable
if (
!authContext.getCachedToken(adalConfig.endpoints.api)
|| !authContext.getCachedToken(adalConfig.clientId)
) {
const response = await cy.request({
method: ‘POST’,
url:
‘https://login.microsoftonline.com/mercedesme.onmicrosoft.com/oauth2/token’,
// qs: { ‘api-version’: ‘1.0’ }, // uncomment if your consuming resource expects the ‘aud’ to have a prefix of ‘sn:’
headers: {
‘cache-control’: ‘no-cache’,
‘content-type’:
‘multipart/form-data; boundary=—-WebKitFormBoundary7MA4YWxkTrZu0gW’,
},
form: true,
body: {
grant_type: ‘password’,
response_type: ‘code’,
client_id: ‘[[yourappsclientid]]’,
username: ‘[[yourtestuzseremail]]’,
password: ‘[[yourtestuserpassword]]!’,
scope: ‘openid’,
resource: ‘[[some-resource-id]]’,
},
});
// Store the token and data in the location where adal expects it
authContext._saveItem(authContext.CONSTANTS.STORAGE.IDTOKEN, response.body.access_token);
authContext._saveItem(
authContext.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY + adalConfig.endpoints.api,
response.body.access_token,
);
authContext._saveItem(
authContext.CONSTANTS.STORAGE.ACCESS_TOKEN_KEY + adalConfig.clientId,
response.body.access_token,
);
authContext._saveItem(
authContext.CONSTANTS.STORAGE.EXPIRATION_KEY + adalConfig.endpoints.api,
response.body.expires_on,
);
authContext._saveItem(
authContext.CONSTANTS.STORAGE.EXPIRATION_KEY + adalConfig.clientId,
response.body.expires_on,
);
authContext._saveItem(
authContext.CONSTANTS.STORAGE.TOKEN_KEYS,
[adalConfig.clientId].join(authContext.CONSTANTS.RESOURCE_DELIMETER)
+ authContext.CONSTANTS.RESOURCE_DELIMETER,
);
}
}

要成功使用 ROPC 流程,请确保您的场景满足以下要求,例如您的用户帐户未启用 MAF。

enter image description here