Full Stack Developer
Tech Speaker
Auth0 Ambassador
Mozilla Reps Mentor
GDG Ranchi Organizer
@mdsbzalam
1. Serverless
2. Authentication & Authorization
3. JWT
4. Deployment
Serverless, is an execution model where the cloud provider is responsible for executing a piece of code by dynamically allocating the resources. The code is typically run inside stateless containers that can be triggered by a variety of events including http requests, database events, queuing services, monitoring alerts, file uploads, scheduled events (cron jobs), etc. The code that is sent to the cloud provider for execution is usually in the form of a function. Hence serverless is sometimes referred to as “Functions as a Service” or “FaaS”.
source: dadario.com.br
source: dadario.com.br
The header is a JSON Object usually consisting of the type( typ ) , which is JWT, and the algorithm used for encrypting the JWT (alg ):
{
"alg": "HS256",
"typ": "JWT"
}
The Payload is a JSON object that consists of user defined attributes ( called public claims ) . Some attributes are defined in the standard ( these are called reserved claims ).
{
// reserved claim
"iss": "https://myapi.com",
// public claim
"user": "mdsbzalam"
}
The Signature is the encoded header and payload, signed with a secret.
HMACSHA256(
base64UrlEncode(header) + "." +
base64UrlEncode(payload),
secret
)
This accomplishes several tasks at once, including:
A finished token looks like [encoded header].[encoded payload].[signature] :
/**
* @param context {WebtaskContext}
*/
module.exports = function(context, cb) {
cb(null, { hello: context.query.name || 'ServerlessDays Jaipur' });
};
'use latest';
import express from 'express';
import { fromExpress } from 'webtask-tools';
import bodyParser from 'body-parser';
const app = express();
app.use(bodyParser.json());
const jwksRsa = require('jwks-rsa');
const jwt = require('express-jwt');
app.use((req, res, next) => {
const issuer = 'https://' + req.webtaskContext.secrets.AUTH0_DOMAIN + '/';
jwt({
secret: jwksRsa.expressJwtSecret({ jwksUri: issuer + '.well-known/jwks.json' }),
audience: req.webtaskContext.secrets.AUDIENCE,
issuer: issuer,
algorithms: [ 'RS256' ]
})(req, res, next);
});
app.get('/test', (req, res) => {
// test endpoint, no-operation
res.send(200);
});
app.get('/', (req, res) => {
// add your logic, you can use scopes from req.user
res.json({hi: req.user.sub});
});
module.exports = fromExpress(app);
General JWT Resources
jwt.io
JWT Handbook
http://bit.ly/jwt-book
WebTask
webtask.io
facebook.com/mdsbzalam
@mdsbzalam
@mdsbzalam
https://in.linkedin.com/in/mdsbzalam
mdsbzalam@gmail.com