-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCIMApiSample.tsx
136 lines (124 loc) · 4.88 KB
/
SCIMApiSample.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React, { useEffect, useState } from 'react';
import { useAuthContext, HttpRequestConfig } from "@asgardeo/auth-react";
import * as authConfig from "../config.json";
import ReactJson from "react-json-view";
import { useHistory } from "react-router-dom";
export const SCIMAPISection = (props: any) => {
const { state, httpRequest } = useAuthContext();
const [name, setName] = useState<string>("");
const [scimUserInfo, setScimUserInfo] = useState<any>({});
const [country, setCountry] = useState<string>("");
const [dob, setDateOfBirth] = useState<string>("");
const history= useHistory();
useEffect(() => {
if (state?.isAuthenticated) {
sendRequest();
}
}, [state.isAuthenticated]);
function sendRequest() {
const requestConfig: HttpRequestConfig = {
headers: {
"Accept": "application/json",
"Content-Type": "application/scim+json"
},
attachToken: true,
method: "GET",
url: authConfig.serverOrigin + "/scim2/Me"
};
httpRequest(requestConfig).then((response: any) => {
setScimUserInfo(response.data);
setName(response.data.name.givenName);
setCountry(response.data["urn:scim:wso2:schema"]["country"]);
setDateOfBirth(response.data["urn:scim:wso2:schema"]["dateOfBirth"])
}).catch((error) => {
console.log("request error: " + error);
})
}
function sendPatchRequest() {
const requestConfig: HttpRequestConfig = {
headers: {
"Accept": "application/json",
"Content-Type": "application/scim+json"
},
method: "PATCH",
url: authConfig.serverOrigin + "/scim2/Me",
data: {
"Operations": [
{
"op": "replace",
"value": {
"name": {
"givenName": name
},
"urn:scim:wso2:schema": {
"country": country,
"dateOfBirth": dob,
}
}
},
],
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:PatchOp"
]
}
};
httpRequest(requestConfig).then((response) => {
setScimUserInfo(response.data);
alert("Updated!");
}).catch((error) => {
console.log("request error: " + error);
})
}
const handleSubmit = (event: any) => {
event.preventDefault();
sendPatchRequest();
}
return (
<div id='features' className='text-center'>
<div className='container'>
<div className='col-md-10 col-md-offset-1 section-title'>
<h2>React-Asgardeo Single Page Application</h2>
<h4>SCIM API</h4>
</div>
<div className='row row-center'>
<form onSubmit={handleSubmit}>
<label>
Change GivenName:
<input
onChange={(e) => setName(e.target.value)}
value={name} type="text" name="name" />
</label>
<br />
<label>
Change Country:
<input
onChange={(e) => setCountry(e.target.value)}
value={country} type="text" name="country" />
</label>
<br />
<label>
Change Date Of Birth:
<input
onChange={(e) => setDateOfBirth(e.target.value)}
value={dob} type="text" name="dob" />
</label>
<br />
<input type="submit" value="Update" />
</form>
<div className='col-xs-12 col-md-12 json'>
{' '}
<ReactJson
src={scimUserInfo}
name={null}
enableClipboard={false}
displayObjectSize={false}
displayDataTypes={false}
iconStyle="square"
theme="monokai"
/>
</div>
</div>
</div>
</div>
)
}