Skip to content

Instantly share code, notes, and snippets.

@shauns
Created November 29, 2016 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shauns/9e3d29ba77c0f424a6fe528f52734b4d to your computer and use it in GitHub Desktop.
Save shauns/9e3d29ba77c0f424a6fe528f52734b4d to your computer and use it in GitHub Desktop.
Webtask to swap auth0 ID token for stream.io one
"use latest";
import jwt from 'jsonwebtoken';
export default function(ctx, cb) {
const authSecret = ctx.data.AUTH0_CLIENT_SECRET;
const streamSecret = ctx.data.STREAM_CLIENT_SECRET;
const token = ctx.data.token;
const userId = jwt.verify(token, new Buffer(authSecret, 'base64')).sub;
const slug = ctx.data.feed;
const payload = {
resource: '*',
action: '*',
feed_id: `${slug}${userId}`
};
const signed = jwt.sign(payload, streamSecret, { noTimestamp: true });
cb(null, signed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment