Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
mojo-perception
Advanced tools
Use Mojo Perception API as a Javascript module both for web and Node.js applications.
If you use npm
, install mojo-perception-js module:
npm install mojo-perception
If you only need a browser usage, add the script in the <head>
section
<script type="text/javascript" src="https://developer.mojo.ai/mojo-perception.min.js"></script>
loadMojoPerception
This function returns a Promise
that resolves with a MojoPerception
object once mojo-perception.js has loaded.
import {loadMojoPerception} from 'mojo-perception';
const mojoPerception = await loadMojoPerception('auth_token');
Please note that the user token 'auth_token' is different from the API Key.
🙏 We take a particular care with publishable user token for web applications. See below for more info and best practices.
To make things safe and easy, we have a REST API ready to create user tokens on-the-fly.
When using the API for a web application, you should implement a backend function that will get a token for each user. We recommend to use tokens with expiration date.
To do so, you can use the REST API of Mojo Perception API.
Below, an example using curl
:
In your terminal, replace <YOUR_API_KEY_HERE>
by one of your API Keys and run :
curl -X PUT -i -H 'Authorization: <YOUR_API_KEY_HERE>' -d '{"datetime": "2022-01-01T00:00:00.000000","expiration":360}' -H 'Content-Type: application/json' https://api.mojo.ai/mojo_perception_api/user
This will give you something like this, and note that we have set expiration: 360
, for a 60 x 60 seconds duration period :
HTTP/2 200
server: nginx
date: Tue, 18 Jan 2022 16:53:54 GMT
content-type: application/json
content-length: 350
{"user_namespace": "a5fa97ded6584cb4a7ff3933aa66025c", "auth_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NDI1MjQ4MzQsInN1YiI6ImE1ZmE5N2RlLWQ2NTgtNGNiNC1hN2ZmLTM5MzliYTY2MDI1YyIsImV4cCI6MTY0MjUyNDg0NH0.7FuLJ6Hmozi2DbX9zooVxYvnp_f91H4vzodstDZbLzI", "host_name": "socket.mojo.ai", "port": "443"}
You can use the auth_token
and given host_name
, port
and user_namespace
to configure your API endpoint in the API, with the setOptions()
method.
Tutorials
💡 Have a look to the tutorials section
1️⃣ If you face a
"JsonWebTokenError"
, maybe that's because of the expiration. You can try to increase the user token duration to match your need. Default value of 360 seconds might be too short.
2️⃣ When you code your web application, you might have some issues because of browser caching. Don't forget to force refresh to stay up do date with your code.
FAQs
Mojo Perception Javascript API
We found that mojo-perception demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.