Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/msal-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@
"test:coverage": "jest --coverage",
"test:coverage:only": "npm run clean:coverage && npm run test:coverage",
"build:all": "cd ../.. && npm run build --workspace=@azure/msal-common --workspace=@azure/msal-browser",
"build:all:debug": "cd ../.. && MSAL_MINIFY_LOGS=false npm run build --workspace=@azure/msal-common --workspace=@azure/msal-browser",
"build:modules": "rollup -c --strictDeprecations --bundleConfigAsCjs",
"build:modules:watch": "rollup -cw --bundleConfigAsCjs",
"build": "npm run clean && npm run build:modules",
"build:debug": "npm run clean && MSAL_MINIFY_LOGS=false npm run build:modules",
"decode-logs": "node scripts/decode-logs.cjs --mappings ./dist/log-strings-mapping.json,../msal-common/dist-browser/log-strings-mapping.json",
"prepack": "npm run build:all",
"format:check": "prettier --ignore-path .gitignore --check src test",
"format:fix": "prettier --ignore-path .gitignore --write src test",
Expand Down Expand Up @@ -114,4 +117,4 @@
"dependencies": {
"@azure/msal-common": "15.7.0"
}
}
}
31 changes: 30 additions & 1 deletion lib/msal-browser/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { nodeResolve } from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import terser from "@rollup/plugin-terser";
import pkg from "./package.json";
import { createPackageJson } from "rollup-msal";
import { createPackageJson, loggerMinifyPlugin } from "rollup-msal";
import path from "path";

const libraryHeader = `/*! ${pkg.name} v${pkg.version} ${
new Date().toISOString().split("T")[0]
} */`;
const useStrictHeader = "'use strict';";
const fileHeader = `${libraryHeader}\n${useStrictHeader}`;
const minifyLogs = process.env.MSAL_MINIFY_LOGS || true;

export default [
{
Expand All @@ -38,6 +40,11 @@ export default [
typescript: require("typescript"),
tsconfig: "tsconfig.build.json",
}),
...(minifyLogs === true ? [loggerMinifyPlugin({
verbose: true,
outputFile: "./dist/log-strings-mapping.json",
packageJsonPath: path.resolve(__dirname, "./package.json"),
})] : []),
],
},
{
Expand Down Expand Up @@ -65,6 +72,11 @@ export default [
compilerOptions: { outDir: "lib/types" },
}),
createPackageJson({ libPath: __dirname }),
...(minifyLogs === true ? [loggerMinifyPlugin({
outputFile: "./lib/log-strings-mapping.json",
packageJsonPath: path.resolve(__dirname, "./package.json"),
verbose: true
})] : []),
],
},
{
Expand Down Expand Up @@ -96,6 +108,9 @@ export default [
declarationMap: false,
},
}),
...(minifyLogs === true ? [loggerMinifyPlugin({
verbose: true
})] : []),
],
},
{
Expand Down Expand Up @@ -127,9 +142,13 @@ export default [
declarationMap: false,
},
}),
loggerMinifyPlugin({
verbose: true
}),
terser({
output: {
preamble: libraryHeader,
comments: false,
},
}),
],
Expand All @@ -156,6 +175,11 @@ export default [
typescript: require("typescript"),
tsconfig: "tsconfig.custom-auth.build.json",
}),
...(minifyLogs === true ? [loggerMinifyPlugin({
verbose: true,
outputFile: "./dist/custom-auth-path/log-strings-mapping.json",
packageJsonPath: path.resolve(__dirname, "./package.json"),
})] : []),
],
},
{
Expand All @@ -180,6 +204,11 @@ export default [
sourceMap: true,
compilerOptions: { outDir: "lib/custom-auth-path/types" },
}),
...(minifyLogs === true ? [loggerMinifyPlugin({
outputFile: "./lib/custom-auth-path/log-strings-mapping.json",
packageJsonPath: path.resolve(__dirname, "./package.json"),
verbose: true
})] : []),
],
},
];
147 changes: 147 additions & 0 deletions lib/msal-browser/scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# MSAL Browser Log Decoder

This script helps decode hashed logging strings from the minified MSAL browser bundle back to their original, human-readable messages.

## Background

When MSAL Browser is built in production mode, all logging strings are minified using consistent hashing to reduce bundle size. This means that instead of seeing:

```
acquireTokenSilent - attempting to acquire token from native platform
```

Users will see:

```
11757953
```

This script allows you to decode these hashes back to the original messages for debugging purposes.

## Usage

### Via npm script (recommended)

```bash
# Decode multiple hashes - simple array format (no quotes needed!)
npm run decode-logs -- [11757953,22757575,bfd4c713]

# Decode multiple hashes - space separated
npm run decode-logs -- 11757953 22757575 bfd4c713

# Decode multiple hashes - traditional JSON format (still supported)
npm run decode-logs -- '["11757953", "22757575", "bfd4c713"]'

# Decode a single hash
npm run decode-logs -- 11757953

# Using stdin
echo '[11757953,bfd4c713]' | npm run decode-logs
```

### Direct script execution

```bash
# Decode multiple hashes - simple array format
node scripts/decode-logs.cjs [11757953,22757575,bfd4c713]

# Decode multiple hashes - space separated
node scripts/decode-logs.cjs 11757953 22757575 bfd4c713

# Decode multiple hashes - traditional JSON format
node scripts/decode-logs.cjs '["11757953", "22757575", "bfd4c713"]'

# Decode a single hash
node scripts/decode-logs.cjs 11757953

# Using stdin
echo '[11757953,bfd4c713]' | node scripts/decode-logs.cjs
```

## Input Format

The script accepts multiple input formats for maximum flexibility:

1. **Simple Array** (recommended): `[hash1,hash2,hash3]` - no quotes needed!
2. **Space Separated**: `hash1 hash2 hash3` - for multiple hashes
3. **JSON Array**: `["hash1", "hash2", "hash3"]` - traditional format (still supported)
4. **Single Hash**: `hash1` - for a single hash
5. **Stdin**: Pipe any of the above formats via stdin

## Output Format

The script outputs each decoded message on a new line with a numbered prefix:

```
MSAL Browser Log Decoder
Decoding 3 log entries...

[1] acquireTokenSilent - attempting to acquire token from native platform
[2] acquireTokenByCode called
[3] TokenCache - loading account

Summary:
✓ Decoded: 3
```

If unknown hashes are encountered:

```
[1] acquireTokenSilent - attempting to acquire token from native platform
[2] Unknown hash: unknown123
[3] acquireTokenByCode called

Summary:
✓ Decoded: 2
✗ Not found: 1
Unknown hashes: unknown123
Note: Unknown hashes might be from a different build or version.
```

## Requirements

- The `lib/log-strings-mapping.json` file must exist (generated during build)
- Node.js environment

## Examples

### Customer logs example

If a customer sends you logs like:
```
[11757953,22757575,bfd4c713,ac8ab727]
```

You can decode them with (no quotes needed!):
```bash
npm run decode-logs -- [11757953,22757575,bfd4c713,ac8ab727]
```

Or if they send space-separated hashes:
```bash
npm run decode-logs -- 11757953 22757575 bfd4c713 ac8ab727
```

### Real-world debugging scenario

Customer reports: "I'm getting error hash `e6a1b82a` during token acquisition"

```bash
npm run decode-logs -- "e6a1b82a"
```

Output:
```
[1] TokenCache - scopes not specified in the request or response. Cannot add token to the cache.
```

## Troubleshooting

### Script not found
Make sure you're running from the msal-browser directory and the build has been completed.

### Mapping file not found
Run `npm run build` to generate the `lib/log-strings-mapping.json` file.

### Unknown hashes
Hashes might be from a different version or build. Ensure you're using the mapping file from the same build as the logs.
Loading
Loading