jupyter-naas / chrome-extension

Boost productivity with Naas Chrome Extension, your AI-powered assistant for analytics and automation.
https://naas.ai
GNU Affero General Public License v3.0
1 stars 0 forks source link

feat: Update how we store secrets in the extension #28

Closed Dr0p42 closed 2 months ago

Dr0p42 commented 5 months ago

Make use of api.naas.ai/secret

Goal

The goal is to now make use of api.naas.ai/secret to make it easier for the extension to update linkedin:

You can see the full spec on https://api.naas.ai/docs.

Authenticate over api.naas.ai

The authentication process is a bit different than before. The way it works now is that you need to grab an access_token from naas.ai. So, as a user, when I login into naas.ai, the token in stored in the local storage as you can see here:

image

Now if you grab this access_token you can trade it for what we call a "long lived token" on this url: https://auth.naas.ai/bearer/workspace/longlived, you can find the documentation here: https://auth.naas.ai/docs#/default/workspace_token_to_longlived_jwt_bearer_workspace_longlived_get

The documentation allows you to test it directly:

image

image

Once you have the token, you should safely store it in the local storage of the extension for future use.

It should be passed like Authorization: Bearer <longlivedtoken> in HTTP headers.

Use the secret api

Here you can find the documentation of the secrets endpoints: https://api.naas.ai/docs#/secret

image

As you can see you can:

Linkedin example

Let's say you need to update the LI_AT secret, you should be able to do it like so:

image

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Accept", "application/json");
myHeaders.append("Authorization", "Bearer <The Long lived token>");

var raw = JSON.stringify({
  "secret": {
    "name": "LI_AT",
    "value": "MyLIATToken"
  }
});

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://api.naas.ai/secret/", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
Dr0p42 commented 2 months ago

This is done