Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { UserAgentApplication, Logger } from 'msal';
const ACCESS_TOKEN = 'rideshare_access_token';
const ID_TOKEN = 'rideshare_id_token';
const EXPIRES_AT = 'rideshare_expires_at';
const USER_DETAILS = 'rideshare_user_details';
let logger = new Logger((level, message, containsPii) => {
console.log(message);
});
export class Authentication {
constructor() {
// The window values below should by set by public/js/settings.js
this._scopes = window.authScopes;
this._clientId = window.authClientId;
this._authority = window.authAuthority;
var cb = this._tokenCallback.bind(this);
var opts = {
validateAuthority: false
};
this._userAgentApplication = new UserAgentApplication(
this._clientId,
{
auth: {
authority: process.env.REACT_APP_AUTHORITY,
clientId: process.env.REACT_APP_AAD_APP_CLIENT_ID,
postLogoutRedirectUri: window.location.origin,
redirectUri: window.location.origin,
validateAuthority: true,
// After being redirected to the "redirectUri" page, should user
// be redirected back to the Url where their login originated from?
navigateToLoginRequestUrl: false,
},
// Enable logging of MSAL events for easier troubleshooting.
// This should be disabled in production builds.
system: {
logger: new Logger(
(logLevel, message, containsPii) => {
console.log('[MSAL]', message);
},
{
level: LogLevel.Verbose,
piiLoggingEnabled: false,
},
),
},
cache: {
cacheLocation: 'sessionStorage',
storeAuthStateInCookie: true,
},
},
{
scopes: ['openid'],
export const AppPage = createReactClass({
mixins: [FluxMixin, StoreWatchMixin],
adApplication: reactAppAdClientId ? new UserAgentApplication(
reactAppAdClientId,
null,
(errorMessage, token, error, tokenType) => {
if (token) {
this.adHandleToken(token);
} else {
this.adHandleError(error);
}
},
{
cacheLocation: 'localStorage',
logger: new Logger((level, message, containsPII) => {
const logger = level === 0 ? console.error : level === 1 ? console.warn : console.log;
logger(`AD: ${message}`);
})
}
) : null,
adHandleError(error) {
console.error(`AD: ${error}`);
localStorage.removeItem(reactAppAdTokenStoreKey);
},
adHandleToken(token) {
const user = this.adApplication.getUser();
localStorage.setItem(reactAppAdTokenStoreKey, token);
this.getFlux().actions.DASHBOARD.handleAuth({ user, token });
window.location.reload();
return new Promise(async (resolve) => {
const loggerCallback = (logLevel, message, containsPii) => {
console.log(`Auth: [${logLevel} ${message}`);
};
const singleMessage = (location) => {
return (message) => {
console.log(`Auth - ${location}: ${message}`);
};
};
const logger = new Logger(
loggerCallback,
{correlationId: "1234", level: LogLevel.Info, piiLoggingEnabled: true});
const redirectUri = "" + Uri + (Uri.substring(Uri.length - 1, Uri.length) === "/" ? "login" : "/login");
console.log(`redirectUri : ${Uri}, ${redirectUri}, ${Uri.substring(Uri.length - 1, Uri.length)}`);
this.msal = new UserAgentApplication(
{
auth: {
clientId: this.clientId,
authority: `https://login.microsoftonline.com/${this.tenantId}`,
redirectUri
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: true
constructor(@Inject(MSAL_CONFIG) private config: MsalConfig, private router: Router, private broadcastService: BroadcastService) {
super(config.clientID, config.authority, null,
{
validateAuthority: config.validateAuthority,
cacheLocation: config.cacheLocation,
storeAuthStateInCookie: config.storeAuthStateInCookie,
redirectUri: config.redirectUri,
postLogoutRedirectUri: config.postLogoutRedirectUri,
logger: new Logger(config.logger, { correlationId: config.correlationId, level :config.level ,piiLoggingEnabled: config.piiLoggingEnabled}),
loadFrameTimeout: config.loadFrameTimeout,
navigateToLoginRequestUrl: config.navigateToLoginRequestUrl,
isAngular: true,
unprotectedResources: config.unprotectedResources,
protectedResourceMap: new Map(config.protectedResourceMap)
});
this.loginScopes = [this.clientId, "openid", "profile", "user.read"];
this.updateDataFromCache(this.loginScopes);
var urlHash = window.location.hash;
this.processHash(urlHash);
window.addEventListener("msal:popUpHashChanged", (e: CustomEvent) => {
this._logger.verbose("popUpHashChanged ");
this.processHash(e.detail);
});
constructor(config, router, broadcastService) {
super(config.clientID, config.authority, null, {
validateAuthority: config.validateAuthority,
cacheLocation: config.cacheLocation,
redirectUri: config.redirectUri,
postLogoutRedirectUri: config.postLogoutRedirectUri,
logger: new Logger(config.logger, { correlationId: config.correlationId, level: config.level, piiLoggingEnabled: config.piiLoggingEnabled }),
loadFrameTimeout: config.loadFrameTimeout,
navigateToLoginRequestUrl: config.navigateToLoginRequestUrl,
isAngular: true,
unprotectedResources: config.unprotectedResources,
protectedResourceMap: new Map(config.protectedResourceMap),
});
this.config = config;
this.router = router;
this.broadcastService = broadcastService;
this._oauthData = { isAuthenticated: false, userName: "", loginError: "", idToken: {} };
this.loginScopes = [this.clientId];
this.updateDataFromCache(this.loginScopes);
var urlHash = window.location.hash;
this.processHash(urlHash);
window.addEventListener("msal:popUpHashChanged", (e) => {
this._logger.verbose("popUpHashChanged ");