@@ -21,11 +21,14 @@ import {
21
21
} from "../form" ;
22
22
import { DatasourceFormProps } from "./datasourceFormRegistry" ;
23
23
import { useHostCheck } from "./useHostCheck" ;
24
+ import { useSelector } from "react-redux" ;
25
+ import { getUser } from "redux/selectors/usersSelectors" ;
24
26
25
27
const AuthTypeOptions = [
26
28
{ label : "None" , value : "NO_AUTH" } ,
27
29
{ 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" } ,
29
32
] as const ;
30
33
31
34
type AuthType = ValueFromOption < typeof AuthTypeOptions > ;
@@ -46,7 +49,15 @@ export const GraphqlDatasourceForm = (props: DatasourceFormProps) => {
46
49
const { form, datasource } = props ;
47
50
const datasourceConfig = datasource ?. datasourceConfig as HttpConfig ;
48
51
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
+
49
59
const [ authType , setAuthType ] = useState ( datasourceConfig ?. authConfig ?. type ) ;
60
+ const [ authId , setAuthId ] = useState ( datasourceConfig ?. authConfig ?. authId ) ;
50
61
51
62
const hostRule = useHostCheck ( ) ;
52
63
@@ -93,6 +104,22 @@ export const GraphqlDatasourceForm = (props: DatasourceFormProps) => {
93
104
}
94
105
} ;
95
106
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
+
96
123
return (
97
124
< DatasourceForm form = { form } preserve = { false } >
98
125
< FormSection size = { props . size } >
@@ -138,6 +165,7 @@ export const GraphqlDatasourceForm = (props: DatasourceFormProps) => {
138
165
afterChange = { ( value ) => setAuthType ( value ) }
139
166
labelWidth = { 142 }
140
167
/>
168
+ { showUserAuthSourceSelector ( ) }
141
169
{ showAuthItem ( authType as AuthType ) }
142
170
</ FormSection >
143
171
0 commit comments