Skip to content

Commit

Permalink
feat(demo): better demo
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet committed Nov 3, 2024
1 parent 301acfe commit 85835ac
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/oidc-client-demo/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const execute = () => {
const href = window.location.href;

const vanillaOidc = OidcClient.getOrCreate(() => fetch)(configuration);

Check failure on line 131 in examples/oidc-client-demo/src/index.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `····`

Check failure on line 131 in examples/oidc-client-demo/src/index.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `····`
// @ts-ignore
function logout() {
vanillaOidc.logoutAsync();
Expand Down
1 change: 1 addition & 0 deletions examples/react-oidc-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"postinstall": "node ./node_modules/@axa-fr/react-oidc/bin/copy-service-worker-files.mjs public"
},
"dependencies": {
"@axa-fr/oidc-client": "workspace:*",
"@axa-fr/react-oidc": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-oidc-demo/public/staticwebapp.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"exclude": ["*.{svg,png,jpg,gif}", "*.{css,scss}", "*.js"]
},
"globalHeaders": {
"content-security-policy": "script-src 'self'",
"content-security-policy": "script-src 'self' 'unsafe-eval' ",
"Access-Control-Allow-Origin": "*",
"X-Frame-Options": "SAMEORIGIN",
"X-Permitted-Cross-Domain-Policies": "none",
Expand Down
3 changes: 3 additions & 0 deletions examples/react-oidc-demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FetchUserHoc, FetchUserHook } from './FetchUser.js';
import { Home } from './Home.js';
import { MultiAuthContainer } from './MultiAuth.js';
import { Profile, SecureProfile } from './Profile.js';
import CodeExecutor from "./CodeExecutor";

Check failure on line 10 in examples/react-oidc-demo/src/App.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Replace `"./CodeExecutor"` with `'./CodeExecutor'`

Check failure on line 10 in examples/react-oidc-demo/src/App.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Replace `"./CodeExecutor"` with `'./CodeExecutor'`

const OidcSecureHoc = withOidcSecure(Profile);

Expand Down Expand Up @@ -111,6 +112,7 @@ function App() {
</div>
</BrowserRouter>
</OidcProvider>

<div className="container-fluid mt-3">
<div className="card">
<div className="card-body">
Expand All @@ -129,6 +131,7 @@ function App() {
</div>
</div>
</div>
<CodeExecutor/>

Check failure on line 134 in examples/react-oidc-demo/src/App.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Insert `·`

Check failure on line 134 in examples/react-oidc-demo/src/App.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Insert `·`
</>
);
}
Expand Down
44 changes: 44 additions & 0 deletions examples/react-oidc-demo/src/CodeExecutor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { OidcClient } from '@axa-fr/oidc-client';
import React, { useState } from 'react';

// @ts-ignore
window.OidcClient = OidcClient;
const CodeExecutor: React.FC = () => {
const [code, setCode] = useState<string>('');

Check failure on line 7 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `··`

Check failure on line 7 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `··`
const [output, setOutput] = useState<string>('');

Check failure on line 8 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `··`

Check failure on line 8 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `··`

Check failure on line 9 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `····`

Check failure on line 9 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `····`
const executeCode = () => {

Check failure on line 10 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `··`

Check failure on line 10 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `··`
try {

Check failure on line 11 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Replace `········` with `····`

Check failure on line 11 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Replace `········` with `····`
const result = eval(`

Check failure on line 12 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `······`

Check failure on line 12 in examples/react-oidc-demo/src/CodeExecutor.tsx

View workflow job for this annotation

GitHub Actions / Run linters

Delete `······`
(function() {
${code}
})()
`);
setOutput(String(result));
} catch (error) {
setOutput(`Erreur : ${(error as Error).message}`);
}
};

return (
<div style={{ padding: '20px', maxWidth: '600px', margin: '0 auto' }}>
<h2>Execute your JavaScript Code</h2>
<textarea
value={code}
onChange={(e) => setCode(e.target.value)}
placeholder="Write your JavaScript code here..."
rows={10}
style={{ width: '100%', marginBottom: '10px' }}
></textarea>
<button onClick={executeCode} style={{ padding: '10px 20px' }}>
Execute the code
</button>
<div style={{ marginTop: '20px', padding: '10px', backgroundColor: '#f5f5f5' }}>
<h3>Result :</h3>
<pre>{output}</pre>
</div>
</div>
);
};

export default CodeExecutor;
14 changes: 1 addition & 13 deletions examples/react-oidc-demo/src/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,23 @@ import { useOidc, useOidcUser } from '@axa-fr/react-oidc';
import React, { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

const createIframeHack = () => {
const iframe = document.createElement('iframe');
const html = '<body>Foo<script>alert("youhou");</script></body>';
iframe.srcdoc = html;
document.body.appendChild(iframe);
};

export const Home = () => {
const { login, logout, renewTokens, isAuthenticated } = useOidc();
const { oidcUser, oidcUserLoadingState } = useOidcUser();
console.log(oidcUser, oidcUserLoadingState);
const navigate = useNavigate();

const navigateProfile = () => {
navigate('/profile');
};

useEffect(() => {
createIframeHack();
}, []);

return (
<div className="container-fluid mt-3">
<div className="card">
<div className="card-body">
<h5 className="card-title">Home</h5>
<p className="card-text">
React Demo Application protected by OpenId Connect. More info on about oidc on{' '}
<a href="https://github.com/AxaGuilDEv/react-oidc">GitHub @axa-fr/react-oidc</a>
<a href="https://github.com/AXAFrance/oidc-client">GitHub @axa-fr/react-oidc</a>
</p>
{!isAuthenticated && (
<p>
Expand Down
4 changes: 1 addition & 3 deletions examples/react-oidc-demo/src/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ interface OidcUserRoleInfo extends OidcUserInfo {

const DisplayUserInfo = () => {
const { oidcUser, oidcUserLoadingState, reloadOidcUser } = useOidcUser<OidcUserRoleInfo>();

console.log('oidcUser', oidcUser);
console.log('oidcUserLoadingState', oidcUserLoadingState);

switch (oidcUserLoadingState) {
case OidcUserStatus.Loading:
return <p>User Information are loading</p>;
Expand Down
2 changes: 1 addition & 1 deletion examples/react-oidc-demo/src/configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const configurationIdentityServer = {
// monitor_session: true,
extras: { youhou_demo: 'youhou' },
token_renew_mode: TokenRenewMode.access_token_invalid,
token_automatic_renew_mode: TokenAutomaticRenewMode.AutomaticOnlyWhenFetchExecuted,
token_automatic_renew_mode: TokenAutomaticRenewMode.AutomaticBeforeTokenExpiration,
demonstrating_proof_of_possession: false,
preload_user_info: true,
};
Expand Down
11 changes: 5 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85835ac

Please sign in to comment.