feat(web): add client utilities
This commit is contained in:
1 parent
a796620b7f
commit
39f3221640
7 files changed
+335
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
PublicClientApplication,
|
||||
type Configuration,
|
||||
} from '@azure/msal-browser';
|
||||
|
||||
const clientId = (import.meta.env.VITE_MSAL_CLIENT_ID ?? '').trim();
|
||||
const authority = (import.meta.env.VITE_MSAL_AUTHORITY ?? '').trim();
|
||||
const redirectUri = (import.meta.env.VITE_MSAL_REDIRECT_URI ?? '').trim();
|
||||
|
||||
export const MSAL_API_SCOPE = (
|
||||
import.meta.env.VITE_MSAL_API_SCOPE ?? ''
|
||||
).trim();
|
||||
|
||||
export const MSAL_SILENT_REDIRECT_URI = (
|
||||
import.meta.env.VITE_MSAL_SILENT_REDIRECT_URI ??
|
||||
`${window.location.origin}/auth/silent-callback.html`
|
||||
).trim();
|
||||
|
||||
export const isMsalConfigured = Boolean(
|
||||
clientId &&
|
||||
authority &&
|
||||
MSAL_API_SCOPE &&
|
||||
!authority.includes('<tenant-id>'),
|
||||
);
|
||||
|
||||
export const msalConfig: Configuration = {
|
||||
auth: {
|
||||
clientId,
|
||||
authority,
|
||||
redirectUri: redirectUri || window.location.origin,
|
||||
postLogoutRedirectUri: window.location.origin,
|
||||
},
|
||||
cache: {
|
||||
cacheLocation: 'localStorage',
|
||||
},
|
||||
};
|
||||
|
||||
export const msalInstance = isMsalConfigured
|
||||
? new PublicClientApplication(msalConfig)
|
||||
: null;
|
||||
Reference in new issue
Block a user