This solution allows you to setup Single Sign-On into React. It allows setting up JWT SSO.You can allow your users to Single Sign-On into React by verifying Identity with your existing compliant Identity Provider. This is done using JSON Web Token (JWT) tokens and it can be easily integrated with React built in any framework or language.
npm install --save base64url jsrsasign jssha utf8



| Custom App Name | The name of your react application. |
| Redirect-URL | Enter the app URL where you want to handle the JWT token. |
| Identity Source | You need to select the user store or the external IDP where the user accounts will be stored. |



import { JWTBuilder } from './path/to/jwt-connector';
<button> onClick={sso}>Single Sign On</button>
function sso() {
window.location.href = window.location.href = ‘’; //
example:https://login.xecurify.com/moas/broker/login/jwt/277898?client_id=AbIVW8A
MNTBzg2o7&redirect_uri=http://localhost:3000/login;
}
const Login = () => {
// The SearchParams hook lets us work with the query string of a URL.
let [searchParams, setSearchParams] = useSearchParams();
const cert = "< PLACE YOUR CERTIFICATE STRING HERE >";
var verified = false;
// Gets the id_token parameter from the query URL
let jwt = searchParams.get("id_token");
if (jwt) {
var jwtBuilder = new JWTBuilder();
// Initialize the JWT
jwtBuilder.parseJwt(jwt);
// set the secret that was shared by your IdP
jwtBuilder.setSecret(cert);
try {
// Compare the hashed jwt with the one received
verified = jwtBuilder.verifyJwt();
} catch (error) {
console.error(error);
}
}
useEffect(() => {
if (verified)
{
// Once you find the JWT is verified, you can go ahead and get the data
from JWT
let user = jwtBuilder.getPayload();
let username=user.username;
let email=user.email;
// You can create a user session here if required and navigate to the home
page
}
}, [verified]);
Test SSO login to your React account with miniOrange IdP:


Contact us or email us at idpsupport@xecurify.com and we'll help you setting it up in no time.
If you want to ensure that all sessions (SP and IDP) for a user are properly closed, you can configure Single Logout with the steps below.
A. Configure miniOrange with IdP SLO endpoint:
B. Configure IdP with miniOrange SLO endpoint:
https://login.xecurify.in/moas/broker/login/saml_logout/<your-customer-id>
C. Configure your JWT application with SLO endpoint:
https://login.xecurify.in/moas/broker/login/jwt/logout/<your-customer-id>?redirect_uri=<redirect-url>| your-customer-id | You have to add your miniOragne account customer ID here. |
| redirect-url | This should be replaced with the logout URL of your JWT application. |