Skip to content

Instantly share code, notes, and snippets.

@tjanczuk
Last active August 29, 2015 14:16
Show Gist options
  • Save tjanczuk/1896dbb747509d0b1d1d to your computer and use it in GitHub Desktop.
Save tjanczuk/1896dbb747509d0b1d1d to your computer and use it in GitHub Desktop.
UI Widget Webtask
<html>
<head>
<title>App</title>
</head>
<body>
<form action="https://sandbox.it.auth0.com/auth0-ui?key=eyJhbGciOiJIUzI1NiIsImtpZCI6IjEifQ.eyJqdGkiOiI0ZGRkMjkyNmYwYzU0NGM3OTJjNWQ4MDYzZjY1ZWI4ZCIsImlhdCI6MTQyNTUyMjE0NSwidXJsIjoiaHR0cDovL2JpdC5seS8xQjRpd2VhIiwidGVuIjoiYXV0aDAtdWkifQ.QCD_xP2j2p3sTAlPr_PFknVeOLJYU4aOMxLUftPS9KU&name=Tomek" method="POST">
<input type="submit" value="Launch Web Task"/>
</form>
</body>
</html>
return function (context, req, res) {
var html = require('ejs').render((function () {/*
<html>
<head>
<title>Auth0 Web Task Widget</title>
<head>
<body>
<h1>Welcome, <%= name %>!</h1>
<h2>What am I looking at?</h2>
<p>This is a text/html response generated by an Auth0 Web Task code. The Auth0 Web Task programming model now allows you
to take full control over the HTTP request and response:</p>
<pre>return function (context, req, res) {
// ...
}</pre>
<p>This enables a lot of new, interesting scenarios:<p>
<ul>
<li>Return arbitrary HTTP responses: HTML, JPG, data, you name it.
<li>Do complext UI flows through redirects.
<li>Accept and process data from form posts.
<li>Stream request data in and stream response data out.
</ul>
<h2>Why is this new model appealing?</h2>
<ul>
<li>Developers now have a convenient ways of packaging entire authenticated UI interaction widgets as a simple URL with a webtask token. T
These interactions can be started as a simple form post from other applications.
<li>These widgets can be provided with secret data (e.g. Twilio or Stripe keys) without disclosing them to the calling application.
<li>These widgets can accept additional data from the calling application.
</ul>
<p>Toughts?</p>
</body>
</html>
*/}).stringify(), {
name: context.data.name || 'Anonymous'
});
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(html);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment