11import { Rule } from "antd/lib/form" ;
2- import { HttpConfig } from "api/datasourceApi" ;
2+ import { HttpConfig , OAuthConfig } from "api/datasourceApi" ;
33import {
44 DatasourceForm ,
55 FormInputItem ,
@@ -21,12 +21,14 @@ import {
2121} from "../form" ;
2222import { DatasourceFormProps } from "./datasourceFormRegistry" ;
2323import { useHostCheck } from "./useHostCheck" ;
24+ import { useSelector } from "react-redux" ;
25+ import { getUser } from "redux/selectors/usersSelectors" ;
2426
2527const AuthTypeOptions = [
2628 { label : "None" , value : "NO_AUTH" } ,
2729 { label : "Basic" , value : "BASIC_AUTH" } ,
2830 { label : "Digest" , value : "DIGEST_AUTH" } ,
29- { label : "OAuth 2.0(Inherit from login)" , value : "OAUTH2_INHERIT_FROM_LOGIN" } ,
31+ { label : "OAuth 2.0 (Inherit from login)" , value : "OAUTH2_INHERIT_FROM_LOGIN" } ,
3032 // { label: "OAuth 2.0", value: "oAuth2" },
3133] as const ;
3234
@@ -50,7 +52,16 @@ export const HttpDatasourceForm = (props: DatasourceFormProps) => {
5052 const datasourceConfig = datasource ?. datasourceConfig as HttpConfig ;
5153 // const oauthConfig = datasourceConfig?.authConfig as OAuthConfig;
5254
55+ // here we get the Auth Sources from a user to enable user impersonation
56+ const userAuthSources = useSelector ( getUser ) . connections ?. filter ( authSource => authSource . source !== "EMAIL" ) ; ;
57+ const userAuthSourcesOptions = userAuthSources ?. map ( item => ( {
58+ label : item . source ,
59+ value : item . authId
60+ } ) ) || [ ] ;
61+
5362 const [ authType , setAuthType ] = useState ( datasourceConfig ?. authConfig ?. type ) ;
63+ const [ authId , setAuthId ] = useState ( datasourceConfig ?. authConfig ?. authId ) ;
64+
5465 // const [grantType, setGrantType] = useState(oauthConfig?.grantType ?? "authorization_code");
5566
5667 const hostRule = useHostCheck ( ) ;
@@ -98,6 +109,22 @@ export const HttpDatasourceForm = (props: DatasourceFormProps) => {
98109 }
99110 } ;
100111
112+ const showUserAuthSourceSelector = ( ) => {
113+ if ( authType === "OAUTH2_INHERIT_FROM_LOGIN" ) {
114+ return (
115+ < FormSelectItem
116+ name = { "authId" }
117+ label = "User Authentication Source"
118+ options = { userAuthSourcesOptions }
119+ initialValue = { datasourceConfig ?. authConfig ?authId : null }
120+ afterChange = { ( value ) => setAuthId ( value ) }
121+ labelWidth = { 142 }
122+ />
123+ ) ;
124+ }
125+ return null ;
126+ } ;
127+
101128 return (
102129 < DatasourceForm form = { form } preserve = { false } >
103130 < FormSection size = { props . size } >
@@ -149,6 +176,7 @@ export const HttpDatasourceForm = (props: DatasourceFormProps) => {
149176 afterChange = { ( value ) => setAuthType ( value ) }
150177 labelWidth = { 142 }
151178 />
179+ { showUserAuthSourceSelector ( ) }
152180 { showAuthItem ( authType ) }
153181 </ FormSection >
154182
0 commit comments