Skip to content

Commit

Permalink
Merge branch 'releaseCandidate' of https://github.com/tprouvot/Chrome…
Browse files Browse the repository at this point in the history
…-Salesforce-inspector into releaseCandidate
  • Loading branch information
tprouvot committed Apr 8, 2024
2 parents e0a50a7 + e97b203 commit 75e037f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
9 changes: 6 additions & 3 deletions addon/inspector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export let apiVersion = localStorage.getItem("apiVersion") == null ? "60.0" : localStorage.getItem("apiVersion");
export let sessionError = "";
export let sessionError;
export let sfConn = {

async getSession(sfHost) {
Expand Down Expand Up @@ -100,8 +100,11 @@ export let sfConn = {
throw err;
} else if (xhr.status == 401) {
let error = xhr.response.length > 0 ? xhr.response[0].message : "New access token needed";
sessionError = error;
showInvalidTokenBanner();
//set sessionError only if user has already generated a token, which will prevent to display the error when the session is expired and api access control not configured
if (localStorage.getItem(this.instanceHostname + "_access_token")){
sessionError = error;
showInvalidTokenBanner();
}
let err = new Error();
err.name = "Unauthorized";
err.message = error;
Expand Down
1 change: 1 addition & 0 deletions addon/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class OptionsTabSelector extends React.Component {
{option: Option, props: {type: "toggle", title: "Search metadata from Shortcut tab", key: "metadataShortcutSearch"}},
{option: Option, props: {type: "toggle", title: "Disable query input autofocus", key: "disableQueryInputAutoFocus"}},
{option: Option, props: {type: "toggle", title: "Popup Dark theme", key: "popupDarkTheme"}},
{option: Option, props: {type: "toggle", title: "Show 'Generate Access Token' button", key: "popupGenerateTokenButton", default: true}},
{option: Option, props: {type: "text", title: "Custom favicon (org specific)", key: this.sfHost + "_customFavicon", placeholder: "Available values : green, orange, pink, purple, red, yellow"}}
]
},
Expand Down
13 changes: 12 additions & 1 deletion addon/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ class App extends React.PureComponent {
if (sessionError){
text = "Access Token Expired";
title = "Generate New Token";
url = `https://${sfHost}/services/oauth2/authorize?response_type=token&client_id=` + clientId + "&redirect_uri=" + browser + "-extension://" + chrome.i18n.getMessage("@@extension_id") + "/data-export.html";
}
url = `https://${sfHost}/services/oauth2/authorize?response_type=token&client_id=` + clientId + "&redirect_uri=" + browser + "-extension://" + chrome.i18n.getMessage("@@extension_id") + "/data-export.html";
return {title, url, text};
}
render() {
Expand Down Expand Up @@ -297,6 +297,17 @@ class App extends React.PureComponent {
h("div", {className: "slds-m-bottom_xx-small"},
h("a", {ref: "apiExploreBtn", href: "explore-api.html?" + hostArg, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "E", h("u", {}, "x"), "plore API"))
),
localStorage.getItem("popupGenerateTokenButton") !== "false" ? h("div", {className: "slds-m-bottom_xx-small"},
h("a",
{
ref: "generateToken",
href: bannerUrlAction.url,
target: linkTarget,
className: !clientId ? "button hide" : "page-button slds-button slds-button_neutral"
},
h("span", {}, h("u", {}, "G"), "enerate Access Token"))
) : null,

// Workaround for in Lightning the link to Setup always opens a new tab, and the link back cannot open a new tab.
inLightning && isInSetup && h("div", {className: "slds-m-bottom_xx-small"},
h("a",
Expand Down
15 changes: 13 additions & 2 deletions docs/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@

---

### For Chrome and Edge users

If you enabled "API client whitelisting" (a.k.a "API Access Control") in your org, SF Inspector may not work anymore.

To secure the extension usage, you can use a OAuth 2.0 flow to get an access token, linked to a connected app installed in your org.
To install the default "SF Inspector reloaded" connected app, open popup and click 'Generate Access Token' button

<img width="275" alt="Generate Token" src="https://github.com/tprouvot/Salesforce-Inspector-reloaded/assets/35368290/931df75d-42ac-4667-ab3f-35f6b6b65a66">

Then navigate to Setup | Connected Apps OAuth Usage, and click "Install" on the Salesforce Inspector reloaded app.

To install the default "SF Inspector reloaded" connected app, navigate to Setup | Connected Apps OAuth Usage, and click "Install" on the Salesforce Inspector reloaded app.
From now when the token will be expired, this banner will show up and provide a link to re-generate the access token

<img width="274" alt="image" src="https://github.com/tprouvot/Salesforce-Inspector-reloaded/assets/35368290/856c3635-008b-4b91-8160-019d1d701ba9">

> **Warning**
> Don't forget to grant access to the users by selecting the related profile(s) or permission set(s).
If you are a Firefox user, or if you want to have full control over the connected app settings, you can also use your own connected app by following these instructions:

### For Firefox users

1. Create a connected app under Setup | App Manager > New Connected App.
2. Set callback url to `chrome-extension://chromeExtensionId/data-export.html` (replace `chromeExtensionId` by the actual ID of the extension in your web browser). Make sure the "Manage user data via APIs (api)" scope is selected. You can leave other settings to their default values.

Expand All @@ -32,7 +43,7 @@ If you are a Firefox user, or if you want to have full control over the connecte

5. Refresh page and generate new token

<img alt="Generate Token" src="https://github.com/tprouvot/Chrome-Salesforce-inspector/blob/master/docs/screenshots/generateAccessToken.png?raw=true" width="300">
<img width="275" alt="Generate Token" src="https://github.com/tprouvot/Salesforce-Inspector-reloaded/assets/35368290/931df75d-42ac-4667-ab3f-35f6b6b65a66">

## Migrate saved queries from legacy extension to Salesforce Inspector Reloaded

Expand Down

0 comments on commit 75e037f

Please sign in to comment.