Skip to content
Open
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
59 changes: 47 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,50 @@
<br>
</h2>

# How to install
1. Clone this repository to any directory such as `~/nullplatform-chrome/`
2. Open Google Chrome and type `chrome://extensions` in the URL
3. Make sure you have enabled the **Developer Mode** and click **Load unpacked extension**
4. Select the directory where you've downloaded the extension and click `Install`
(Optional) Once you have installed the extension, you can click on the **Pin** button to have it readily available

# Usage: personal access tokens
To retrieve your personall access token you have to:
1. Log into nullplatform
2. Click the extension and it will open a popup with your personal access token
3. Click on "Copy to clipboard" button and that's it! now you can Copy the token to any cURL or script that you're crafting.

This Chrome extension helps you quickly retrieve your **personal access token** and use it to make authenticated calls
to the nullplatform API.

# How to install or update

1. Clone this repository to any directory, for example:

```bash
git clone https://github.com/nullplatform/nullplatform-chrome.git ~/nullplatform-chrome
```

2. Open Google Chrome and navigate to `chrome://extensions`.
3. Enable Developer mode (toggle in the top-right corner).
4. Click **Load unpacked** and select the directory where you cloned the repository.
5. The extension will now be installed or updated.

💡 **Tip**: Pin the extension to your Chrome toolbar (📌 icon) for quicker access.

# Usage: Retrieve your personal access token

To retrieve your personal access token, just:

1. Log in to nullplatform in a Chrome tab.
2. Click the nullplatform extension icon.
3. A popup will appear showing **your personal access token**.
4. Click **Copy to clipboard** to easily paste it into any cURL command or script.

# Troubleshooting

If you see the following message when using the extension:

> *"No token found. Make sure you’re logged in to nullplatform in this tab."*

This usually means one of the following:

1. You're not on a logged-in nullplatform tab

Make sure you have the platform open in a tab where you are already logged in. Then click the extension again.

2. You need to update the extension

If you’re still seeing this message while on a logged-in tab, update the extension:

- Remove it and reinstall following the steps in [How to install or update](#how-to-install-or-update)

We release periodic updates, so make sure you’re using the latest version.
151 changes: 76 additions & 75 deletions nullplatform-chrome.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,89 @@
const copyButton = document.getElementById('copyButton');
const copyButton = document.getElementById("copyButton");

function updateUI(token) {
const title = document.getElementById('title');
const label = document.getElementById('token');
const title = document.getElementById("title");
const label = document.getElementById("token");

if (token) {
title.style.visibility = "visible";
title.innerHTML = "Here is your <b>personal</b> access token:";
label.textContent = token;
label.style.display = "block";
if (copyButton) {
copyButton.style.visibility = "visible";
copyButton.style.display = "block";
}
} else {
title.innerHTML = "No token found. Is this a Nullplatform tab where you're already logged in?";
title.style.visibility = "visible";
label.style.display = "none";
if (copyButton) {
copyButton.style.display = "none";
}
if (token) {
title.style.visibility = "visible";
title.innerHTML = "Here is your <b>personal</b> access token:";
label.textContent = token;
label.style.display = "block";
if (copyButton) {
copyButton.style.visibility = "visible";
copyButton.style.display = "block";
}
} else {
title.innerHTML = "No token found. Make sure you’re logged in to nullplatform in this tab.";
title.style.visibility = "visible";
label.style.display = "none";
if (copyButton) {
copyButton.style.display = "none";
}
}
}

function getAccessToken() {
const accessTokenLocalStorageKey = 'accessToken';
const accessTokenFetchURL = 'https://bff-dashboard.nullplatform.io/v1/auth/access_token';
async function _getAccessToken() {
try {
const accessTokenFromLocalStorage = localStorage.getItem(accessTokenLocalStorageKey);
if (accessTokenFromLocalStorage) {
return accessTokenFromLocalStorage;
}
const organizationSlug = window.location.hostname?.split?.('.')?.[0];
const response = await fetch(accessTokenFetchURL, {
method: 'GET',
credentials: 'include',
headers: {
'Accept': 'application/json',
'np-organization-slug': organizationSlug
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const text = await response.text();

const data = JSON.parse(text);
const token = data.access_token;
return token;
} catch (error) {;
return null;
}
const accessTokenLocalStorageKey = "accessToken";
const accessTokenFetchURL = "https://bff-dashboard.nullplatform.io/v1/auth/access_token";
async function _getAccessToken() {
try {
const accessTokenFromLocalStorage = localStorage.getItem(accessTokenLocalStorageKey);
if (accessTokenFromLocalStorage) {
return accessTokenFromLocalStorage;
}
const organizationSlug = window.location.hostname?.split?.(".")?.[0];
const response = await fetch(accessTokenFetchURL, {
method: "GET",
credentials: "include",
headers: {
Accept: "application/json",
"np-organization-slug": organizationSlug,
},
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const text = await response.text();

const data = JSON.parse(text);
const token = data.access_token;
return token;
} catch (error) {
return null;
}
return _getAccessToken();
}
return _getAccessToken();
}

document.addEventListener('DOMContentLoaded', async function() {
const tabs = await chrome.tabs.query({active: true, currentWindow: true});
const results = await chrome.scripting.executeScript({
target: {tabId: tabs[0].id},
function: getAccessToken
});
if (results && results[0] && results[0].result) {
const token = await results[0].result;
updateUI(token);
} else {
updateUI(null);
}
document.addEventListener("DOMContentLoaded", async function () {
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
const results = await chrome.scripting.executeScript({
target: { tabId: tabs[0].id },
function: getAccessToken,
});
if (results && results[0] && results[0].result) {
const token = await results[0].result;
updateUI(token);
} else {
updateUI(null);
}
});

copyButton.addEventListener('click', function() {
var copyText = document.getElementById('token');

navigator.clipboard.writeText(copyText.textContent)
.then(() => {
copyButton.innerHTML = "Copy to clipboard &#x2713;";
})
.catch(err => {
console.error('Failed to copy text: ', err);
})
.finally(() => {
setTimeout(() => {
copyButton.innerHTML = "Copy to clipboard";
}, 2000);
});
copyButton.addEventListener("click", function () {
var copyText = document.getElementById("token");

navigator.clipboard
.writeText(copyText.textContent)
.then(() => {
copyButton.innerHTML = "Copy to clipboard &#x2713;";
})
.catch((err) => {
console.error("Failed to copy text: ", err);
})
.finally(() => {
setTimeout(() => {
copyButton.innerHTML = "Copy to clipboard";
}, 2000);
});
});