@@ -21,11 +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" } ,
28- { label : "Digest" , value : "DIGEST_AUTH" } ,
30+ { label : "Digest" , value : "DIGEST_AUTH" } ,
31+ { label : "OAuth 2.0 (Inherit from login)" , value : "OAUTH2_INHERIT_FROM_LOGIN" } ,
2932] as const ;
3033
3134type AuthType = ValueFromOption < typeof AuthTypeOptions > ;
@@ -46,7 +49,15 @@ export const GraphqlDatasourceForm = (props: DatasourceFormProps) => {
4649 const { form, datasource } = props ;
4750 const datasourceConfig = datasource ?. datasourceConfig as HttpConfig ;
4851
52+ // here we get the Auth Sources from a user to enable user impersonation
53+ const userAuthSources = useSelector ( getUser ) . connections ?. filter ( authSource => authSource . source !== "EMAIL" ) ; ;
54+ const userAuthSourcesOptions = userAuthSources ?. map ( item => ( {
55+ label : item . source ,
56+ value : item . authId
57+ } ) ) || [ ] ;
58+
4959 const [ authType , setAuthType ] = useState ( datasourceConfig ?. authConfig ?. type ) ;
60+ const [ authId , setAuthId ] = useState ( datasourceConfig ?. authConfig ?. authId ) ;
5061
5162 const hostRule = useHostCheck ( ) ;
5263
@@ -93,6 +104,22 @@ export const GraphqlDatasourceForm = (props: DatasourceFormProps) => {
93104 }
94105 } ;
95106
107+ const showUserAuthSourceSelector = ( ) => {
108+ if ( authType === "OAUTH2_INHERIT_FROM_LOGIN" ) {
109+ return (
110+ < FormSelectItem
111+ name = { "authId" }
112+ label = "User Authentication Source"
113+ options = { userAuthSourcesOptions }
114+ initialValue = { datasourceConfig ?. authConfig ?authId : null }
115+ afterChange = { ( value ) => setAuthId ( value ) }
116+ labelWidth = { 142 }
117+ />
118+ ) ;
119+ }
120+ return null ;
121+ } ;
122+
96123 return (
97124 < DatasourceForm form = { form } preserve = { false } >
98125 < FormSection size = { props . size } >
@@ -138,6 +165,7 @@ export const GraphqlDatasourceForm = (props: DatasourceFormProps) => {
138165 afterChange = { ( value ) => setAuthType ( value ) }
139166 labelWidth = { 142 }
140167 />
168+ { showUserAuthSourceSelector ( ) }
141169 { showAuthItem ( authType as AuthType ) }
142170 </ FormSection >
143171
0 commit comments