Files
monorepo/LCU.WebApps.Collections.RepoClient/src/adalConfig.ts
T
2026-03-17 11:09:46 -05:00

49 lines
1.5 KiB
TypeScript

import {AuthenticationContext, AdalConfig} from 'react-adal';
export const adalConfig:AdalConfig = {
tenant: '63cd1554-2783-4a86-ae50-b9e6c21c9499',
clientId: '60f721aa-75bf-4195-ae48-d42cbfd8326b',
endpoints: {
api: "cc253cda-05b2-425c-a60c-d1f516a1c4a9"
},
cacheLocation: "localStorage"
};
export const authContext = new AuthenticationContext(adalConfig);
authContext.handleWindowCallback();
// This is an example of getting the token, or the user.
// To get a users groups, it's getUser().profile.roles
export const getToken = () => authContext.getCachedToken(adalConfig.clientId);
export const getUser = () => authContext.getCachedUser();
const hasRole = (profile: { roles?: string[] }, role:string) : boolean => {
if( !profile || !profile.roles || profile.roles.length <= 0 ) {
return false;
}
let hasRole = false;
profile.roles.forEach( (roleInput) => {
if( roleInput.toLowerCase() === role.toLowerCase() ) {
hasRole = true;
}
});
return hasRole;
};
export const hasAdminRole = () => {
const user = getUser();
return user && hasRole( user.profile, "Admin");
};
export const hasAnyRole = () => {
const user = getUser();
return user && (hasRole( user.profile, "Admin") || hasRole(user.profile, "Specialist"));
};
/*
export const adalApiFetch = (fetch: any, url: string, options: any) =>
adalFetch(authContext, adalConfig.endpoints.api, fetch, url, options);
export const withAdalLoginApi = withAdalLogin(authContext, adalConfig.endpoints.api);
*/