-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* define auth api and use in attestation * add callback * fix callback page issue * update else state * setup attestation * add AuthenticationWrapper * fix custom auth with wallet * add attest integration * remove connectButton in app bar * update import * update import * update import * add protect route * update constant.d.ts * update ts.config * upd
- Loading branch information
1 parent
11613f2
commit 1076eba
Showing
17 changed files
with
1,542 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,6 @@ dist-ssr | |
|
||
coverage | ||
|
||
.env | ||
.env | ||
|
||
/src/contracts/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useEffect } from 'react'; | ||
import { useLocation, useNavigate } from 'react-router-dom'; | ||
import { jwtDecode } from 'jwt-decode'; | ||
import { Backdrop, CircularProgress } from '@mui/material'; | ||
|
||
interface DecodedJwt { | ||
exp: number; | ||
iat: number; | ||
provider: string; | ||
sub: string; | ||
} | ||
|
||
const useQueryParams = () => { | ||
const { search } = useLocation(); | ||
return new URLSearchParams(search); | ||
}; | ||
|
||
const isJwt = (token: string): boolean => { | ||
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$/; | ||
return jwtRegex.test(token); | ||
}; | ||
|
||
const getStoredTokens = (): Array<{ | ||
token: string; | ||
exp: number; | ||
provider: string; | ||
}> => { | ||
const storedTokens = localStorage.getItem('OCI_PROVIDER_TOKENS'); | ||
return storedTokens ? JSON.parse(storedTokens) : []; | ||
}; | ||
|
||
const storeTokens = ( | ||
tokens: Array<{ token: string; exp: number; provider: string }> | ||
) => { | ||
localStorage.setItem('OCI_PROVIDER_TOKENS', JSON.stringify(tokens)); | ||
}; | ||
|
||
export function Callback() { | ||
const queryParams = useQueryParams(); | ||
const jwt = queryParams.get('jwt'); | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
if (jwt && isJwt(jwt)) { | ||
try { | ||
const decodedJwt: DecodedJwt = jwtDecode(jwt); | ||
const { provider, exp } = decodedJwt; | ||
|
||
// Retrieve existing tokens from localStorage | ||
const storedTokens = getStoredTokens(); | ||
|
||
// Remove any existing token for the current provider | ||
const updatedTokens = storedTokens.filter( | ||
(token) => token.provider !== provider | ||
); | ||
|
||
// Add the new token | ||
updatedTokens.push({ token: jwt, exp, provider }); | ||
|
||
// Store updated tokens back to localStorage | ||
storeTokens(updatedTokens); | ||
|
||
// Redirect to the current JWT provider route | ||
navigate(`/identifiers/${provider}/attestation?jwt=${jwt}`); | ||
} catch (error) { | ||
console.error('Invalid JWT:', error); | ||
} | ||
} else { | ||
navigate('/identifiers'); | ||
} | ||
}, [jwt, navigate]); | ||
|
||
return ( | ||
<Backdrop open> | ||
<CircularProgress color="inherit" /> | ||
</Backdrop> | ||
); | ||
} | ||
|
||
export default Callback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Callback } from './Callback'; | ||
|
||
export default Callback; |
Oops, something went wrong.