1
1
import { Rule } from "antd/lib/form" ;
2
- import { HttpConfig } from "api/datasourceApi" ;
2
+ import { HttpConfig , OAuthConfig } from "api/datasourceApi" ;
3
3
import {
4
4
DatasourceForm ,
5
5
FormInputItem ,
@@ -21,12 +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
30
{ 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" } ,
30
32
// { label: "OAuth 2.0", value: "oAuth2" },
31
33
] as const ;
32
34
@@ -50,7 +52,16 @@ export const HttpDatasourceForm = (props: DatasourceFormProps) => {
50
52
const datasourceConfig = datasource ?. datasourceConfig as HttpConfig ;
51
53
// const oauthConfig = datasourceConfig?.authConfig as OAuthConfig;
52
54
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
+
53
62
const [ authType , setAuthType ] = useState ( datasourceConfig ?. authConfig ?. type ) ;
63
+ const [ authId , setAuthId ] = useState ( datasourceConfig ?. authConfig ?. authId ) ;
64
+
54
65
// const [grantType, setGrantType] = useState(oauthConfig?.grantType ?? "authorization_code");
55
66
56
67
const hostRule = useHostCheck ( ) ;
@@ -98,6 +109,22 @@ export const HttpDatasourceForm = (props: DatasourceFormProps) => {
98
109
}
99
110
} ;
100
111
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
+
101
128
return (
102
129
< DatasourceForm form = { form } preserve = { false } >
103
130
< FormSection size = { props . size } >
@@ -149,6 +176,7 @@ export const HttpDatasourceForm = (props: DatasourceFormProps) => {
149
176
afterChange = { ( value ) => setAuthType ( value ) }
150
177
labelWidth = { 142 }
151
178
/>
179
+ { showUserAuthSourceSelector ( ) }
152
180
{ showAuthItem ( authType ) }
153
181
</ FormSection >
154
182
0 commit comments