"Access denied" error message when using a read-only token on Getstream.io

In my implementation of the django getstream.io client, I have a backend code snippet that generates a read-only token and includes it in the response along with my jwt token upon successful login. This code snippet resides at the end of my settings.py file, where I have defined the STREAM_API_SECRET and STREAM_API_KEY keys which match the settings on my getstream.io dashboard.

from stream_django.client import stream_client
def jwt_response_payload_handler(token, user=None, request=None):
    user_feed_1 = stream_client.feed('user', str(user.id))
    readonly_token = user_feed_1.get_readonly_token()
    return {
        'token': token,
        'stream': str(readonly_token)
    }

When attempting to set up a real-time stream on the frontend using the obtained token from the login response, I encountered a "Not authenticated error" upon connection. Despite confirming that the token passed matches the generated one on the backend, the issue persists.

function setupStream (token, id) {
  var client = stream.connect(STREAM_API_KEY, null, STREAM_APP_ID)
  var user1 = client.feed('user', id, token)

  function callback (data) {
    console.log(data)
  }

  function failCallback (data) {
    alert('something went wrong, check the console logs')
    console.log(data)
  }

  user1.subscribe(callback).then(() => {}, failCallback)
}

Despite following the documentation, the functionality remains unresolved. As per the documentation guide:

An attempt to fetch data through the console resulted in an error response:

  user1.get({ limit: 5, offset: 0 })
  .then(callback)
  .catch(failCallback)

The error response body was as follows:

{
    "code": null,
    "detail": "url signature missing or invalid",
    "duration": "7ms",
    "exception": "AuthenticationFailed",
    "status_code": 403
}

EDIT:

After modifying the method from get_readonly_token() to .token, and creating a read/write token instead, the client-side code started functioning correctly. It raises the question if readonly tokens are not supported?

Answer №1

After careful investigation, I discovered that my decoding method for the read_only token was incorrect. By updating the backend code as shown below, I successfully resolved the problem;

 'stream': readonly_token.decode("utf-8")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing named parameters as variables

In my Django project, I've encountered a situation that seems to be more related to Python itself. Consider the following code snippet: def get(self, request, arg, *args, **kwargs): if kwargs['m0'] == 'death': if kwarg ...

Having difficulties transmitting numerical values through res.send() in express with node

Currently, I'm faced with a challenge in my express application on node.js as I attempt to retrieve the "imdb rating." movies.json [{ "id": "3962210", "order": [4.361276149749756, 1988], "fields": { "year": 2015, "title": "David and Goliath" ...

What is the best way to access my request data within the django-paypal IPN function?

I'm in the process of creating an e-commerce website. All my order information is stored in the request. The structure of my views is as follows: payment.py def payment(request): order = request.order # Accessing the order instance # per ...

Exploring how to incorporate Express middleware into Firebase Functions for handling HTTPS requests

Encountering a challenge while using Express middleware with Firebase Functions. In this sample, a function is linked to the app() instance as shown below: app.get('*', (req, res) => { res.send(`Hello ${req.user.name}`); }); exports.autho ...

Can I create a personalized datepicker without relying on Angular Material or Bootstrap?

Looking to create a datepicker in Angular without relying on Angular Material or bootstrap, similar to the design shown in this image: https://i.sstatic.net/ujfDI.png Any ideas on how this can be achieved? Note: It's a business requirement. ...

Traverse a computed attribute in Vue.js

I am working with a component that contains a simple array as its data: data() { return { roles: [ { id: '1' , name: 'admin'}, { id: '2' , name: 'user'}, { id: &a ...

Delivering JSON content through an ExpressJS server from a file

As a newcomer to Express, I am facing an issue with serving a db.json file that gets replaced every 11 seconds. I want the updated content to show on each API call. Here's my current code snippet: const express = require('express'); const r ...

Regular expressions in JavaScript to match characters that are not the first character and are

I prefer not to include the first letter of characters such as _-., but they can be used between other characters '(^[a-zA-Z0-9-_. ]*$){1,10}' ...

Upgrading from Django 1.11 to 2.0 results in a significant decrease in unit test speed, as they are now running

After upgrading from Django 1.11 to 2.0, the only changes made were due to backwards incompatibilities: the switch from url to path with a route instead of a regex argument adding a few on_delete arguments that were previously overlooked Comparing unit ...

Steps for transforming an array into a complex array

Here is an array I have: [2, 1, 2, 1, 1, 1, 1, 1] I am looking for a way to create new arrays within the original array when the sum of values exceeds four. The desired result should look like this: [[2,1],[2,1,1],[1,1,1]] ...

Circular arrangement using D3 Circle Pack Layout in a horizontal orientation

I'm currently experimenting with creating a wordcloud using the D3 pack layout in a horizontal format. Instead of restricting the width, I am limiting the height for my layout. The pack layout automatically arranges the circles with the largest one ...

Transfer all the child nodes to the parent using the spread operator or Object.assign while preventing duplicate properties from being overwritten

I'm trying to transfer all the nodes of a child node to the parent using the spread operator or Object.assign (without relying on Lodash) while avoiding overwriting existing properties. My initial thought was to simply append the childArray to the ro ...

Autocomplete feature on Google fails to function beyond the first page

HTML <input id="location_input" type="text" name="location" value="" placeholder="Location" class="0 text-center" style="width:200px;margin:0 auto;" required> SCRIPT <script> function initMap() { var input = /** @type {!HTMLInputElement} ...

How to process JSON data that includes a function

I'm trying to replicate a similar diagram using dynamic input data. Here is a basic example of how I'm attempting to achieve this: <script> var myYears = ', 1991, 1992, 1993, 1994, 1995, 1998'; //auto-generated var myValues = ...

Error: Collection2 validation did not pass: The field 'name' must be filled in, the field 'email' cannot be empty, and the field 'message' is mandatory

I need to set up a way for visitors to send messages through my website const mongoose = require("mongoose"); mongoose.connect("MongoDb-Connection-Uri") .then(() => { console.log("mongodb connected"); }) .catch(() => { console.log("fail ...

Mysterious error regarding SMTPRecipientsRefused

The e-mail form I have is functioning properly on the staging server, but not on my local machine. After testing, I encountered the following error: SMTPRecipientsRefused at /submit-foo/ {'': (555, '5.5.2 Syntax error. y4sm50402qad.14 - gs ...

What is the best way to transform an Observable array containing objects into an Observable that emits the data contained within those objects?

Encountering an error: Error: Type 'Observable<Country[]>' is not assignable to type 'Observable'. Type 'Country[]' is missing properties like name, tld, alpha2Code, alpha3Code and more.ts(2322 The issue might be due ...

Converting the current Django page to a PDF file

I'm currently attempting to add a "convert to pdf" button on a dynamic service detail page, but I've been struggling with using ReportLab as suggested by Django documentation. Unfortunately, the ReportLab documentation doesn't provide any gu ...

Why is React JS unable to discover my exported modules?

Upon running my React app, the console displayed the following error message: Failed to compile. ./src/components/login/index.js Attempted import error: 'Login' is not exported from './login'. Here is an overview of the folder struct ...

Is it possible to utilize multiple controller files?

SOLVED After reviewing your feedback and making some adjustments to my code, I discovered a simple typo that was preventing me from achieving the desired result. Big thanks to everyone who assisted in pinpointing where I was going wrong. I've success ...