casual-simulation / casualos

Casual Open Simulation for the Web
https://ab1.bot
MIT License
49 stars 9 forks source link

Add the ability to get access tokens for hume.ai sessions #474

Closed KallynGowdy closed 4 months ago

KallynGowdy commented 4 months ago

hume.ai is a AI service that can be used for classifying a user's emotional state. It would be great if there was some way to integrate their Expression Measurement API into CasualOS. Some techproofing has demonstrated that we can use OAuth access tokens for expression measurement sessions.

For now, the only needed function is ai.hume.requestAccessToken(). This should make a request to the server which will generate an access token that can be used by the client to access the Hume API. These tokens should ideally be somewhat short lived and not able to be refreshed.

The basic pattern looks like this:

// Request an access token using the OAuth Client Credentials flow
const res = await self.fetch(`https://${host}/oauth2-cc/token`, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': `Basic ${API_KEY}`,
    },
    body: new URLSearchParams({
        grant_type: 'client_credentials',
    }).toString(),
    cache: 'no-cache',
});

The server should also have another subscription feature: ai.hume so that this feature can be limited based on a user's subscription tier.

Hume Docs