How to use the msal.Logger function in msal

To help you get started, we’ve selected a few msal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure-Samples / Serverless-microservices-reference-architecture / web / serverless-microservices-web / src / utils / Authentication.js View on Github external
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,
github syncweek-react-aad / react-aad / sample / src / authProvider.js View on Github external
{
    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'],
github CatalystCode / project-fortis / project-fortis-interfaces / src / routes / AppPage.js View on Github external
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();
github TypedProject / ts-express-decorators / examples / passport-azure-ad / packages / client / src / app / services / core / azureAd / AuthService.ts View on Github external
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
github AzureAD / microsoft-authentication-library-for-js / lib / msal-angular / src / msal.service.ts View on Github external
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);
        });
github AzureAD / microsoft-authentication-library-for-js / lib / msal-angular / dist / msal.service.js View on Github external
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 ");