Search code examples
getstream-io

Generating access token for getstream feed?


I am new to getstream - and I am writing some client side code

var streamclient = stream.connect('xxxxxxxx', null, '11111');

var feed = streamclient.feed('user', 'maurice', '??????') ;

How do I generate the access token for this client ?


Solution

  • In order to keep things secure, you'll first want to get the feed token on the server-side.

    When initialising a Stream client on the server-side, you'll pass your app secret which enables access to all your app's feeds. The token can then be passed onward to your client application (single-page app, mobile app etc.).

    Example server-side code:

    var stream = require('getstream');
    
    // pass the app secret when connecting on the server-side
    streamclient = stream.connect('<key>', '<secret>', '<app id>');
    
    // no feed token is req'd when the Stream client was connected with an app secret
    var feed = streamclient.feed('user', 'maurice');
    
    var feedToken = feed.token // or feed.getReadOnlyToken();
    

    The client-side snippet you posted looks fine for initialising the feed variable.