Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement- http request functionality to sample apps #262

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
* under the License.
*/

import { BasicUserInfo } from "@asgardeo/auth-react";
import React, { FunctionComponent, ReactElement } from "react";
import { BasicUserInfo, useAuthContext, HttpRequestConfig } from "@asgardeo/auth-react";
import React, { FunctionComponent, ReactElement, useState, useEffect } from "react";
import { JsonViewer } from '@textea/json-viewer'
import config from "../config.json";

/**
* Decoded ID Token Response component Prop types interface.
Expand Down Expand Up @@ -64,8 +65,55 @@ export const AuthenticationResponse: FunctionComponent<AuthenticationResponsePro
derivedResponse
} = props;

const [resp, setResp] = useState<object>({});

const { httpRequest } = useAuthContext();
const requestConfig: HttpRequestConfig = {
headers: {
"Accept": "application/json",
"Content-Type": "application/scim+json"
},
method: "GET",
attachToken: true,
url: `${config.baseUrl}/scim2/Me?attributes=emails,roles,name,phoneNumbers`,
};

useEffect(() => {
httpRequest(requestConfig)
.then((response) => {
setResp(response.data);
})
.catch((error) => {
console.error('Error:', error);
});
}, [])

return (
<>
{ Object.keys(resp).length !== 0 &&
(<><h2>httpRequest method Response</h2>
<p>Derived by the&nbsp;
<code className="inline-code-block">
<a href="https://www.npmjs.com/package/@asgardeo/auth-react/v/latest"
target="_blank"
rel="noreferrer"
>
@asgardeo/auth-react
</a>
</code>&nbsp;SDK
</p>
<div className="json">
<JsonViewer
className="asg-json-viewer"
value={ resp }
enableClipboard={ false }
displayObjectSize={ false }
displayDataTypes={ false }
rootName={ false }
theme="dark"
/>
</div></>)
}
<h2>Authentication Response</h2>
<h4 className="sub-title">
Derived by the&nbsp;
Expand Down
2 changes: 1 addition & 1 deletion samples/asgardeo-react-app/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"baseUrl": "",
"signInRedirectURL": "https://localhost:3000",
"signOutRedirectURL": "https://localhost:3000",
"scope": ["profile"]
"scope": ["internal_login"]
}
Loading