Fix setting oauthPassThru flag (#72472)
* Fix setting oauthPassThru flag * Call onChange only if azure auth is enabled * Move changes in onSettingsChange
This commit is contained in:
@@ -78,17 +78,36 @@ export const DataSourceHttpSettings = (props: HttpSettingsProps) => {
|
|||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [isAccessHelpVisible, setIsAccessHelpVisible] = useState(false);
|
const [isAccessHelpVisible, setIsAccessHelpVisible] = useState(false);
|
||||||
|
const [azureAuthEnabled, setAzureAuthEnabled] = useState(false);
|
||||||
const theme = useTheme2();
|
const theme = useTheme2();
|
||||||
let urlTooltip;
|
let urlTooltip;
|
||||||
|
|
||||||
const onSettingsChange = useCallback(
|
const onSettingsChange = useCallback(
|
||||||
(change: Partial<typeof dataSourceConfig>) => {
|
(change: Partial<typeof dataSourceConfig>) => {
|
||||||
|
// Azure Authentication doesn't work correctly when Forward OAuth Identity is enabled.
|
||||||
|
// The Authorization header that has been set by the ApplyAzureAuth middleware gets overwritten
|
||||||
|
// with the Authorization header set by the OAuthTokenMiddleware.
|
||||||
|
const isAzureAuthEnabled =
|
||||||
|
(azureAuthSettings?.azureAuthSupported && azureAuthSettings.getAzureAuthEnabled(dataSourceConfig)) || false;
|
||||||
|
setAzureAuthEnabled(isAzureAuthEnabled);
|
||||||
|
if (isAzureAuthEnabled) {
|
||||||
|
const tmpOauthPassThru =
|
||||||
|
dataSourceConfig.jsonData.oauthPassThru !== undefined ? dataSourceConfig.jsonData.oauthPassThru : false;
|
||||||
|
change = {
|
||||||
|
...change,
|
||||||
|
jsonData: {
|
||||||
|
...dataSourceConfig.jsonData,
|
||||||
|
oauthPassThru: isAzureAuthEnabled ? false : tmpOauthPassThru,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
onChange({
|
onChange({
|
||||||
...dataSourceConfig,
|
...dataSourceConfig,
|
||||||
...change,
|
...change,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[dataSourceConfig, onChange]
|
[azureAuthSettings, dataSourceConfig, onChange]
|
||||||
);
|
);
|
||||||
|
|
||||||
switch (dataSourceConfig.access) {
|
switch (dataSourceConfig.access) {
|
||||||
@@ -145,15 +164,6 @@ export const DataSourceHttpSettings = (props: HttpSettingsProps) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
const azureAuthEnabled: boolean =
|
|
||||||
(azureAuthSettings?.azureAuthSupported && azureAuthSettings.getAzureAuthEnabled(dataSourceConfig)) || false;
|
|
||||||
|
|
||||||
// Azure Authentication doesn't work correctly when Forward OAuth Identity is enabled.
|
|
||||||
// The Authorization header that has been set by the ApplyAzureAuth middleware gets overwritten
|
|
||||||
// with the Authorization header set by the OAuthTokenMiddleware.
|
|
||||||
dataSourceConfig.jsonData.oauthPassThru = azureAuthEnabled ? false : dataSourceConfig.jsonData.oauthPassThru;
|
|
||||||
const shouldShowForwardOAuthIdentityOption = azureAuthEnabled ? false : showForwardOAuthIdentityOption;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="gf-form-group">
|
<div className="gf-form-group">
|
||||||
<>
|
<>
|
||||||
@@ -301,7 +311,7 @@ export const DataSourceHttpSettings = (props: HttpSettingsProps) => {
|
|||||||
<HttpProxySettings
|
<HttpProxySettings
|
||||||
dataSourceConfig={dataSourceConfig}
|
dataSourceConfig={dataSourceConfig}
|
||||||
onChange={(jsonData) => onSettingsChange({ jsonData })}
|
onChange={(jsonData) => onSettingsChange({ jsonData })}
|
||||||
showForwardOAuthIdentityOption={shouldShowForwardOAuthIdentityOption}
|
showForwardOAuthIdentityOption={azureAuthEnabled ? false : showForwardOAuthIdentityOption}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user