Created
November 29, 2016 16:21
-
-
Save shauns/9e3d29ba77c0f424a6fe528f52734b4d to your computer and use it in GitHub Desktop.
Webtask to swap auth0 ID token for stream.io one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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