-
Notifications
You must be signed in to change notification settings - Fork 355
/
OIDCConfigContainer.tsx
111 lines (101 loc) · 3.03 KB
/
OIDCConfigContainer.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { FormApi } from "final-form";
import React from "react";
import { graphql } from "react-relay";
import { withForm } from "coral-framework/lib/form";
import {
FetchProp,
withFetch,
withFragmentContainer,
} from "coral-framework/lib/relay";
import { OmitRefType } from "coral-framework/types";
import { OIDCConfig_formValues } from "coral-admin/__generated__/OIDCConfig_formValues.graphql";
import { OIDCConfigContainer_auth as AuthData } from "coral-admin/__generated__/OIDCConfigContainer_auth.graphql";
import DiscoverOIDCConfigurationFetch from "./DiscoverOIDCConfigurationFetch";
import OIDCConfig from "./OIDCConfig";
interface Props {
auth: AuthData;
disabled?: boolean;
discoverOIDCConfiguration: FetchProp<typeof DiscoverOIDCConfigurationFetch>;
form: FormApi<{
auth: OmitRefType<AuthData> & OmitRefType<OIDCConfig_formValues>;
}>;
}
interface State {
awaitingResponse: boolean;
}
class OIDCConfigContainer extends React.Component<Props, State> {
public state = {
awaitingResponse: false,
};
private handleDiscover = async () => {
const issuer = this.props.form.getState().values.auth.integrations.oidc
.issuer;
if (!issuer) {
return;
}
this.setState({ awaitingResponse: true });
try {
const {
discoverOIDCConfiguration: config,
} = await this.props.discoverOIDCConfiguration({
issuer,
});
if (config) {
if (config.issuer) {
this.props.form.change(
// TODO: @(cvle) Types in final-form are not accurate...
"auth.integrations.oidc.issuer" as any,
config.issuer
);
}
this.props.form.change(
// TODO: @(cvle) Types in final-form are not accurate...
"auth.integrations.oidc.authorizationURL" as any,
config.authorizationURL
);
this.props.form.change(
// TODO: @(cvle) Types in final-form are not accurate...
"auth.integrations.oidc.jwksURI" as any,
config.jwksURI
);
this.props.form.change(
// TODO: @(cvle) Types in final-form are not accurate...
"auth.integrations.oidc.tokenURL" as any,
config.tokenURL
);
}
} catch (error) {
// FIXME: (wyattjoh) handle error
// eslint-disable-next-line no-console
console.warn(error);
}
this.setState({ awaitingResponse: false });
};
public render() {
const { disabled, auth } = this.props;
return (
<OIDCConfig
disabled={disabled}
callbackURL={auth.integrations.oidc.callbackURL}
onDiscover={this.handleDiscover}
disableForDiscover={this.state.awaitingResponse}
/>
);
}
}
const enhanced = withForm(
withFetch(DiscoverOIDCConfigurationFetch)(
withFragmentContainer<Props>({
auth: graphql`
fragment OIDCConfigContainer_auth on Auth {
integrations {
oidc {
callbackURL
}
}
}
`,
})(OIDCConfigContainer)
)
);
export default enhanced;